1. 20 Mar, 2021 1 commit
  2. 19 Mar, 2021 4 commits
    • Zqiang's avatar
      bpf: Fix umd memory leak in copy_process() · f60a85ca
      Zqiang authored
      The syzbot reported a memleak as follows:
      
      BUG: memory leak
      unreferenced object 0xffff888101b41d00 (size 120):
        comm "kworker/u4:0", pid 8, jiffies 4294944270 (age 12.780s)
        backtrace:
          [<ffffffff8125dc56>] alloc_pid+0x66/0x560
          [<ffffffff81226405>] copy_process+0x1465/0x25e0
          [<ffffffff81227943>] kernel_clone+0xf3/0x670
          [<ffffffff812281a1>] kernel_thread+0x61/0x80
          [<ffffffff81253464>] call_usermodehelper_exec_work
          [<ffffffff81253464>] call_usermodehelper_exec_work+0xc4/0x120
          [<ffffffff812591c9>] process_one_work+0x2c9/0x600
          [<ffffffff81259ab9>] worker_thread+0x59/0x5d0
          [<ffffffff812611c8>] kthread+0x178/0x1b0
          [<ffffffff8100227f>] ret_from_fork+0x1f/0x30
      
      unreferenced object 0xffff888110ef5c00 (size 232):
        comm "kworker/u4:0", pid 8414, jiffies 4294944270 (age 12.780s)
        backtrace:
          [<ffffffff8154a0cf>] kmem_cache_zalloc
          [<ffffffff8154a0cf>] __alloc_file+0x1f/0xf0
          [<ffffffff8154a809>] alloc_empty_file+0x69/0x120
          [<ffffffff8154a8f3>] alloc_file+0x33/0x1b0
          [<ffffffff8154ab22>] alloc_file_pseudo+0xb2/0x140
          [<ffffffff81559218>] create_pipe_files+0x138/0x2e0
          [<ffffffff8126c793>] umd_setup+0x33/0x220
          [<ffffffff81253574>] call_usermodehelper_exec_async+0xb4/0x1b0
          [<ffffffff8100227f>] ret_from_fork+0x1f/0x30
      
      After the UMD process exits, the pipe_to_umh/pipe_from_umh and
      tgid need to be released.
      
      Fixes: d71fa5c9 ("bpf: Add kernel module with user mode driver that populates bpffs.")
      Reported-by: syzbot+44908bb56d2bfe56b28e@syzkaller.appspotmail.com
      Signed-off-by: default avatarZqiang <qiang.zhang@windriver.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20210317030915.2865-1-qiang.zhang@windriver.com
      f60a85ca
    • Andrii Nakryiko's avatar
      Merge branch 'libbpf: Fix BTF dump of pointer-to-array-of-struct' · e75b513e
      Andrii Nakryiko authored
      Jean-Philippe Brucker says:
      
      ====================
      
      Fix an issue with the libbpf BTF dump, see patch 1 for details.
      
      Since [v1] I added the selftest in patch 2, though I couldn't figure out
      a way to make it independent from the order in which debug info is
      issued by the compiler.
      
      [v1]: https://lore.kernel.org/bpf/20210318122700.396574-1-jean-philippe@linaro.org/
      ====================
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      e75b513e
    • Jean-Philippe Brucker's avatar
      selftests/bpf: Add selftest for pointer-to-array-of-struct BTF dump · f118aac6
      Jean-Philippe Brucker authored
      Bpftool used to issue forward declarations for a struct used as part of
      a pointer to array, which is invalid. Add a test to check that the
      struct is fully defined in this case:
      
      	@@ -134,9 +134,9 @@
      	 	};
      	 };
      
      	-struct struct_in_array {};
      	+struct struct_in_array;
      
      	-struct struct_in_array_typed {};
      	+struct struct_in_array_typed;
      
      	 typedef struct struct_in_array_typed struct_in_array_t[2];
      
      	@@ -189,3 +189,7 @@
      	 	struct struct_with_embedded_stuff _14;
      	 };
      
      	+struct struct_in_array {};
      	+
      	+struct struct_in_array_typed {};
      	+
      	...
      	#13/1 btf_dump: syntax:FAIL
      Suggested-by: default avatarAndrii Nakryiko <andrii.nakryiko@gmail.com>
      Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210319112554.794552-3-jean-philippe@linaro.org
      f118aac6
    • Jean-Philippe Brucker's avatar
      libbpf: Fix BTF dump of pointer-to-array-of-struct · 901ee1d7
      Jean-Philippe Brucker authored
      The vmlinux.h generated from BTF is invalid when building
      drivers/phy/ti/phy-gmii-sel.c with clang:
      
      vmlinux.h:61702:27: error: array type has incomplete element type ‘struct reg_field’
      61702 |  const struct reg_field (*regfields)[3];
            |                           ^~~~~~~~~
      
      bpftool generates a forward declaration for this struct regfield, which
      compilers aren't happy about. Here's a simplified reproducer:
      
      	struct inner {
      		int val;
      	};
      	struct outer {
      		struct inner (*ptr_to_array)[2];
      	} A;
      
      After build with clang -> bpftool btf dump c -> clang/gcc:
      ./def-clang.h:11:23: error: array has incomplete element type 'struct inner'
              struct inner (*ptr_to_array)[2];
      
      Member ptr_to_array of struct outer is a pointer to an array of struct
      inner. In the DWARF generated by clang, struct outer appears before
      struct inner, so when converting BTF of struct outer into C, bpftool
      issues a forward declaration to struct inner. With GCC the DWARF info is
      reversed so struct inner gets fully defined.
      
      That forward declaration is not sufficient when compilers handle an
      array of the struct, even when it's only used through a pointer. Note
      that we can trigger the same issue with an intermediate typedef:
      
      	struct inner {
      	        int val;
      	};
      	typedef struct inner inner2_t[2];
      	struct outer {
      	        inner2_t *ptr_to_array;
      	} A;
      
      Becomes:
      
      	struct inner;
      	typedef struct inner inner2_t[2];
      
      And causes:
      
      ./def-clang.h:10:30: error: array has incomplete element type 'struct inner'
      	typedef struct inner inner2_t[2];
      
      To fix this, clear through_ptr whenever we encounter an intermediate
      array, to make the inner struct part of a strong link and force full
      declaration.
      
      Fixes: 351131b5 ("libbpf: add btf_dump API for BTF-to-C conversion")
      Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210319112554.794552-2-jean-philippe@linaro.org
      901ee1d7
  3. 18 Mar, 2021 2 commits
  4. 17 Mar, 2021 12 commits
  5. 16 Mar, 2021 21 commits