netlink: set bad attribute also on maxtype check
authorMichal Kubecek <mkubecek@suse.cz>
Thu, 2 May 2019 14:15:10 +0000 (16:15 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 4 May 2019 05:27:10 +0000 (01:27 -0400)
The check that attribute type is within 0...maxtype range in
__nla_validate_parse() sets only error message but not bad_attr in extack.
Set also bad_attr to tell userspace which attribute failed validation.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Reviewed-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
lib/nlattr.c

index 29f6336e2422bb8e863162a8e4ebf657d52c0f32..adc919b32bf92d2fa54ed0943b39b168ee66fcd8 100644 (file)
@@ -356,7 +356,8 @@ static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype,
 
                if (type == 0 || type > maxtype) {
                        if (validate & NL_VALIDATE_MAXTYPE) {
-                               NL_SET_ERR_MSG(extack, "Unknown attribute type");
+                               NL_SET_ERR_MSG_ATTR(extack, nla,
+                                                   "Unknown attribute type");
                                return -EINVAL;
                        }
                        continue;