Skip to content

Commit 56b1bc4

Browse files
ameryhungKernel Patches Daemon
authored and
Kernel Patches Daemon
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 <[email protected]>
1 parent 4f05866 commit 56b1bc4

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
@@ -207,7 +207,7 @@ static struct Qdisc_ops *qdisc_lookup_default(const char *name)
207207

208208
for (q = qdisc_base; q; q = q->next) {
209209
if (!strcmp(name, q->id)) {
210-
if (!try_module_get(q->owner))
210+
if (!bpf_try_module_get(q, q->owner))
211211
q = NULL;
212212
break;
213213
}
@@ -237,7 +237,7 @@ int qdisc_set_default(const char *name)
237237

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

net/sched/sch_generic.c

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

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

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

0 commit comments

Comments
 (0)