🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
6 messages
6 total messages Started by Sechang Lim Tue, 24 Nov 2026 14:31
[PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context
#21848
Author: Sechang Lim
Date: Tue, 24 Nov 2026 14:31
24 lines
11817 bytes
Any struct_ops program can be loaded as sleepable, and it is up to each
struct_ops to reject that in check_member for members that run in
atomic context. tcp_congestion_ops, Qdisc_ops and smc_hs_ctrl have no
check_member, although the kernel calls their members in softirq, under
a spinlock or under rcu_read_lock(). A sleepable program attached there
is entered through __bpf_prog_enter_sleepable(), and lockdep reports
"BUG: Invalid wait context" at its might_fault().

This series adds a check_member that rejects sleepable programs to each
of them, like bpf_tcp_ops does.

Sechang Lim (3):
  bpf: Reject sleepable programs in bpf-tcp-cc
  bpf: net_sched: Reject sleepable programs in bpf qdisc
  net/smc: bpf: Reject sleepable programs in smc_hs_ctrl

 net/ipv4/bpf_tcp_ca.c | 11 +++++++++++
 net/sched/bpf_qdisc.c | 11 +++++++++++
 net/smc/smc_hs_bpf.c  | 11 +++++++++++
 3 files changed, 33 insertions(+)

-- 
2.56.1
[PATCH bpf 1/3] bpf: Reject sleepable programs in bpf-tcp-cc
#21849
Author: Sechang Lim
Date: Tue, 24 Nov 2026 14:31
46 lines
13020 bytes
A bpf-tcp-cc program can be loaded with BPF_F_SLEEPABLE, but the TCP
stack calls the congestion control ops in atomic context. For example,
tcp_set_ca_state() is called from tcp_v4_syn_recv_sock() in softirq with
the socket spinlock held.

bpf_tcp_congestion_ops has no check_member, so nothing rejects such a
program. Add one that rejects sleepable programs.

Fixes: 1e12d3ef47d2 ("bpf: Allow BPF_PROG_TYPE_STRUCT_OPS programs to be sleepable")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 net/ipv4/bpf_tcp_ca.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
index 2a71dc81562f..acd5e84a3dd9 100644
--- a/net/ipv4/bpf_tcp_ca.c
+++ b/net/ipv4/bpf_tcp_ca.c
@@ -208,6 +208,16 @@ static const struct bpf_verifier_ops bpf_tcp_ca_verifier_ops = {
 	.btf_struct_access	= bpf_tcp_ca_btf_struct_access,
 };
 
+static int bpf_tcp_ca_check_member(const struct btf_type *t,
+				   const struct btf_member *member,
+				   const struct bpf_prog *prog)
+{
+	if (prog->sleepable)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int bpf_tcp_ca_init_member(const struct btf_type *t,
 				  const struct btf_member *member,
 				  void *kdata, const void *udata)
@@ -335,6 +345,7 @@ static struct bpf_struct_ops bpf_tcp_congestion_ops = {
 	.reg = bpf_tcp_ca_reg,
 	.unreg = bpf_tcp_ca_unreg,
 	.update = bpf_tcp_ca_update,
+	.check_member = bpf_tcp_ca_check_member,
 	.init_member = bpf_tcp_ca_init_member,
 	.init = bpf_tcp_ca_init,
 	.validate = bpf_tcp_ca_validate,
-- 
2.56.1
[PATCH bpf 2/3] bpf: net_sched: Reject sleepable programs in bpf qdisc
#21850
Author: Sechang Lim
Date: Tue, 24 Nov 2026 14:31
44 lines
12844 bytes
A bpf qdisc program can be loaded with BPF_F_SLEEPABLE, but enqueue and
dequeue run with the qdisc root lock held and BH disabled.

bpf_Qdisc_ops has no check_member, so nothing rejects such a program.
Add one that rejects sleepable programs.

Fixes: c8240344956e ("bpf: net_sched: Support implementation of Qdisc_ops in bpf")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 net/sched/bpf_qdisc.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/sched/bpf_qdisc.c b/net/sched/bpf_qdisc.c
index 5691c13781a8..3dbe52a04fa2 100644
--- a/net/sched/bpf_qdisc.c
+++ b/net/sched/bpf_qdisc.c
@@ -356,6 +356,16 @@ static const struct bpf_verifier_ops bpf_qdisc_verifier_ops = {
 	.gen_epilogue		= bpf_qdisc_gen_epilogue,
 };
 
+static int bpf_qdisc_check_member(const struct btf_type *t,
+				  const struct btf_member *member,
+				  const struct bpf_prog *prog)
+{
+	if (prog->sleepable)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int bpf_qdisc_init_member(const struct btf_type *t,
 				 const struct btf_member *member,
 				 void *kdata, const void *udata)
@@ -446,6 +456,7 @@ static struct bpf_struct_ops bpf_Qdisc_ops = {
 	.reg = bpf_qdisc_reg,
 	.unreg = bpf_qdisc_unreg,
 	.validate = bpf_qdisc_validate,
+	.check_member = bpf_qdisc_check_member,
 	.init_member = bpf_qdisc_init_member,
 	.init = bpf_qdisc_init,
 	.name = "Qdisc_ops",
-- 
2.56.1
[PATCH bpf 3/3] net/smc: bpf: Reject sleepable programs in smc_hs_ctrl
#21851
Author: Sechang Lim
Date: Tue, 24 Nov 2026 14:31
45 lines
12895 bytes
An smc_hs_ctrl program can be loaded with BPF_F_SLEEPABLE, but
smc_call_hsbpf() calls syn_option and synack_option under
rcu_read_lock().

bpf_smc_hs_ctrl_ops has no check_member, so nothing rejects such a
program. Add one that rejects sleepable programs.

Fixes: 15f295f55656 ("net/smc: bpf: Introduce generic hook for handshake flow")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 net/smc/smc_hs_bpf.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/smc/smc_hs_bpf.c b/net/smc/smc_hs_bpf.c
index 063d23d85850..66cf5143109a 100644
--- a/net/smc/smc_hs_bpf.c
+++ b/net/smc/smc_hs_bpf.c
@@ -82,6 +82,16 @@ static void smc_bpf_hs_ctrl_unreg(void *kdata, struct bpf_link *link)
 	smc_hs_ctrl_unreg(kdata);
 }
 
+static int smc_bpf_hs_ctrl_check_member(const struct btf_type *t,
+					const struct btf_member *member,
+					const struct bpf_prog *prog)
+{
+	if (prog->sleepable)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int smc_bpf_hs_ctrl_init_member(const struct btf_type *t,
 				       const struct btf_member *member,
 				       void *kdata, const void *udata)
@@ -130,6 +140,7 @@ static struct bpf_struct_ops bpf_smc_hs_ctrl_ops = {
 	.unreg		= smc_bpf_hs_ctrl_unreg,
 	.cfi_stubs	= &__smc_bpf_hs_ctrl,
 	.verifier_ops	= &smc_bpf_verifier_ops,
+	.check_member	= smc_bpf_hs_ctrl_check_member,
 	.init_member	= smc_bpf_hs_ctrl_init_member,
 	.owner		= THIS_MODULE,
 };
-- 
2.56.1
Re: [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context
#22086
Author: "Alexei Starovoitov"
Date: Tue, 24 Nov 2026 21:06
131 lines
16327 bytes
On Tue, Nov 24, 2026 at 06:31 AM Sechang Lim <rhkrqnwk98@gmail.com> wrote:
> atomic context. tcp_congestion_ops, Qdisc_ops and smc_hs_ctrl have no
> check_member, although the kernel calls their members in softirq, under
> a spinlock or under rcu_read_lock(). A sleepable program attached there

Not all of them. Qdisc_ops init and destroy run under rtnl and can sleep:

  qdisc_create_dflt()
    qdisc_alloc()                 kzalloc_node() with GFP_KERNEL
    ops->init(sch, NULL, extack)  no lock taken in between
  __qdisc_destroy()
    ops->destroy(qdisc)           fq_codel_destroy() takes a mutex here

A sleepable init is valid today. bpf_arena_alloc_pages() uses GFP_KERNEL
there instead of alloc_pages_nolock(). Patch 2 rejects such progs.

> This series adds a check_member that rejects sleepable programs to each
> of them, like bpf_tcp_ops does.

That makes four copies of one function. The default is the bug.
bpf_tcp_ops v2 and blk-iocost v1 missed the same check:
https://lore.kernel.org/bpf/20260623175006.3136053-12-ameryhung@gmail.com/
https://lore.kernel.org/bpf/178889947167.2.9168058946538747939@kernel.org/

Fix it once in check_struct_ops_btf_id(). Patches 1 and 3 go away.
sched_ext, hid, io_uring, binfmt_misc and bpf_dummy_ops have
check_member already, so they keep their sleepable progs.
A struct_ops with check_member still has to test prog->sleepable itself.

In place of the series.

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 1dd9db1..f7c7380 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2209,7 +2209,8 @@ struct btf_member;
  * @check_member: When defined, a callback invoked by the verifier to allow
  *		  the subsystem to determine if an entry in the struct_ops map
  *		  is valid. A nonzero return value means that the map is
- *		  invalid and should be rejected by the verifier.
+ *		  invalid and should be rejected by the verifier. When not
+ *		  defined, the verifier rejects sleepable progs.
  * @init_member: A callback that is invoked for each member of the struct_ops
  *		 map to allow the subsystem to initialize the member. A nonzero
  *		 value means the member could not be initialized. This callback
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 01a74e1..42a90c7 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -22244,6 +22244,10 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
 				mname, st_ops->name);
 			return err;
 		}
+	} else if (prog->sleepable) {
+		verbose(env, "member %s of struct %s cannot be sleepable\n",
+			mname, st_ops->name);
+		return -EINVAL;
 	}
 
 	if (prog->aux->priv_stack_requested && !bpf_jit_supports_private_stack()) {
diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
index 2ba73dd..4e54165 100644
--- a/net/ipv4/bpf_tcp_ops.c
+++ b/net/ipv4/bpf_tcp_ops.c
@@ -301,16 +301,6 @@ static int bpf_tcp_ops_init_member(const struct btf_type *t,
 	return 0;
 }
 
-static int bpf_tcp_ops_check_member(const struct btf_type *t,
-				    const struct btf_member *member,
-				    const struct bpf_prog *prog)
-{
-	if (prog->sleepable)
-		return -EINVAL;
-
-	return 0;
-}
-
 static int bpf_tcp_ops_init(struct btf *btf)
 {
 	return 0;
@@ -329,7 +319,6 @@ static const struct bpf_verifier_ops bpf_tcp_ops_verifier = {
 static struct bpf_struct_ops bpf_tcp_ops = {
 	.verifier_ops = &bpf_tcp_ops_verifier,
 	.init_member = bpf_tcp_ops_init_member,
-	.check_member = bpf_tcp_ops_check_member,
 	.init = bpf_tcp_ops_init,
 	.validate = bpf_tcp_ops_validate,
 	.name = "bpf_tcp_ops",
diff --git a/net/sched/bpf_qdisc.c b/net/sched/bpf_qdisc.c
index 5691c13..61a1971 100644
--- a/net/sched/bpf_qdisc.c
+++ b/net/sched/bpf_qdisc.c
@@ -356,6 +356,24 @@ static const struct bpf_verifier_ops bpf_qdisc_verifier_ops = {
 	.gen_epilogue		= bpf_qdisc_gen_epilogue,
 };
 
+static int bpf_qdisc_check_member(const struct btf_type *t,
+				  const struct btf_member *member,
+				  const struct bpf_prog *prog)
+{
+	u32 moff = __btf_member_bit_offset(t, member) / 8;
+
+	switch (moff) {
+	case offsetof(struct Qdisc_ops, init):
+	case offsetof(struct Qdisc_ops, destroy):
+		break;
+	default:
+		if (prog->sleepable)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int bpf_qdisc_init_member(const struct btf_type *t,
 				 const struct btf_member *member,
 				 void *kdata, const void *udata)
@@ -446,6 +464,7 @@ static struct bpf_struct_ops bpf_Qdisc_ops = {
 	.reg = bpf_qdisc_reg,
 	.unreg = bpf_qdisc_unreg,
 	.validate = bpf_qdisc_validate,
+	.check_member = bpf_qdisc_check_member,
 	.init_member = bpf_qdisc_init_member,
 	.init = bpf_qdisc_init,
 	.name = "Qdisc_ops",

Pls target bpf-next.

pw-bot: cr
Re: [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context
#22287
Author: Sechang Lim
Date: Wed, 25 Nov 2026 04:25
137 lines
16661 bytes
On Tue, Nov 24, 2026 at 09:06:37PM +0000, Alexei Starovoitov wrote:
>On Tue, Nov 24, 2026 at 06:31 AM Sechang Lim <rhkrqnwk98@gmail.com> wrote:
>> atomic context. tcp_congestion_ops, Qdisc_ops and smc_hs_ctrl have no
>> check_member, although the kernel calls their members in softirq, under
>> a spinlock or under rcu_read_lock(). A sleepable program attached there
>
>Not all of them. Qdisc_ops init and destroy run under rtnl and can sleep:
>
>  qdisc_create_dflt()
>    qdisc_alloc()                 kzalloc_node() with GFP_KERNEL
>    ops->init(sch, NULL, extack)  no lock taken in between
>  __qdisc_destroy()
>    ops->destroy(qdisc)           fq_codel_destroy() takes a mutex here
>
>A sleepable init is valid today. bpf_arena_alloc_pages() uses GFP_KERNEL
>there instead of alloc_pages_nolock(). Patch 2 rejects such progs.
>
>> This series adds a check_member that rejects sleepable programs to each
>> of them, like bpf_tcp_ops does.
>
>That makes four copies of one function. The default is the bug.
>bpf_tcp_ops v2 and blk-iocost v1 missed the same check:
>https://lore.kernel.org/bpf/20260623175006.3136053-12-ameryhung@gmail.com/
>https://lore.kernel.org/bpf/178889947167.2.9168058946538747939@kernel.org/
>
>Fix it once in check_struct_ops_btf_id(). Patches 1 and 3 go away.
>sched_ext, hid, io_uring, binfmt_misc and bpf_dummy_ops have
>check_member already, so they keep their sleepable progs.
>A struct_ops with check_member still has to test prog->sleepable itself.
>
>In place of the series.
>
>diff --git a/include/linux/bpf.h b/include/linux/bpf.h
>index 1dd9db1..f7c7380 100644
>--- a/include/linux/bpf.h
>+++ b/include/linux/bpf.h
>@@ -2209,7 +2209,8 @@ struct btf_member;
>  * @check_member: When defined, a callback invoked by the verifier to allow
>  *		  the subsystem to determine if an entry in the struct_ops map
>  *		  is valid. A nonzero return value means that the map is
>- *		  invalid and should be rejected by the verifier.
>+ *		  invalid and should be rejected by the verifier. When not
>+ *		  defined, the verifier rejects sleepable progs.
>  * @init_member: A callback that is invoked for each member of the struct_ops
>  *		 map to allow the subsystem to initialize the member. A nonzero
>  *		 value means the member could not be initialized. This callback
>diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>index 01a74e1..42a90c7 100644
>--- a/kernel/bpf/verifier.c
>+++ b/kernel/bpf/verifier.c
>@@ -22244,6 +22244,10 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
> 				mname, st_ops->name);
> 			return err;
> 		}
>+	} else if (prog->sleepable) {
>+		verbose(env, "member %s of struct %s cannot be sleepable\n",
>+			mname, st_ops->name);
>+		return -EINVAL;
> 	}
>
> 	if (prog->aux->priv_stack_requested && !bpf_jit_supports_private_stack()) {
>diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
>index 2ba73dd..4e54165 100644
>--- a/net/ipv4/bpf_tcp_ops.c
>+++ b/net/ipv4/bpf_tcp_ops.c
>@@ -301,16 +301,6 @@ static int bpf_tcp_ops_init_member(const struct btf_type *t,
> 	return 0;
> }
>
>-static int bpf_tcp_ops_check_member(const struct btf_type *t,
>-				    const struct btf_member *member,
>-				    const struct bpf_prog *prog)
>-{
>-	if (prog->sleepable)
>-		return -EINVAL;
>-
>-	return 0;
>-}
>-
> static int bpf_tcp_ops_init(struct btf *btf)
> {
> 	return 0;
>@@ -329,7 +319,6 @@ static const struct bpf_verifier_ops bpf_tcp_ops_verifier = {
> static struct bpf_struct_ops bpf_tcp_ops = {
> 	.verifier_ops = &bpf_tcp_ops_verifier,
> 	.init_member = bpf_tcp_ops_init_member,
>-	.check_member = bpf_tcp_ops_check_member,
> 	.init = bpf_tcp_ops_init,
> 	.validate = bpf_tcp_ops_validate,
> 	.name = "bpf_tcp_ops",
>diff --git a/net/sched/bpf_qdisc.c b/net/sched/bpf_qdisc.c
>index 5691c13..61a1971 100644
>--- a/net/sched/bpf_qdisc.c
>+++ b/net/sched/bpf_qdisc.c
>@@ -356,6 +356,24 @@ static const struct bpf_verifier_ops bpf_qdisc_verifier_ops = {
> 	.gen_epilogue		= bpf_qdisc_gen_epilogue,
> };
>
>+static int bpf_qdisc_check_member(const struct btf_type *t,
>+				  const struct btf_member *member,
>+				  const struct bpf_prog *prog)
>+{
>+	u32 moff = __btf_member_bit_offset(t, member) / 8;
>+
>+	switch (moff) {
>+	case offsetof(struct Qdisc_ops, init):
>+	case offsetof(struct Qdisc_ops, destroy):
>+		break;
>+	default:
>+		if (prog->sleepable)
>+			return -EINVAL;
>+	}
>+
>+	return 0;
>+}
>+
> static int bpf_qdisc_init_member(const struct btf_type *t,
> 				 const struct btf_member *member,
> 				 void *kdata, const void *udata)
>@@ -446,6 +464,7 @@ static struct bpf_struct_ops bpf_Qdisc_ops = {
> 	.reg = bpf_qdisc_reg,
> 	.unreg = bpf_qdisc_unreg,
> 	.validate = bpf_qdisc_validate,
>+	.check_member = bpf_qdisc_check_member,
> 	.init_member = bpf_qdisc_init_member,
> 	.init = bpf_qdisc_init,
> 	.name = "Qdisc_ops",
>
>Pls target bpf-next.
>

Thanks, that's cleaner. I'll move the check into check_struct_ops_btf_id()
and send v2 against bpf-next tree.

Thanks,
sechang
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads