diff options
author | Johannes Berg <johannes.berg@intel.com> | 2018-09-26 11:15:33 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-09-28 19:24:39 +0200 |
commit | 9a659a35ba177cec30676e170fb6ed98157bcb0d (patch) | |
tree | 0a551784a6b946553793306790e75e1bb69d4f83 /lib/nlattr.c | |
parent | netlink: move extack setting into validate_nla() (diff) | |
download | linux-9a659a35ba177cec30676e170fb6ed98157bcb0d.tar.xz linux-9a659a35ba177cec30676e170fb6ed98157bcb0d.zip |
netlink: allow NLA_NESTED to specify nested policy to validate
Now that we have a validation_data pointer, and the len field in
the policy is unused for NLA_NESTED, we can allow using them both
to have nested validation. This can be nice in code, although we
still have to use nla_parse_nested() or similar which would also
take a policy; however, it also serves as documentation in the
policy without requiring a look at the code.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/nlattr.c')
-rw-r--r-- | lib/nlattr.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/nlattr.c b/lib/nlattr.c index 6e03d650bec4..04750f88477c 100644 --- a/lib/nlattr.c +++ b/lib/nlattr.c @@ -155,6 +155,20 @@ static int validate_nla(const struct nlattr *nla, int maxtype, */ if (attrlen == 0) break; + if (attrlen < NLA_HDRLEN) + goto out_err; + if (pt->validation_data) { + err = nla_validate(nla_data(nla), nla_len(nla), pt->len, + pt->validation_data, extack); + if (err < 0) { + /* + * return directly to preserve the inner + * error message/attribute pointer + */ + return err; + } + } + break; default: if (pt->len) minlen = pt->len; |