• Paul Chaignon's avatar
    Fix dereference replacements for pointers to pointers · 471f1ea1
    Paul Chaignon authored
    Currently, the bcc rewriter is unable to track external pointers if
    there is more than a single level of indirection (e.g., pointer to
    external pointer).  For example, in the following, the rewriter is
    unable to detect that ptr2 doesn't need a call to bpf_probe_read,
    only *ptr2 do.
    
    int test(struct pt_regs *ctx, struct sock *sk) {
        struct sock *ptr1;
        struct sock **ptr2 = &ptr1;
        *ptr2 = sk;
        return ((struct sock *)(*ptr2))->sk_daddr;
    }
    
    This commit fixes this issue by tracking the levels of indirections
    in addition to the variable declarations (identifies each variable).
    When traversing dereferences, the level of indirections is used to
    decide whether the base expression is an external pointer.  The level
    of indirections is inherited when a pointer is assigned to a new
    variable (assignments and function calls).
    471f1ea1
b_frontend_action.h 5.77 KB