* [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context
@ 2026-11-24 14:31 Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 1/3] bpf: Reject sleepable programs in bpf-tcp-cc Sechang Lim
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Sechang Lim @ 2026-11-24 14:31 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jamal Hadi Salim, Jiri Pirko, Amery Hung, Cong Wang,
Toke Høiland-Jørgensen, D . Wythe, Dust Li,
Sidraya Jayagond, Mahanta Jambigi, Tony Lu, Wen Gu, David Vernet,
bpf, netdev, linux-rdma, linux-s390
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf 1/3] bpf: Reject sleepable programs in bpf-tcp-cc
2026-11-24 14:31 [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Sechang Lim
@ 2026-11-24 14:31 ` Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 2/3] bpf: net_sched: Reject sleepable programs in bpf qdisc Sechang Lim
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sechang Lim @ 2026-11-24 14:31 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jamal Hadi Salim, Jiri Pirko, Amery Hung, Cong Wang,
Toke Høiland-Jørgensen, D . Wythe, Dust Li,
Sidraya Jayagond, Mahanta Jambigi, Tony Lu, Wen Gu, David Vernet,
bpf, netdev, linux-rdma, linux-s390
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf 2/3] bpf: net_sched: Reject sleepable programs in bpf qdisc
2026-11-24 14:31 [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 1/3] bpf: Reject sleepable programs in bpf-tcp-cc Sechang Lim
@ 2026-11-24 14:31 ` Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 3/3] net/smc: bpf: Reject sleepable programs in smc_hs_ctrl Sechang Lim
2026-11-24 21:06 ` [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Alexei Starovoitov
3 siblings, 0 replies; 5+ messages in thread
From: Sechang Lim @ 2026-11-24 14:31 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jamal Hadi Salim, Jiri Pirko, Amery Hung, Cong Wang,
Toke Høiland-Jørgensen, D . Wythe, Dust Li,
Sidraya Jayagond, Mahanta Jambigi, Tony Lu, Wen Gu, David Vernet,
bpf, netdev, linux-rdma, linux-s390
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf 3/3] net/smc: bpf: Reject sleepable programs in smc_hs_ctrl
2026-11-24 14:31 [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 1/3] bpf: Reject sleepable programs in bpf-tcp-cc Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 2/3] bpf: net_sched: Reject sleepable programs in bpf qdisc Sechang Lim
@ 2026-11-24 14:31 ` Sechang Lim
2026-11-24 21:06 ` [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Alexei Starovoitov
3 siblings, 0 replies; 5+ messages in thread
From: Sechang Lim @ 2026-11-24 14:31 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jamal Hadi Salim, Jiri Pirko, Amery Hung, Cong Wang,
Toke Høiland-Jørgensen, D . Wythe, Dust Li,
Sidraya Jayagond, Mahanta Jambigi, Tony Lu, Wen Gu, David Vernet,
bpf, netdev, linux-rdma, linux-s390
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context
2026-11-24 14:31 [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Sechang Lim
` (2 preceding siblings ...)
2026-11-24 14:31 ` [PATCH bpf 3/3] net/smc: bpf: Reject sleepable programs in smc_hs_ctrl Sechang Lim
@ 2026-11-24 21:06 ` Alexei Starovoitov
3 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2026-11-24 21:06 UTC (permalink / raw)
To: Sechang Lim, Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jamal Hadi Salim, Jiri Pirko, Amery Hung, Cong Wang,
Toke Høiland-Jørgensen, D . Wythe, Dust Li,
Sidraya Jayagond, Mahanta Jambigi, Tony Lu, Wen Gu, David Vernet,
bpf, netdev, linux-rdma, linux-s390
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-24 21:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 14:31 [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 1/3] bpf: Reject sleepable programs in bpf-tcp-cc Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 2/3] bpf: net_sched: Reject sleepable programs in bpf qdisc Sechang Lim
2026-11-24 14:31 ` [PATCH bpf 3/3] net/smc: bpf: Reject sleepable programs in smc_hs_ctrl Sechang Lim
2026-11-24 21:06 ` [PATCH bpf 0/3] bpf: Reject sleepable struct_ops programs in atomic context Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox