bpf: net_sched: Fix using bpf qdisc as default qdisc
Subsystems (4)
PATCH 1/1 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
--- net/sched/sch_api.c | 4 ++-- net/sched/sch_generic.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
net/sched/sch_api.c +2 -2
@@ -208,7 +208,7 @@ static struct Qdisc_ops *qdisc_lookup_default(const char *name)for (q = qdisc_base; q; q = q->next) {if (!strcmp (name, q->id)) { -if (!try_module_get (q->owner)) +if (!bpf_try_module_get (q, q->owner)) q =NULL ;break ; }
@@ -238,7 +238,7 @@ int qdisc_set_default(const char *name)if (ops) {/* Set new default */ -module_put (default_qdisc_ops->owner); +bpf_module_put (ops, default_qdisc_ops->owner); default_qdisc_ops = ops; }write_unlock (&qdisc_mod_lock);
net/sched/sch_generic.c +2 -2
@@ -1002,14 +1002,14 @@ struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue, {struct Qdisc *sch; -if (!try_module_get (ops->owner)) { +if (!bpf_try_module_get (ops, ops->owner)) {NL_SET_ERR_MSG (extack,"Failed to increase module reference counter" );return NULL ; } sch =qdisc_alloc (dev_queue, ops, extack);if (IS_ERR (sch)) { -module_put (ops->owner); +bpf_module_put (ops, ops->owner);return NULL ; } sch->parent = parentid;
Signature · 1 line
2.47.1
Quoted 8 lines · Amery Hung
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
Good to see eBPF Qdisc's can be default as well.
Quoted 2 lines
Fixes c8240344956e (bpf: net_sched: Support implementation of Qdisc_ops in bpf)Signed-off-by Amery Hung <[email protected]>
Thanks!
Martin KaFai Lau
reviewerQuoted 14 lines · Amery Hung
net/sched/sch_api.c +1
-1@@ -208,7 +208,7 @@ static struct Qdisc_ops *qdisc_lookup_default(const char *name)for (q = qdisc_base; q; q = q->next) {if (!strcmp (name, q->id)) { -if (!try_module_get (q->owner)) +if (!bpf_try_module_get (q, q->owner)) q =NULL ;break ; }
net/sched/sch_api.c int qdisc_set_default(const char *name) · line 241
Quoted 5 lines
net/sched/sch_api.c +1
-1@@ -238,7 +238,7 @@ int qdisc_set_default(const char *name)if (ops) {/* Set new default */ -module_put (default_qdisc_ops->owner); +bpf_module_put (ops, default_qdisc_ops->owner);
The first arg, should it be the "default_qdisc_ops" instead?
Quoted 3 lines
net/sched/sch_api.c +0
-0default_qdisc_ops = ops; }write_unlock (&qdisc_mod_lock);
Quoted 17 lines · Martin KaFai Lau
Quoted 15 lines · Amery Hung
net/sched/sch_api.c +1
-1@@ -208,7 +208,7 @@ static struct Qdisc_ops *qdisc_lookup_default(const char *name)for (q = qdisc_base; q; q = q->next) {if (!strcmp (name, q->id)) { -if (!try_module_get (q->owner)) +if (!bpf_try_module_get (q, q->owner)) q =NULL ;break ; }@@ -238,7 +238,7 @@ int qdisc_set_default(const char *name)
Quoted 7 lines
net/sched/sch_api.c int qdisc_set_default(const char *name) · line 241
Quoted 4 lines
net/sched/sch_api.c +1
-1if (ops) {/* Set new default */ -module_put (default_qdisc_ops->owner); +bpf_module_put (ops, default_qdisc_ops->owner);The first arg, should it be the "
default_qdisc_ops" instead?
You are right. I will fix this sloppy mistake and resend.
Thanks,
Amery
Quoted 4 lines
Quoted 4 lines
net/sched/sch_api.c +0
-0default_qdisc_ops = ops; }write_unlock (&qdisc_mod_lock);