TencentOS-kernel/kernel/bpf
Menglong Dong 7faeff95e4 bpf: fix probe read error in ___bpf_prog_run()
I think there is something wrong with BPF_PROBE_MEM in ___bpf_prog_run()
in big-endian machine. Let's make a test and see what will happen if we
want to load a 'u16' with BPF_PROBE_MEM.

Let's make the src value '0x0001', the value of dest register will become
0x0001000000000000, as the value will be loaded to the first 2 byte of
DST with following code:

  bpf_probe_read_kernel(&DST, SIZE, (const void *)(long) (SRC + insn->off));

Obviously, the value in DST is not correct. In fact, we can compare
BPF_PROBE_MEM with LDX_MEM_H:

  DST = *(SIZE *)(unsigned long) (SRC + insn->off);

If the memory load is done by LDX_MEM_H, the value in DST will be 0x1 now.

And I think this error results in the test case 'test_bpf_sk_storage_map'
failing:

  test_bpf_sk_storage_map:PASS:bpf_iter_bpf_sk_storage_map__open_and_load 0 nsec
  test_bpf_sk_storage_map:PASS:socket 0 nsec
  test_bpf_sk_storage_map:PASS:map_update 0 nsec
  test_bpf_sk_storage_map:PASS:socket 0 nsec
  test_bpf_sk_storage_map:PASS:map_update 0 nsec
  test_bpf_sk_storage_map:PASS:socket 0 nsec
  test_bpf_sk_storage_map:PASS:map_update 0 nsec
  test_bpf_sk_storage_map:PASS:attach_iter 0 nsec
  test_bpf_sk_storage_map:PASS:create_iter 0 nsec
  test_bpf_sk_storage_map:PASS:read 0 nsec
  test_bpf_sk_storage_map:FAIL:ipv6_sk_count got 0 expected 3
  $10/26 bpf_iter/bpf_sk_storage_map:FAIL

The code of the test case is simply, it will load sk->sk_family to the
register with BPF_PROBE_MEM and check if it is AF_INET6. With this patch,
now the test case 'bpf_iter' can pass:

  $10  bpf_iter:OK

Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
2022-08-30 11:33:35 +08:00
..
Makefile bpf: Implement BPF ring buffer and verifier support for it 2022-08-30 11:33:29 +08:00
arraymap.c bpf: Add map side support for bpf timers. 2022-08-30 11:33:30 +08:00
bpf_inode_storage.c bpf: Implement bpf_local_storage for inodes 2022-08-30 11:33:29 +08:00
bpf_iter.c bpf: Add bpf_for_each_map_elem() helper 2022-08-30 11:33:30 +08:00
bpf_local_storage.c bpf: Split bpf_local_storage to bpf_sk_storage 2022-08-30 11:33:29 +08:00
bpf_lru_list.c bpf_lru_list: Read double-checked variable once without lock 2021-04-12 12:52:15 +08:00
bpf_lru_list.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
bpf_lsm.c bpf: Allow local storage to be used from LSM programs 2022-08-30 11:33:29 +08:00
bpf_struct_ops.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
bpf_struct_ops_types.h bpf: tcp: Support tcp_congestion_ops in bpf 2022-08-30 11:33:19 +08:00
btf.c bpf: Remember BTF of inner maps. 2022-08-30 11:33:30 +08:00
cgroup.c bpf: Add support for forced LINK_DETACH command 2022-08-30 11:33:32 +08:00
core.c bpf: fix probe read error in ___bpf_prog_run() 2022-08-30 11:33:35 +08:00
cpumap.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
devmap.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
disasm.c bpf: Introduce BPF nospec instruction for mitigating Spectre v4 2022-08-30 11:33:16 +08:00
disasm.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
dispatcher.c bpf: Introduce BPF dispatcher 2022-08-30 11:33:19 +08:00
hashtab.c bpf: Add map side support for bpf timers. 2022-08-30 11:33:30 +08:00
helpers.c bpf: Implement verifier support for validation of async callbacks. 2022-08-30 11:33:30 +08:00
inode.c bpf: Create file bpf iterator 2022-08-30 11:33:25 +08:00
local_storage.c bpf: Add map side support for bpf timers. 2022-08-30 11:33:30 +08:00
lpm_trie.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
map_in_map.c bpf: Remember BTF of inner maps. 2022-08-30 11:33:30 +08:00
map_in_map.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
map_iter.c bpf: Change uapi for bpf iterator map elements 2022-08-30 11:33:28 +08:00
net_namespace.c bpf: Add support for forced LINK_DETACH command 2022-08-30 11:33:32 +08:00
offload.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
percpu_freelist.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
percpu_freelist.h Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
prog_iter.c bpf: Refactor bpf_iter_reg to have separate seq_info member 2022-08-30 11:33:28 +08:00
queue_stack_maps.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
reuseport_array.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00
ringbuf.c bpf: Implement BPF ring buffer and verifier support for it 2022-08-30 11:33:29 +08:00
stackmap.c bpf: Resolve BTF IDs in vmlinux image 2022-08-30 11:33:27 +08:00
syscall.c bpf: Fix leak in LINK_UPDATE and enforce empty old_prog_fd 2022-08-30 11:33:32 +08:00
sysfs_btf.c bpf: Fix sysfs export of empty BTF section 2021-03-16 16:37:55 +08:00
task_iter.c bpf: Refactor to provide aux info to bpf_iter_init_seq_priv_t 2022-08-30 11:33:28 +08:00
tnum.c Init Repo base on linux 5.4.32 long term, and add base tlinux kernel interfaces. 2021-03-16 11:01:34 +08:00
trampoline.c bpf: lsm: Implement attach, detach and execution 2022-08-30 11:33:21 +08:00
verifier.c bpf: Stop caching subprog index in the bpf_pseudo_func insn 2022-08-30 11:33:34 +08:00
xskmap.c bpf: Set map_btf_{name, id} for all map types 2022-08-30 11:33:27 +08:00