• Paul Chaignon's avatar
    Trace all external pointers passed through a first map (#1737) · ad2d0d9f
    Paul Chaignon authored
    * Trace all external pointers going through a first map
    
    Currently, MapVisitor only detects maps with external pointers as
    values if the value was directly passed from a function's argument.
    For example, in the following, the rewriter is currently unable to
    detect currsock has an external pointer as value because an
    intermediate variable is used instead of passing directly sk as the
    map's value.
    
        int test(struct pt_regs *ctx, struct sock *sk) {
            u32 pid = bpf_get_current_pid_tgid();
            struct sock **skp = &sk;
            currsock.update(&pid, skp);
            return 0;
        };
    
    With this commit, MapVisitor is able to trace any external pointer
    derived from the function's argument and used as a map value. This
    commit breaks the ProbeVisitor traversal in two distinct traversals.
    The first rewrites dereferences of external pointers originating
    from function's arguments and helpers, while the second rewrites only
    dereferences of external pointers passed through maps.
    Maps with external pointers as values are identified between the two
    ProbeVisitor traversals.
    
    * New tests for external pointers passed through maps
    
    test_ext_ptr_maps_reverse ensures dereferences are correctly replaced
    even if the update happens after the lookup (in the order of
    MapVisitor traversal).
    test_ext_ptr_maps_indirect ensures the rewriter is able to trace
    external pointers used as map values even if using an intermediate
    variable.
    ad2d0d9f
test_clang.py 21 KB