]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Reject offset refcount acquire arguments
authorYiyang Chen <chenyy23@mails.tsinghua.edu.cn>
Tue, 23 Jun 2026 06:11:09 +0000 (06:11 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 26 Jun 2026 00:51:20 +0000 (17:51 -0700)
commit931a577fc79ea6a169a33f5538f4c1433235c358
tree4d4a34dd2ffd53a1d8287a8efe9d7dd264fdb97d
parent66bb952b449eac53dffb341108251d632767fd2d
bpf: Reject offset refcount acquire arguments

bpf_refcount_acquire() increments the refcount at the caller-supplied
pointer plus the refcount field offset, then returns the caller-supplied
pointer unchanged.

The verifier records the return value as a base pointer to the refcounted
object.

bpf_list_pop_front() and bpf_rbtree_remove() can return embedded
graph-node pointers as PTR_TO_BTF_ID | MEM_ALLOC with a fixed offset equal
to the node field offset. Passing such a pointer directly to
bpf_refcount_acquire() currently passes the refcounted-kptr type check.

That makes the runtime operation start from base + node_off while the
verifier models the returned pointer as the object base.

Require refcount-acquire arguments to have zero fixed offset by carrying
the requirement through check_func_arg_reg_off() to __check_ptr_off_reg().
Programs can still acquire a refcount from a graph-node-derived pointer
after normalizing it with container_of().

Fixes: 7c50b1cb76aca ("bpf: Add bpf_refcount_acquire kfunc")
Signed-off-by: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/2f894647f56f71838fdddeb97a3e057ed35ea92e.1782192383.git.chenyy23@mails.tsinghua.edu.cn
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c