Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: Fix a bpf_kptr_xchg() issue with local kptr #5549

Closed
wants to merge 2 commits into from

Commits on Aug 21, 2023

  1. bpf: Fix a bpf_kptr_xchg() issue with local kptr

    When reviewing local percpu kptr support, Alexei discovered a bug
    wherea bpf_kptr_xchg() may succeed even if the map value kptr type and
    locally allocated obj type do not match ([1]). Missed struct btf_id
    comparison is the reason for the bug. This patch added such struct btf_id
    comparison and will flag verification failure if types do not match.
    
      [1] https://lore.kernel.org/bpf/20230819002907.io3iphmnuk43xblu@macbook-pro-8.dhcp.thefacebook.com/#t
    
    Reported-by: Alexei Starovoitov <ast@kernel.org>
    Fixes: 738c96d ("bpf: Allow local kptrs to be exchanged via bpf_kptr_xchg")
    Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
    Yonghong Song authored and Kernel Patches Daemon committed Aug 21, 2023
    Configuration menu
    Copy the full SHA
    862c892 View commit details
    Browse the repository at this point in the history
  2. selftests/bpf: Add a failure test for bpf_kptr_xchg() with local kptr

    For a bpf_kptr_xchg() with local kptr, if the map value kptr type and
    allocated local obj type does not match, with the previous patch,
    the below verifier error message will be logged:
      R2 is of type <allocated local obj type> but <map value kptr type> is expected
    
    Without the previous patch, the test will have unexpected success.
    
    Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
    Yonghong Song authored and Kernel Patches Daemon committed Aug 21, 2023
    Configuration menu
    Copy the full SHA
    1df4abf View commit details
    Browse the repository at this point in the history