[PATCH v0 4/5] cgroup: Protect access to task_netprioidx() when built as module
From: Daniel Wagner <hidden>
Date: 2012-08-16 14:12:15
Also in:
cgroups
Subsystem:
networking [general], networking [sockets], the rest · Maintainers:
"David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Kuniyuki Iwashima, Willem de Bruijn, Linus Torvalds
From: Daniel Wagner <redacted> The module version of task_netprioidex() checks if net_prio_subsys_id is valid to indentify when it is okay to access the controller. Instead relying on the net_prio_subsys_id to be set, make it explicit with a jump label. Signed-off-by: Daniel Wagner <redacted> Cc: "David S. Miller" <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org> Cc: Gao feng <redacted> Cc: Jamal Hadi Salim <jhs-jkUAjuhPggJWk0Htik3J/w@public.gmane.org> Cc: John Fastabend <redacted> Cc: Li Zefan <redacted> Cc: Neil Horman <redacted> Cc: Tejun Heo <redacted> Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org --- include/net/netprio_cgroup.h | 10 +++++++++- net/core/netprio_cgroup.c | 6 ++++++ net/core/sock.c | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/include/net/netprio_cgroup.h b/include/net/netprio_cgroup.h
index 2719dec..a0fd35a 100644
--- a/include/net/netprio_cgroup.h
+++ b/include/net/netprio_cgroup.h@@ -16,7 +16,7 @@ #include <linux/cgroup.h> #include <linux/hardirq.h> #include <linux/rcupdate.h> - +#include <linux/jump_label.h> struct netprio_map { struct rcu_head rcu;
@@ -35,6 +35,11 @@ struct cgroup_netprio_state { extern int net_prio_subsys_id; #endif +#if IS_ENABLED(CONFIG_NETPRIO_CGROUP) +extern struct static_key cgroup_netprio_enabled; +#define netpriocg_enabled static_key_false(&cgroup_netprio_enabled) +#endif + extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task); #if IS_BUILTIN(CONFIG_NETPRIO_CGROUP)
@@ -60,6 +65,9 @@ static inline u32 task_netprioidx(struct task_struct *p) int subsys_id; u32 idx = 0; + if (!netpriocg_enabled) + return 0; + rcu_read_lock(); subsys_id = rcu_dereference_index_check(net_prio_subsys_id, rcu_read_lock_held());
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index ed0c043..6fef72f 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c@@ -155,6 +155,9 @@ static struct cgroup_subsys_state *cgrp_create(struct cgroup *cgrp) goto out; } + if (!netpriocg_enabled && !cgrp->parent) + static_key_slow_inc(&cgroup_netprio_enabled); + ret = update_netdev_tables(); if (ret < 0) { put_prioidx(cs->prioidx);
@@ -173,6 +176,9 @@ static void cgrp_destroy(struct cgroup *cgrp) struct net_device *dev; struct netprio_map *map; + if (netpriocg_enabled && !cgrp->parent) + static_key_slow_dec(&cgroup_netprio_enabled); + cs = cgrp_netprio_state(cgrp); rtnl_lock(); for_each_netdev(&init_net, dev) {
diff --git a/net/core/sock.c b/net/core/sock.c
index 8d3a400..d00da68 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c@@ -331,6 +331,10 @@ EXPORT_SYMBOL(__sk_backlog_rcv); struct static_key cgroup_cls_enabled = STATIC_KEY_INIT_FALSE; EXPORT_SYMBOL_GPL(cgroup_cls_enabled); #endif +#if IS_ENABLED(CONFIG_NETPRIO_CGROUP) +struct static_key cgroup_netprio_enabled = STATIC_KEY_INIT_FALSE; +EXPORT_SYMBOL_GPL(cgroup_netprio_enabled); +#endif #if !defined(CONFIG_NET_CLS_CGROUP) int net_cls_subsys_id = -1;
--
1.7.12.rc1.16.g05a20c8