diff options
| author | Neil Horman <nhorman@tuxdriver.com> | 2012-02-10 00:43:38 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2012-02-10 15:08:57 -0500 |
| commit | 2b73bc65e2771372c818db7955709c8caedbf8b9 (patch) | |
| tree | 4cd1bfe8284d9266d45f5de11e3f4d8fbfcdbf4f /include | |
| parent | f5c38208d32412d72b97a4f0d44af0eb39feb20b (diff) | |
netprio_cgroup: fix wrong memory access when NETPRIO_CGROUP=m
When the netprio_cgroup module is not loaded, net_prio_subsys_id
is -1, and so sock_update_prioidx() accesses cgroup_subsys array
with negative index subsys[-1].
Make the code resembles cls_cgroup code, which is bug free.
Origionally-authored-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
CC: "David S. Miller" <davem@davemloft.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
| -rw-r--r-- | include/net/netprio_cgroup.h | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/include/net/netprio_cgroup.h b/include/net/netprio_cgroup.h index 7b2d43139c8e..d58fdec47597 100644 --- a/include/net/netprio_cgroup.h +++ b/include/net/netprio_cgroup.h | |||
| @@ -37,19 +37,51 @@ extern int net_prio_subsys_id; | |||
| 37 | 37 | ||
| 38 | extern void sock_update_netprioidx(struct sock *sk); | 38 | extern void sock_update_netprioidx(struct sock *sk); |
| 39 | 39 | ||
| 40 | static inline struct cgroup_netprio_state | 40 | #if IS_BUILTIN(CONFIG_NETPRIO_CGROUP) |
| 41 | *task_netprio_state(struct task_struct *p) | 41 | |
| 42 | static inline u32 task_netprioidx(struct task_struct *p) | ||
| 42 | { | 43 | { |
| 43 | #if IS_ENABLED(CONFIG_NETPRIO_CGROUP) | 44 | struct cgroup_netprio_state *state; |
| 44 | return container_of(task_subsys_state(p, net_prio_subsys_id), | 45 | u32 idx; |
| 45 | struct cgroup_netprio_state, css); | 46 | |
| 46 | #else | 47 | rcu_read_lock(); |
| 47 | return NULL; | 48 | state = container_of(task_subsys_state(p, net_prio_subsys_id), |
| 48 | #endif | 49 | struct cgroup_netprio_state, css); |
| 50 | idx = state->prioidx; | ||
| 51 | rcu_read_unlock(); | ||
| 52 | return idx; | ||
| 53 | } | ||
| 54 | |||
| 55 | #elif IS_MODULE(CONFIG_NETPRIO_CGROUP) | ||
| 56 | |||
| 57 | static inline u32 task_netprioidx(struct task_struct *p) | ||
| 58 | { | ||
| 59 | struct cgroup_netprio_state *state; | ||
| 60 | int subsys_id; | ||
| 61 | u32 idx = 0; | ||
| 62 | |||
| 63 | rcu_read_lock(); | ||
| 64 | subsys_id = rcu_dereference_index_check(net_prio_subsys_id, | ||
| 65 | rcu_read_lock_held()); | ||
| 66 | if (subsys_id >= 0) { | ||
| 67 | state = container_of(task_subsys_state(p, subsys_id), | ||
| 68 | struct cgroup_netprio_state, css); | ||
| 69 | idx = state->prioidx; | ||
| 70 | } | ||
| 71 | rcu_read_unlock(); | ||
| 72 | return idx; | ||
| 49 | } | 73 | } |
| 50 | 74 | ||
| 51 | #else | 75 | #else |
| 52 | 76 | ||
| 77 | static inline u32 task_netprioidx(struct task_struct *p) | ||
| 78 | { | ||
| 79 | return 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | #endif /* CONFIG_NETPRIO_CGROUP */ | ||
| 83 | |||
| 84 | #else | ||
| 53 | #define sock_update_netprioidx(sk) | 85 | #define sock_update_netprioidx(sk) |
| 54 | #endif | 86 | #endif |
| 55 | 87 | ||
