rtnetlink: Remove VLA usage
authorKees Cook <keescook@chromium.org>
Wed, 30 May 2018 22:20:52 +0000 (15:20 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Jun 2018 02:48:46 +0000 (22:48 -0400)
commitccf8dbcd062a930e64741c939ca784d15316aa0c
tree2ee1f0523cb121c01d5bc082875c1393ce8691dd
parent7bb8c9969d919517fc379cacebd8fa93704173db
rtnetlink: Remove VLA usage

In the quest to remove all stack VLA usage from the kernel[1], this
allocates the maximum size expected for all possible types and adds
sanity-checks at both registration and usage to make sure nothing gets
out of sync. This matches the proposed VLA solution for nfnetlink[2]. The
values chosen here were based on finding assignments for .maxtype and
.slave_maxtype and manually counting the enums:

slave_maxtype (max 33):
IFLA_BRPORT_MAX     33
IFLA_BOND_SLAVE_MAX  9

maxtype (max 45):
IFLA_BOND_MAX       28
IFLA_BR_MAX         45
__IFLA_CAIF_HSI_MAX  8
IFLA_CAIF_MAX        4
IFLA_CAN_MAX        16
IFLA_GENEVE_MAX     12
IFLA_GRE_MAX        25
IFLA_GTP_MAX         5
IFLA_HSR_MAX         7
IFLA_IPOIB_MAX       4
IFLA_IPTUN_MAX      21
IFLA_IPVLAN_MAX      3
IFLA_MACSEC_MAX     15
IFLA_MACVLAN_MAX     7
IFLA_PPP_MAX         2
__IFLA_RMNET_MAX     4
IFLA_VLAN_MAX        6
IFLA_VRF_MAX         2
IFLA_VTI_MAX         7
IFLA_VXLAN_MAX      28
VETH_INFO_MAX        2
VXCAN_INFO_MAX       2

This additionally changes maxtype and slave_maxtype fields to unsigned,
since they're only ever using positive values.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
[2] https://patchwork.kernel.org/patch/10439647/

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/rtnetlink.h
net/core/rtnetlink.c