Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <tj@kernel.org>
Acked-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>
CC: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Tejun Heo and committed by
David S. Miller
297dbde1 bc9b145a

+14 -5
+5 -5
include/net/sock.h
··· 288 288 * @sk_ack_backlog: current listen backlog 289 289 * @sk_max_ack_backlog: listen backlog set in listen() 290 290 * @sk_priority: %SO_PRIORITY setting 291 - * @sk_cgrp_prioidx: socket group's priority map index 292 291 * @sk_type: socket type (%SOCK_STREAM, etc) 293 292 * @sk_protocol: which protocol this socket belongs in this network family 294 293 * @sk_peer_pid: &struct pid for this socket's peer ··· 308 309 * @sk_send_head: front of stuff to transmit 309 310 * @sk_security: used by security modules 310 311 * @sk_mark: generic packet mark 312 + * @sk_cgrp_prioidx: socket group's priority map index 311 313 * @sk_classid: this socket's cgroup classid 312 314 * @sk_cgrp: this socket's cgroup-specific proto data 313 315 * @sk_write_pending: a write to stream socket waits to start ··· 425 425 u32 sk_ack_backlog; 426 426 u32 sk_max_ack_backlog; 427 427 __u32 sk_priority; 428 - #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO) 429 - __u32 sk_cgrp_prioidx; 430 - #endif 428 + __u32 sk_mark; 431 429 struct pid *sk_peer_pid; 432 430 const struct cred *sk_peer_cred; 433 431 long sk_rcvtimeo; ··· 443 445 #ifdef CONFIG_SECURITY 444 446 void *sk_security; 445 447 #endif 446 - __u32 sk_mark; 448 + #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO) 449 + u16 sk_cgrp_prioidx; 450 + #endif 447 451 #ifdef CONFIG_CGROUP_NET_CLASSID 448 452 u32 sk_classid; 449 453 #endif
+9
net/core/netprio_cgroup.c
··· 27 27 28 28 #include <linux/fdtable.h> 29 29 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 + 30 36 #define PRIOMAP_MIN_SZ 128 31 37 32 38 /* ··· 149 143 struct cgroup_subsys_state *parent_css = css->parent; 150 144 struct net_device *dev; 151 145 int ret = 0; 146 + 147 + if (css->id > NETPRIO_ID_MAX) 148 + return -ENOSPC; 152 149 153 150 if (!parent_css) 154 151 return 0;