kernel_optimize_test/net
Johannes Berg 8cb081746c netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:

 1) liberal (default)
     - undefined (type >= max) & NLA_UNSPEC attributes accepted
     - attribute length >= expected accepted
     - garbage at end of message accepted
 2) strict (opt-in)
     - NLA_UNSPEC attributes accepted
     - attribute length >= expected accepted

Split out parsing strictness into four different options:
 * TRAILING     - check that there's no trailing data after parsing
                  attributes (in message or nested)
 * MAXTYPE      - reject attrs > max known type
 * UNSPEC       - reject attributes with NLA_UNSPEC policy entries
 * STRICT_ATTRS - strictly validate attribute size

The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().

Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.

We end up with the following renames:
 * nla_parse           -> nla_parse_deprecated
 * nla_parse_strict    -> nla_parse_deprecated_strict
 * nlmsg_parse         -> nlmsg_parse_deprecated
 * nlmsg_parse_strict  -> nlmsg_parse_deprecated_strict
 * nla_parse_nested    -> nla_parse_nested_deprecated
 * nla_validate_nested -> nla_validate_nested_deprecated

Using spatch, of course:
    @@
    expression TB, MAX, HEAD, LEN, POL, EXT;
    @@
    -nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
    +nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)

    @@
    expression NLH, HDRLEN, TB, MAX, POL, EXT;
    @@
    -nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
    +nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)

    @@
    expression NLH, HDRLEN, TB, MAX, POL, EXT;
    @@
    -nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
    +nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)

    @@
    expression TB, MAX, NLA, POL, EXT;
    @@
    -nla_parse_nested(TB, MAX, NLA, POL, EXT)
    +nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)

    @@
    expression START, MAX, POL, EXT;
    @@
    -nla_validate_nested(START, MAX, POL, EXT)
    +nla_validate_nested_deprecated(START, MAX, POL, EXT)

    @@
    expression NLH, HDRLEN, MAX, POL, EXT;
    @@
    -nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
    +nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)

For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.

Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.

Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.

In effect then, this adds fully strict validation for any new command.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-27 17:07:21 -04:00
..
6lowpan 6lowpan: Off by one handling ->nexthdr 2019-04-23 19:09:58 +02:00
9p 9p/net: fix memory leak in p9_client_create 2019-03-13 11:50:04 +01:00
802
8021q netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
appletalk net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
atm net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
ax25 net: ax25: fix misuse of %x 2019-04-21 10:37:26 -07:00
batman-adv Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-04-05 14:14:19 -07:00
bluetooth Bluetooth: Align minimum encryption key size for LE and BR/EDR connections 2019-04-25 06:18:07 -07:00
bpf bpf: explicitly prohibit ctx_{in, out} in non-skb BPF_PROG_TEST_RUN 2019-04-12 00:53:00 +02:00
bpfilter bpfilter: re-add header search paths to tools include to fix build error 2019-02-23 13:34:40 -08:00
bridge netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
caif net: caif: avoid using qdisc_qlen() 2019-04-10 12:20:46 -07:00
can netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
ceph libceph: fix breakage caused by multipage bvecs 2019-03-25 22:28:07 +01:00
core netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
dcb netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
dccp net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
decnet netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
dns_resolver dns: remove redundant zero length namelen check 2019-04-11 14:01:08 -07:00
dsa Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-04-05 14:14:19 -07:00
ethernet net/ethernet: Add parse_protocol header_ops support 2019-02-22 12:55:31 -08:00
hsr net: hsr: add tx stats for master interface 2019-04-15 17:22:02 -07:00
ieee802154 netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
ife
ipv4 netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
ipv6 netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
iucv
kcm kcm: switch order of device registration to fix a crash 2019-04-01 14:59:20 -07:00
key af_key: unconditionally clone on broadcast 2019-02-12 10:36:42 +01:00
l2tp netlink: make nla_nest_start() add NLA_F_NESTED flag 2019-04-27 17:03:44 -04:00
l3mdev
lapb
llc llc: Check address length before reading address field 2019-04-12 10:25:03 -07:00
mac80211 Various updates, notably: 2019-04-26 16:05:52 -04:00
mac802154
mpls netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
ncsi netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
netfilter netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
netlabel netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
netlink netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
netrom net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
nfc netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
nsh
openvswitch netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
packet netlink: make nla_nest_start() add NLA_F_NESTED flag 2019-04-27 17:03:44 -04:00
phonet netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
psample
qrtr netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
rds net: rds: exchange of 8K and 1M pool 2019-04-24 12:07:08 -07:00
rfkill
rose Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-04-25 23:52:29 -04:00
rxrpc Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-04-25 23:52:29 -04:00
sched netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
sctp net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
smc Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-04-17 11:26:25 -07:00
strparser net: strparser: make it explicitly non-modular 2019-04-22 21:50:54 -07:00
sunrpc Fix miscellaneous nfsd bugs, in NFSv4.1 callbacks, NFSv4.1 2019-04-23 13:40:55 -07:00
switchdev switchdev: Remove unused transaction item queue 2019-03-01 21:35:19 -08:00
tipc netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
tls net/tls: byte swap device req TCP seq no upon setting 2019-04-27 16:52:21 -04:00
unix datagram: remove rendundant 'peeked' argument 2019-04-08 09:51:54 -07:00
vmw_vsock vsock/virtio: fix kernel panic from virtio_transport_reset_no_sock 2019-03-08 15:15:44 -08:00
wimax genetlink: make policy common to family 2019-03-22 10:38:23 -04:00
wireless netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
x25 net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
xdp xsk: fix XDP socket ring buffer memory ordering 2019-04-16 20:13:10 -07:00
xfrm netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
compat.c net: rework SIOCGSTAMP ioctl handling 2019-04-19 14:07:40 -07:00
Kconfig net: devlink: select NET_DEVLINK from drivers 2019-03-24 14:55:31 -04:00
Makefile net: split out functions related to registering inflight socket files 2019-02-28 08:24:23 -07:00
socket.c net: socket: Fix missing break in switch statement 2019-04-26 11:28:47 -04:00
sysctl_net.c