bpf: Fix __bpf_{list,rbtree}_add's beginning-of-node calculation
authorDave Marchevsky <davemarchevsky@fb.com>
Fri, 2 Jun 2023 02:26:41 +0000 (19:26 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 5 Jun 2023 20:17:19 +0000 (13:17 -0700)
commitcc0d76cafebbd3e1ffab9c4252d48ecc9e0737f6
tree9fb1dcd4e75f800637d7be2763c019a58541c249
parent2140a6e3422de22e6ebe77d4d18b6c0c9c425426
bpf: Fix __bpf_{list,rbtree}_add's beginning-of-node calculation

Given the pointer to struct bpf_{rb,list}_node within a local kptr and
the byte offset of that field within the kptr struct, the calculation changed
by this patch is meant to find the beginning of the kptr so that it can
be passed to bpf_obj_drop.

Unfortunately instead of doing

  ptr_to_kptr = ptr_to_node_field - offset_bytes

the calculation is erroneously doing

  ptr_to_ktpr = ptr_to_node_field - (offset_bytes * sizeof(struct bpf_rb_node))

or the bpf_list_node equivalent.

This patch fixes the calculation.

Fixes: d2dcc67df910 ("bpf: Migrate bpf_rbtree_add and bpf_list_push_{front,back} to possibly fail")
Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/r/20230602022647.1571784-4-davemarchevsky@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c