Skip to contentSkip to conversation

bpf: Disable bpf_refcount_acquire kfunc calls until race conditions are fixed

PATCH Applied Dave Marchevsky 2 participants 2 messages Apr 24, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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/

---
 kernel/bpf/verifier.c                                    | 5 ++++-
 tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c | 2 --
 2 files changed, 4 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +4 -1
index 0d73139ee4d8..5c4aa393f65a 100644
@@ -10509,7 +10509,10 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
 				verbose(env, "arg#%d doesn't point to a type with bpf_refcount field\n", i);
 				return -EINVAL;
 			}
-
+			if (rec->refcount_off >= 0) {
+				verbose(env, "bpf_refcount_acquire calls are disabled for now\n");
+				return -EINVAL;
+			}
 			meta->arg_refcount_acquire.btf = reg->btf;
 			meta->arg_refcount_acquire.btf_id = reg->btf_id;
 			break;
tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c +0 -2
index 2ab23832062d..595cbf92bff5 100644
@@ -9,10 +9,8 @@
 
 void test_refcounted_kptr(void)
 {
-	RUN_TESTS(refcounted_kptr);
 }
 
 void test_refcounted_kptr_fail(void)
 {
-	RUN_TESTS(refcounted_kptr_fail);
 }
Signature · 1 line
2.34.1
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Mon, 24 Apr 2023 13:43:21 -0700 you wrote:

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.

[...]

Here is the summary with links:
- [v2,bpf-next] bpf: Disable bpf_refcount_acquire kfunc calls until race conditions are fixed

    https://git.kernel.org/bpf/bpf-next/c/7deca5eae833

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html