Thread (5 messages) 5 messages, 2 authors, 2018-09-27

Re: [PATCH] netlink: add policy attribute range validation

From: Johannes Berg <johannes@sipsolutions.net>
Date: 2018-09-27 02:32:43
Also in: linux-wireless

On Wed, 2018-09-26 at 22:06 +0200, Johannes Berg wrote:
From: Johannes Berg <redacted>

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.
That said, I did find a few places where we could benefit from a larger
type here - e.g. having a NLA_U16 that must be non-zero cannot be
represented in the policy as is, since you can't set max to 65535.

However, I don't think we want to push the policy struct to 12 bytes on
32-bit platforms? It's currently 16 bytes on 64-bit due to the pointer
(and alignment), but only 8 bytes on 32-bit.

Keeping the few places that needed this validation is unlikely to be a
larger win than the policy size increase due to the larger type.

johannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help