Skip to content

Commit 297dbde

Browse files
htejundavem330
authored andcommitted
netprio_cgroup: limit the maximum css->id to USHRT_MAX
netprio builds per-netdev contiguous priomap array which is indexed by css->id. The array is allocated using kzalloc() effectively limiting the maximum ID supported to some thousand range. This patch caps the maximum supported css->id to USHRT_MAX which should be way above what is actually useable. This allows reducing sock->sk_cgrp_prioidx to u16 from u32. The freed up part will be used to overload the cgroup related fields. sock->sk_cgrp_prioidx's position is swapped with sk_mark so that the two cgroup related fields are adjacent. Signed-off-by: Tejun Heo <[email protected]> Acked-by: Daniel Wagner <[email protected]> Cc: Daniel Borkmann <[email protected]> CC: Neil Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bc9b145 commit 297dbde

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/net/sock.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ struct cg_proto;
288288
* @sk_ack_backlog: current listen backlog
289289
* @sk_max_ack_backlog: listen backlog set in listen()
290290
* @sk_priority: %SO_PRIORITY setting
291-
* @sk_cgrp_prioidx: socket group's priority map index
292291
* @sk_type: socket type (%SOCK_STREAM, etc)
293292
* @sk_protocol: which protocol this socket belongs in this network family
294293
* @sk_peer_pid: &struct pid for this socket's peer
@@ -309,6 +308,7 @@ struct cg_proto;
309308
* @sk_send_head: front of stuff to transmit
310309
* @sk_security: used by security modules
311310
* @sk_mark: generic packet mark
311+
* @sk_cgrp_prioidx: socket group's priority map index
312312
* @sk_classid: this socket's cgroup classid
313313
* @sk_cgrp: this socket's cgroup-specific proto data
314314
* @sk_write_pending: a write to stream socket waits to start
@@ -425,9 +425,7 @@ struct sock {
425425
u32 sk_ack_backlog;
426426
u32 sk_max_ack_backlog;
427427
__u32 sk_priority;
428-
#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
429-
__u32 sk_cgrp_prioidx;
430-
#endif
428+
__u32 sk_mark;
431429
struct pid *sk_peer_pid;
432430
const struct cred *sk_peer_cred;
433431
long sk_rcvtimeo;
@@ -445,7 +443,9 @@ struct sock {
445443
#ifdef CONFIG_SECURITY
446444
void *sk_security;
447445
#endif
448-
__u32 sk_mark;
446+
#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
447+
u16 sk_cgrp_prioidx;
448+
#endif
449449
#ifdef CONFIG_CGROUP_NET_CLASSID
450450
u32 sk_classid;
451451
#endif

net/core/netprio_cgroup.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
#include <linux/fdtable.h>
2929

30+
/*
31+
* netprio allocates per-net_device priomap array which is indexed by
32+
* css->id. Limiting css ID to 16bits doesn't lose anything.
33+
*/
34+
#define NETPRIO_ID_MAX USHRT_MAX
35+
3036
#define PRIOMAP_MIN_SZ 128
3137

3238
/*
@@ -144,6 +150,9 @@ static int cgrp_css_online(struct cgroup_subsys_state *css)
144150
struct net_device *dev;
145151
int ret = 0;
146152

153+
if (css->id > NETPRIO_ID_MAX)
154+
return -ENOSPC;
155+
147156
if (!parent_css)
148157
return 0;
149158

0 commit comments

Comments
 (0)