netlink: policy: correct validation type check
authorJohannes Berg <johannes.berg@intel.com>
Mon, 31 Aug 2020 18:28:05 +0000 (20:28 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 31 Aug 2020 19:01:15 +0000 (12:01 -0700)
In the policy export for binary attributes I erroneously used
a != NLA_VALIDATE_NONE comparison instead of checking for the
two possible values, which meant that if a validation function
pointer ended up aliasing the min/max as negatives, we'd hit
a warning in nla_get_range_unsigned().

Fix this to correctly check for only the two types that should
be handled here, i.e. range with or without warn-too-long.

Reported-by: syzbot+353df1490da781637624@syzkaller.appspotmail.com
Fixes: 8aa26c575fb3 ("netlink: make NLA_BINARY validation more flexible")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netlink/policy.c

index 7b1f505..5c9e753 100644 (file)
@@ -264,7 +264,8 @@ send_attribute:
                else
                        type = NL_ATTR_TYPE_BINARY;
 
-               if (pt->validation_type != NLA_VALIDATE_NONE) {
+               if (pt->validation_type == NLA_VALIDATE_RANGE ||
+                   pt->validation_type == NLA_VALIDATE_RANGE_WARN_TOO_LONG) {
                        struct netlink_range_validation range;
 
                        nla_get_range_unsigned(pt, &range);