• Kumar Kartikeya Dwivedi's avatar
    bpf: Allow reinitializing unreferenced dynptr stack slots · 379d4ba8
    Kumar Kartikeya Dwivedi authored
    Consider a program like below:
    
    void prog(void)
    {
    	{
    		struct bpf_dynptr ptr;
    		bpf_dynptr_from_mem(...);
    	}
    	...
    	{
    		struct bpf_dynptr ptr;
    		bpf_dynptr_from_mem(...);
    	}
    }
    
    Here, the C compiler based on lifetime rules in the C standard would be
    well within in its rights to share stack storage for dynptr 'ptr' as
    their lifetimes do not overlap in the two distinct scopes. Currently,
    such an example would be rejected by the verifier, but this is too
    strict. Instead, we should allow reinitializing over dynptr stack slots
    and forget information about the old dynptr object.
    
    The destroy_if_dynptr_stack_slot function already makes necessary checks
    to avoid overwriting referenced dynptr slots. This is done to present a
    better error message instead of forgetting dynptr information on stack
    and preserving reference state, leading to an inevitable but
    undecipherable error at the end about an unreleased reference which has
    to be associated back to its allocating call instruction to make any
    sense to the user.
    Acked-by: default avatarJoanne Koong <joannelkoong@gmail.com>
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20230121002241.2113993-6-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    379d4ba8
verifier.c 504 KB