** Description changed:

  [Impact]
  
  When building out-of-tree kernel modules (via DKMS or manual module
- build) on systems with the debuginfo package (`linux-image-*-dbgsym`)
- installed, BTF (BPF Type Format) generation is skipped due to vmlinux
- not being found in the expected location. This prevents BPF-based
- tracing tools (bpftrace, BCC) from attaching kprobes/kfuncs to out-of-
- tree module functions.
+ build), BTF (BPF Type Format) generation is skipped due to a vmlinux not
+ being found in the expected location. This prevents BPF-based tracing
+ tools (bpftrace, BCC) from attaching kprobes/kfuncs to out-of-tree
+ module functions.
  
  [Fix]
  
  The patch "UBUNTU: [Packaging] dbgsym: add vmlinux symlink to headers
- directory" resolves this issue by including a symlink to the vmlinux at
- /usr/src/linux-headers-7.0.0-xx-generic/vmlinux in the linux-
- image-7.0.0-xx-generic-dbgsym package.
+ directory" resolves this issue by including a stripped-down version of
+ the vmlinux with only .BTF and .BTF_ids sections at /usr/src/linux-
+ headers-7.0.0-xx-generic/vmlinux in the linux-headers-7.0.0-xx-<flavour>
+ packages.
+ 
+ This solution matches the one in Debian by Bastian Blank: 
https://salsa.debian.org/kernel-team/linux/-/commit/0dedced119aea5426f81a931
+ 8c36e0a6c7339547.
  
  [Test Plan]
  
  Verify that BTF generation succeeds:
  
- 1. Install dbgsym and headers for the target kernel.
+ 1. Install headers for the target kernel.
  
- $ sudo apt install linux-image-7.0.0-xx-generic-dbgsym linux-
- headers-7.0.0-xx-generic-dbgsym
+ $ sudo apt install linux-headers-7.0.0-xx-generic
  
  2. Obtain sources for a test kernel module.
  
  $ git clone https://github.com/ivbakula/hello-world-kernel-module
  
  3. Build this kernel module.
  
  make -C /lib/modules/7.0.0-xx-generic/build M=hello-world-kernel-module
  modules
  
  4. Verify BTF generation is successful.
  
  $ objdump --section=.BTF -s ~/hello-world-kernel-module/hello.ko
  
  /root/hello-world-kernel-module/hello.ko:     file format elf64-x86-64
  
  Contents of section .BTF:
-  0000 9feb0100 18000000 00000000 60000000  ............`...
-  0010 60000000 16000000 00000000 0000000a  `...............
-  0020 02000000 00000000 00000003 00000000  ................
-  0030 03000000 01000000 05000000 00000000  ................
-  0040 0000000a 04000000 15000000 0000000c  ................
-  0050 09000000 20000000 0000000c 08000000  .... ...........
-  0060 00000000 0000000d 01000000 00000000  ................
-  0070 0000000d 00000000 68656c6c 6f5f6578  ........hello_ex
-  0080 69740068 656c6c6f 5f696e69 7400      it.hello_init.
- 
+  0000 9feb0100 18000000 00000000 60000000  ............`...
+  0010 60000000 16000000 00000000 0000000a  `...............
+  0020 02000000 00000000 00000003 00000000  ................
+  0030 03000000 01000000 05000000 00000000  ................
+  0040 0000000a 04000000 15000000 0000000c  ................
+  0050 09000000 20000000 0000000c 08000000  .... ...........
+  0060 00000000 0000000d 01000000 00000000  ................
+  0070 0000000d 00000000 68656c6c 6f5f6578  ........hello_ex
+  0080 69740068 656c6c6f 5f696e69 7400      it.hello_init.
  
  Note: if BTF generation is unsuccessful, the output will appear as:
  
  $ objdump --section=.BTF -s hello.nobtf.ko
  
  hello.nobtf.ko:     file format elf64-x86-64
  
  objdump: section '.BTF' mentioned in a -j option, but not found in any
  input file
  
  [Where issues could occur]
  
- This modifies the Ubuntu dbgsym packaging. An issue with this fix could
- result in a malformed dbgsym package. On systems with the dbgsym package
- installed, built out-of-tree kernel modules will now include an
- additional .BTF section, which is already true for in-tree kernel
- modules.
- 
+ This modifies the flavour-specific header package to include a stripped-
+ down vmlinux with only .BTF and .BTF_ids sections. Issues could occur if
+ software on the system assumes vmlinux at this path will be a full
+ vmlinux, but finds the version with only .BTF and .BTF_ids sections. As
+ a vmlinux file was not included in the headers at all before, it is
+ unlikely existing functionality was relying on it.
  
  Original bug description:
  
  steps to reproduce:
  
  git clone https://github.com/ivbakula/hello-world-kernel-module
  
  $ cd hello-world-kernel-module
  
  $ make -C /usr/src/linux-headers-6.14.0-33-generic/ M=$PWD modules V=1
  
  make: Entering directory '/usr/src/linux-headers-6.14.0-33-generic'
  <snip>
  
  # LD [M]  hello.ko
  
    ld -r -m elf_x86_64 -z noexecstack --no-warn-rwx-segments --build-
  id=sha1  -T /usr/src/linux-headers-6.14.0-33-generic/scripts/module.lds
  -o hello.ko hello.o hello.mod.o .module-common.o
  
  # BTF [M] hello.ko
  
    if [ ! -f /usr/src/linux-headers-6.14.0-33-generic/vmlinux ]; then
  printf "Skipping BTF generation for %s due to unavailability of
  vmlinux\n" hello.ko 1>&2; else LLVM_OBJCOPY="objcopy" pahole -J
  --btf_gen_floats -j --skip_encoding_btf_inconsistent_proto
  --btf_gen_optimized --lang_exclude=rust  --btf_base /usr/src/linux-
  headers-6.14.0-33-generic/vmlinux hello.ko; /usr/src/linux-
  headers-6.14.0-33-generic/tools/bpf/resolve_btfids/resolve_btfids -b
  /usr/src/linux-headers-6.14.0-33-generic/vmlinux hello.ko; fi;
  
  Skipping BTF generation for hello.ko due to unavailability of vmlinux
  
  make[1]: Leaving directory '/tmp/hello-world-kernel-module'
  
  make: Leaving directory '/usr/src/linux-headers-6.14.0-33-generic'
  
  "Skipping BTF generation for hello.ko due to unavailability of vmlinux" says 
vmlinux wasn't found.
  Workaround: ln -s /usr/lib/debug/boot/vmlinux-$(uname -r) 
/usr/src/linux-headers-$(uname -r)/vmlinux it seems to work.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2133794

Title:
  BTF Generation Fails for Out-of-Tree Modules with Debuginfo Package

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2133794/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to