1. 07 Jun, 2023 1 commit
    • Jiri Olsa's avatar
      bpf: Add extra path pointer check to d_path helper · f46fab0e
      Jiri Olsa authored
      Anastasios reported crash on stable 5.15 kernel with following
      BPF attached to lsm hook:
      
        SEC("lsm.s/bprm_creds_for_exec")
        int BPF_PROG(bprm_creds_for_exec, struct linux_binprm *bprm)
        {
                struct path *path = &bprm->executable->f_path;
                char p[128] = { 0 };
      
                bpf_d_path(path, p, 128);
                return 0;
        }
      
      But bprm->executable can be NULL, so bpf_d_path call will crash:
      
        BUG: kernel NULL pointer dereference, address: 0000000000000018
        #PF: supervisor read access in kernel mode
        #PF: error_code(0x0000) - not-present page
        PGD 0 P4D 0
        Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC NOPTI
        ...
        RIP: 0010:d_path+0x22/0x280
        ...
        Call Trace:
         <TASK>
         bpf_d_path+0x21/0x60
         bpf_prog_db9cf176e84498d9_bprm_creds_for_exec+0x94/0x99
         bpf_trampoline_6442506293_0+0x55/0x1000
         bpf_lsm_bprm_creds_for_exec+0x5/0x10
         security_bprm_creds_for_exec+0x29/0x40
         bprm_execve+0x1c1/0x900
         do_execveat_common.isra.0+0x1af/0x260
         __x64_sys_execve+0x32/0x40
      
      It's problem for all stable trees with bpf_d_path helper, which was
      added in 5.9.
      
      This issue is fixed in current bpf code, where we identify and mark
      trusted pointers, so the above code would fail even to load.
      
      For the sake of the stable trees and to workaround potentially broken
      verifier in the future, adding the code that reads the path object from
      the passed pointer and verifies it's valid in kernel space.
      
      Fixes: 6e22ab9d ("bpf: Add d_path helper")
      Reported-by: default avatarAnastasios Papagiannis <tasos.papagiannnis@gmail.com>
      Suggested-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarStanislav Fomichev <sdf@google.com>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20230606181714.532998-1-jolsa@kernel.org
      f46fab0e
  2. 06 Jun, 2023 1 commit
    • Yonghong Song's avatar
      selftests/bpf: Fix sockopt_sk selftest · 69844e33
      Yonghong Song authored
      Commit f4e45348 ("net/netlink: fix NETLINK_LIST_MEMBERSHIPS length report")
      fixed NETLINK_LIST_MEMBERSHIPS length report which caused
      selftest sockopt_sk failure. The failure log looks like
      
        test_sockopt_sk:PASS:join_cgroup /sockopt_sk 0 nsec
        run_test:PASS:skel_load 0 nsec
        run_test:PASS:setsockopt_link 0 nsec
        run_test:PASS:getsockopt_link 0 nsec
        getsetsockopt:FAIL:Unexpected NETLINK_LIST_MEMBERSHIPS value unexpected Unexpected NETLINK_LIST_MEMBERSHIPS value: actual 8 != expected 4
        run_test:PASS:getsetsockopt 0 nsec
        #201     sockopt_sk:FAIL
      
      In net/netlink/af_netlink.c, function netlink_getsockopt(), for NETLINK_LIST_MEMBERSHIPS,
      nlk->ngroups equals to 36. Before Commit f4e45348, the optlen is calculated as
        ALIGN(nlk->ngroups / 8, sizeof(u32)) = 4
      After that commit, the optlen is
        ALIGN(BITS_TO_BYTES(nlk->ngroups), sizeof(u32)) = 8
      
      Fix the test by setting the expected optlen to be 8.
      
      Fixes: f4e45348 ("net/netlink: fix NETLINK_LIST_MEMBERSHIPS length report")
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20230606172202.1606249-1-yhs@fb.com
      69844e33
  3. 05 Jun, 2023 1 commit
  4. 03 Jun, 2023 2 commits
  5. 02 Jun, 2023 2 commits
  6. 01 Jun, 2023 5 commits
  7. 31 May, 2023 8 commits
  8. 30 May, 2023 19 commits
  9. 26 May, 2023 1 commit