* [PATCH bpf-next v2] bpf: Reject sleepable struct_ops programs without check_member
@ 2026-11-25 4:50 Sechang Lim
2026-11-25 4:58 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Sechang Lim @ 2026-11-25 4:50 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Kumar Kartikeya Dwivedi
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jamal Hadi Salim, Jiri Pirko, Amery Hung,
Kuniyuki Iwashima, 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. tcp_congestion_ops, Qdisc_ops
and smc_hs_ctrl have no check_member, although the kernel calls most of
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".
Reject sleepable programs in the verifier when the struct_ops has no
check_member, and drop the check in bpf_tcp_ops that is now the
default. Qdisc_ops init and destroy run under rtnl and can sleep, so
give bpf qdisc a check_member that still allows sleepable programs
there.
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
v2:
- Fix the default in check_struct_ops_btf_id() (Alexei)
- Keep sleepable Qdisc_ops init and destroy (Alexei)
- Target bpf-next
v1: https://lore.kernel.org/bpf/20261124143123.1182108-1-rhkrqnwk98@gmail.com/
include/linux/bpf.h | 3 ++-
kernel/bpf/verifier.c | 4 ++++
net/ipv4/bpf_tcp_ops.c | 11 -----------
net/sched/bpf_qdisc.c | 19 +++++++++++++++++++
4 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 4e9a4d15af0e..95835534b065 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2253,7 +2253,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 e7013ed8cadd..8c7e43220df3 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -23934,6 +23934,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 2ba73dd6c52c..4e54165a3928 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 5691c13781a8..61a19713c5ec 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",
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH bpf-next v2] bpf: Reject sleepable struct_ops programs without check_member
2026-11-25 4:50 [PATCH bpf-next v2] bpf: Reject sleepable struct_ops programs without check_member Sechang Lim
@ 2026-11-25 4:58 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-25 4:58 UTC (permalink / raw)
To: Sechang Lim
Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger
> Any struct_ops program can be loaded as sleepable, and it is up to each
> struct_ops to reject that in check_member. tcp_congestion_ops, Qdisc_ops
> and smc_hs_ctrl have no check_member, although the kernel calls most of
> 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".
>
> Reject sleepable programs in the verifier when the struct_ops has no
> check_member, and drop the check in bpf_tcp_ops that is now the
> default. Qdisc_ops init and destroy run under rtnl and can sleep, so
> give bpf qdisc a check_member that still allows sleepable programs
> there.
>
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125045105.2326120-1-rhkrqnwk98@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 4:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 4:50 [PATCH bpf-next v2] bpf: Reject sleepable struct_ops programs without check_member Sechang Lim
2026-11-25 4:58 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox