• Kumar Kartikeya Dwivedi's avatar
    bpf: Make BTF type match stricter for release arguments · 2ab3b380
    Kumar Kartikeya Dwivedi authored
    The current of behavior of btf_struct_ids_match for release arguments is
    that when type match fails, it retries with first member type again
    (recursively). Since the offset is already 0, this is akin to just
    casting the pointer in normal C, since if type matches it was just
    embedded inside parent sturct as an object. However, we want to reject
    cases for release function type matching, be it kfunc or BPF helpers.
    
    An example is the following:
    
    struct foo {
    	struct bar b;
    };
    
    struct foo *v = acq_foo();
    rel_bar(&v->b); // btf_struct_ids_match fails btf_types_are_same, then
    		// retries with first member type and succeeds, while
    		// it should fail.
    
    Hence, don't walk the struct and only rely on btf_types_are_same for
    strict mode. All users of strict mode must be dealing with zero offset
    anyway, since otherwise they would want the struct to be walked.
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20220424214901.2743946-10-memxor@gmail.com
    2ab3b380
verifier.c 424 KB