Skip to content

Commit 7deca5e

Browse files
davemarchevskyAlexei Starovoitov
authored andcommitted
bpf: Disable bpf_refcount_acquire kfunc calls until race conditions are fixed
As reported by Kumar in [0], the shared ownership implementation for BPF programs has some race conditions which need to be addressed before it can safely be used. This patch does so in a minimal way instead of ripping out shared ownership entirely, as proper fixes for the issues raised will follow ASAP, at which point this patch's commit can be reverted to re-enable shared ownership. The patch removes the ability to call bpf_refcount_acquire_impl from BPF programs. Programs can only bump refcount and obtain a new owning reference using this kfunc, so removing the ability to call it effectively disables shared ownership. Instead of changing success / failure expectations for bpf_refcount-related selftests, this patch just disables them from running for now. [0]: https://lore.kernel.org/bpf/d7hyspcow5wtjcmw4fugdgyp3fwhljwuscp3xyut5qnwivyeru@ysdq543otzv2/ Reported-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Dave Marchevsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3515020 commit 7deca5e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10509,7 +10509,10 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
1050910509
verbose(env, "arg#%d doesn't point to a type with bpf_refcount field\n", i);
1051010510
return -EINVAL;
1051110511
}
10512-
10512+
if (rec->refcount_off >= 0) {
10513+
verbose(env, "bpf_refcount_acquire calls are disabled for now\n");
10514+
return -EINVAL;
10515+
}
1051310516
meta->arg_refcount_acquire.btf = reg->btf;
1051410517
meta->arg_refcount_acquire.btf_id = reg->btf_id;
1051510518
break;

tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
void test_refcounted_kptr(void)
1111
{
12-
RUN_TESTS(refcounted_kptr);
1312
}
1413

1514
void test_refcounted_kptr_fail(void)
1615
{
17-
RUN_TESTS(refcounted_kptr_fail);
1816
}

0 commit comments

Comments
 (0)