OSDN Git Service

netlink: add attribute range validation to policy
authorJohannes Berg <johannes.berg@intel.com>
Thu, 27 Sep 2018 09:28:35 +0000 (11:28 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Oct 2018 06:05:31 +0000 (23:05 -0700)
commit3e48be05f3c7eb6f6126939e9d957903c5cfeee5
tree866035464b1e44661e6ac5459f80db6580364a93
parent6140cc20caf7da861fb113a707e0acc36bd358ec
netlink: add attribute range validation to policy

Without further bloating the policy structs, we can overload
the `validation_data' pointer with a struct of s16 min, max
and use those to validate ranges in NLA_{U,S}{8,16,32,64}
attributes.

It may sound strange to validate NLA_U32 with a s16 max, but
in many cases NLA_U32 is used for enums etc. since there's no
size benefit in using a smaller attribute width anyway, due
to netlink attribute alignment; in cases like that it's still
useful, particularly when the attribute really transports an
enum value.

Doing so lets us remove quite a bit of validation code, if we
can be sure that these attributes aren't used by userspace in
places where they're ignored today.

To achieve all this, split the 'type' field and introduce a
new 'validation_type' field which indicates what further
validation (beyond the validation prescribed by the type of
the attribute) is done. This currently allows for no further
validation (the default), as well as min, max and range checks.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netlink.h
lib/nlattr.c