eBPF:默认 bpf programs/maps?

eBPF: default bpf programs/maps?

我在使用最新的 net-next 内核时遇到 bpf 的奇怪行为。在启用所有 BPF 内核选项(包括 CONFIG_BPF_JIT_ALWAYS_ON)且未加载 any bpf 程序的情况下,bpftool 报告以下内容:

# ./bpftool prog show
2: cgroup_skb  tag 7be49e3934a125ba
        loaded_at Feb 05/10:17  uid 0
        xlated 296B  jited 229B  memlock 4096B  map_ids 2,3
3: cgroup_skb  tag 2a142ef67aaad174
        loaded_at Feb 05/10:17  uid 0
        xlated 296B  jited 229B  memlock 4096B  map_ids 2,3
4: cgroup_skb  tag 7be49e3934a125ba
        loaded_at Feb 05/10:17  uid 0
        xlated 296B  jited 229B  memlock 4096B  map_ids 4,5
5: cgroup_skb  tag 2a142ef67aaad174
        loaded_at Feb 05/10:17  uid 0
        xlated 296B  jited 229B  memlock 4096B  map_ids 4,5
6: cgroup_skb  tag 7be49e3934a125ba
        loaded_at Feb 05/10:17  uid 0
        xlated 296B  jited 229B  memlock 4096B  map_ids 6,7
7: cgroup_skb  tag 2a142ef67aaad174
        loaded_at Feb 05/10:17  uid 0
        xlated 296B  jited 229B  memlock 4096B  map_ids 6,7
#
# ./bpftool map show
2: lpm_trie  flags 0x1
        key 8B  value 8B  max_entries 1  memlock 4096B
3: lpm_trie  flags 0x1
        key 20B  value 8B  max_entries 1  memlock 4096B
4: lpm_trie  flags 0x1
        key 8B  value 8B  max_entries 1  memlock 4096B
5: lpm_trie  flags 0x1
        key 20B  value 8B  max_entries 1  memlock 4096B
6: lpm_trie  flags 0x1
        key 8B  value 8B  max_entries 1  memlock 4096B
7: lpm_trie  flags 0x1
        key 20B  value 8B  max_entries 1  memlock 4096B
#

程序内容如下:

# ./bpftool prog dump xlated id 2
   0: (bf) r6 = r1
   1: (69) r7 = *(u16 *)(r6 +192)
   2: (b4) (u32) r8 = (u32) 0
   3: (55) if r7 != 0x8 goto pc+14
   4: (bf) r1 = r6
   5: (b4) (u32) r2 = (u32) 16
   6: (bf) r3 = r10
   7: (07) r3 += -4
   8: (b4) (u32) r4 = (u32) 4
   9: (85) call bpf_skb_load_bytes#6169312
  10: (18) r1 = map[id:2]
  12: (bf) r2 = r10
  13: (07) r2 += -8
  14: (62) *(u32 *)(r2 +0) = 32
  15: (85) call bpf_map_lookup_elem#73712
  16: (15) if r0 == 0x0 goto pc+1
  17: (44) (u32) r8 |= (u32) 2
  18: (55) if r7 != 0xdd86 goto pc+14
  19: (bf) r1 = r6
  20: (b4) (u32) r2 = (u32) 24
  21: (bf) r3 = r10
  22: (07) r3 += -16
  23: (b4) (u32) r4 = (u32) 16
  24: (85) call bpf_skb_load_bytes#6169312
  25: (18) r1 = map[id:3]
  27: (bf) r2 = r10
  28: (07) r2 += -20
  29: (62) *(u32 *)(r2 +0) = 128
  30: (85) call bpf_map_lookup_elem#73712
  31: (15) if r0 == 0x0 goto pc+1
  32: (44) (u32) r8 |= (u32) 2
  33: (b7) r0 = 1
  34: (55) if r8 != 0x2 goto pc+1
  35: (b7) r0 = 0
  36: (95) exit
#

有趣的是我没有明确加载任何 eBPF 程序。我想知道现在内核中是否有一个默认的 eBPF blob,它显示出来了吗?

这会在机器启动后立即发生。这个系统和另一个系统(运行 相同的内核和选项,并且我在多个 cgroup_skb 程序中没有看到这个问题)之间的唯一区别是 /sys/fs/cgroup/unified cgroup2 FS 的存在。我不知道这是否与我的问题有关,但我不知道如何禁用/sys/fs/cgroup/unified,不允许卸载

正如 Qeole 所怀疑的那样,这是来自 systemd,特别是 systemd v235 引入了 IP 访问控制 eBPF 功能,并公开了两个配置选项,IPAddressDeny 和 IPAddressAllow。 (不知道是否可以在编译时禁用)