]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bpf: fix is_allow_list section
authorJames Hilliard <james.hilliard1@gmail.com>
Mon, 1 Aug 2022 01:11:47 +0000 (01:11 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Aug 2022 14:24:10 +0000 (16:24 +0200)
The llvm bpf compiler appears to place const volatile variables in
a non-standard section which creates an incompatibility with the gcc
bpf compiler.

To fix this force GCC to also use the rodata section.

Note this does emit an assembler warning:
Generating src/core/bpf/restrict_ifaces/restrict-ifaces.bpf.unstripped.o with a custom command
/tmp/ccM2b7jP.s: Assembler messages:
/tmp/ccM2b7jP.s:87: Warning: setting incorrect section attributes for .rodata

See:
https://github.com/llvm/llvm-project/issues/56468

Fixes:
../src/core/restrict-ifaces.c:45:14: error: ‘struct
restrict_ifaces_bpf’ has no member named ‘rodata’; did you mean
‘data’?
   45 |         obj->rodata->is_allow_list = is_allow_list;
      |              ^~~~~~
      |              data

src/core/bpf/restrict_ifaces/restrict-ifaces.bpf.c

index 32cde5c8e020fc8f4e20470dcaa395a1c4f5bb5f..3e33728f4008dc4b75d0125ebec9c75fc147bc85 100644 (file)
@@ -6,7 +6,7 @@
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 
-const volatile __u8 is_allow_list = 0;
+const volatile __u8 is_allow_list SEC(".rodata") = 0;
 
 /* Map containing the network interfaces indexes.
  * The interpretation of the map depends on the value of is_allow_list.