All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] bpf: Fix potential call bpf_link_free() in atomic context
@ 2020-09-17  7:44 Muchun Song
  2020-09-17 22:37 ` Song Liu
  2020-09-21 17:29 ` Andrii Nakryiko
  0 siblings, 2 replies; 6+ messages in thread
From: Muchun Song @ 2020-09-17  7:44 UTC (permalink / raw)
  To: ast, daniel, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh
  Cc: netdev, bpf, Muchun Song

The in_atomic macro cannot always detect atomic context. In particular,
it cannot know about held spinlocks in non-preemptible kernels. Although,
there is no user call bpf_link_put() with holding spinlock now. Be the
safe side, we can avoid this in the feature.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 kernel/bpf/syscall.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 178c147350f5..6347be0a5c82 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2345,12 +2345,8 @@ void bpf_link_put(struct bpf_link *link)
 	if (!atomic64_dec_and_test(&link->refcnt))
 		return;
 
-	if (in_atomic()) {
-		INIT_WORK(&link->work, bpf_link_put_deferred);
-		schedule_work(&link->work);
-	} else {
-		bpf_link_free(link);
-	}
+	INIT_WORK(&link->work, bpf_link_put_deferred);
+	schedule_work(&link->work);
 }
 
 static int bpf_link_release(struct inode *inode, struct file *filp)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-21 19:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17  7:44 [RFC PATCH] bpf: Fix potential call bpf_link_free() in atomic context Muchun Song
2020-09-17 22:37 ` Song Liu
2020-09-19  5:26   ` [External] " Muchun Song
2020-09-21 17:29 ` Andrii Nakryiko
2020-09-21 18:31   ` Andrii Nakryiko
2020-09-21 19:27     ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.