1. 17 Nov, 2022 3 commits
    • Hou Tao's avatar
      bpf: Pass map file to .map_update_batch directly · 3af43ba4
      Hou Tao authored
      Currently bpf_map_do_batch() first invokes fdget(batch.map_fd) to get
      the target map file, then it invokes generic_map_update_batch() to do
      batch update. generic_map_update_batch() will get the target map file
      by using fdget(batch.map_fd) again and pass it to bpf_map_update_value().
      
      The problem is map file returned by the second fdget() may be NULL or a
      totally different file compared by map file in bpf_map_do_batch(). The
      reason is that the first fdget() only guarantees the liveness of struct
      file instead of file descriptor and the file description may be released
      by concurrent close() through pick_file().
      
      It doesn't incur any problem as for now, because maps with batch update
      support don't use map file in .map_fd_get_ptr() ops. But it is better to
      fix the potential access of an invalid map file.
      
      Using __bpf_map_get() again in generic_map_update_batch() can not fix
      the problem, because batch.map_fd may be closed and reopened, and the
      returned map file may be different with map file got in
      bpf_map_do_batch(), so just passing the map file directly to
      .map_update_batch() in bpf_map_do_batch().
      Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20221116075059.1551277-1-houtao@huaweicloud.com
      3af43ba4
    • Daniel Müller's avatar
      bpf/docs: Include blank lines between bullet points in bpf_devel_QA.rst · 383f1a8d
      Daniel Müller authored
      Commit 26a9b433 ("bpf/docs: Document how to run CI without patch
      submission") caused a warning to be generated when compiling the
      documentation:
      
       > bpf_devel_QA.rst:55: WARNING: Unexpected indentation.
       > bpf_devel_QA.rst:56: WARNING: Block quote ends without a blank line
      
      This change fixes the problem by inserting the required blank lines.
      
      Fixes: 26a9b433 ("bpf/docs: Document how to run CI without patch submission")
      Reported-by: default avatarAkira Yokosawa <akiyks@gmail.com>
      Signed-off-by: default avatarDaniel Müller <deso@posteo.net>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarAkira Yokosawa <akiyks@gmail.com>
      Link: https://lore.kernel.org/bpf/20221116174358.2744613-1-deso@posteo.net
      383f1a8d
    • Wang Yufen's avatar
      selftests/bpf: fix memory leak of lsm_cgroup · c453e64c
      Wang Yufen authored
      kmemleak reports this issue:
      
      unreferenced object 0xffff88810b7835c0 (size 32):
        comm "test_progs", pid 270, jiffies 4294969007 (age 1621.315s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          03 00 00 00 03 00 00 00 0f 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000376cdeab>] kmalloc_trace+0x27/0x110
          [<000000003bcdb3b6>] selinux_sk_alloc_security+0x66/0x110
          [<000000003959008f>] security_sk_alloc+0x47/0x80
          [<00000000e7bc6668>] sk_prot_alloc+0xbd/0x1a0
          [<0000000002d6343a>] sk_alloc+0x3b/0x940
          [<000000009812a46d>] unix_create1+0x8f/0x3d0
          [<000000005ed0976b>] unix_create+0xa1/0x150
          [<0000000086a1d27f>] __sock_create+0x233/0x4a0
          [<00000000cffe3a73>] __sys_socket_create.part.0+0xaa/0x110
          [<0000000007c63f20>] __sys_socket+0x49/0xf0
          [<00000000b08753c8>] __x64_sys_socket+0x42/0x50
          [<00000000b56e26b3>] do_syscall_64+0x3b/0x90
          [<000000009b4871b8>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      The issue occurs in the following scenarios:
      
      unix_create1()
        sk_alloc()
          sk_prot_alloc()
            security_sk_alloc()
              call_int_hook()
                hlist_for_each_entry()
                  entry1->hook.sk_alloc_security
                  <-- selinux_sk_alloc_security() succeeded,
                  <-- sk->security alloced here.
                  entry2->hook.sk_alloc_security
                  <-- bpf_lsm_sk_alloc_security() failed
            goto out_free;
              ...    <-- the sk->security not freed, memleak
      
      The core problem is that the LSM is not yet fully stacked (work is
      actively going on in this space) which means that some LSM hooks do
      not support multiple LSMs at the same time. To fix, skip the
      "EPERM" test when it runs in the environments that already have
      non-bpf lsms installed
      
      Fixes: dca85aac ("selftests/bpf: lsm_cgroup functional test")
      Signed-off-by: default avatarWang Yufen <wangyufen@huawei.com>
      Cc: Stanislav Fomichev <sdf@google.com>
      Acked-by: default avatarStanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/r/1668482980-16163-1-git-send-email-wangyufen@huawei.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      c453e64c
  2. 16 Nov, 2022 6 commits
  3. 15 Nov, 2022 10 commits
  4. 14 Nov, 2022 21 commits