Skip to content

Commit 7625645

Browse files
ameryhungMartin KaFai Lau
authored and
Martin KaFai Lau
committed
bpf: net_sched: Fix using bpf qdisc as default qdisc
Use bpf_try_module_get()/bpf_module_put() instead of try_module_get()/ module_put() when handling default qdisc since users can assign a bpf qdisc to it. To trigger the bug: $ bpftool struct_ops register bpf_qdisc_fq.bpf.o /sys/fs/bpf $ echo bpf_fq > /proc/sys/net/core/default_qdisc Fixes: c824034 ("bpf: net_sched: Support implementation of Qdisc_ops in bpf") Signed-off-by: Amery Hung <ameryhung@gmail.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://patch.msgid.link/20250429192128.3860571-1-ameryhung@gmail.com
1 parent 1ce6510 commit 7625645

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

net/sched/sch_api.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static struct Qdisc_ops *qdisc_lookup_default(const char *name)
208208

209209
for (q = qdisc_base; q; q = q->next) {
210210
if (!strcmp(name, q->id)) {
211-
if (!try_module_get(q->owner))
211+
if (!bpf_try_module_get(q, q->owner))
212212
q = NULL;
213213
break;
214214
}
@@ -238,7 +238,7 @@ int qdisc_set_default(const char *name)
238238

239239
if (ops) {
240240
/* Set new default */
241-
module_put(default_qdisc_ops->owner);
241+
bpf_module_put(default_qdisc_ops, default_qdisc_ops->owner);
242242
default_qdisc_ops = ops;
243243
}
244244
write_unlock(&qdisc_mod_lock);

net/sched/sch_generic.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,14 @@ struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
10021002
{
10031003
struct Qdisc *sch;
10041004

1005-
if (!try_module_get(ops->owner)) {
1005+
if (!bpf_try_module_get(ops, ops->owner)) {
10061006
NL_SET_ERR_MSG(extack, "Failed to increase module reference counter");
10071007
return NULL;
10081008
}
10091009

10101010
sch = qdisc_alloc(dev_queue, ops, extack);
10111011
if (IS_ERR(sch)) {
1012-
module_put(ops->owner);
1012+
bpf_module_put(ops, ops->owner);
10131013
return NULL;
10141014
}
10151015
sch->parent = parentid;

0 commit comments

Comments
 (0)