Commit d30045a0 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller

[NETLINK]: introduce NLA_BINARY type

This patch introduces a new NLA_BINARY attribute policy type with the
verification of simply checking the maximum length of the payload.

It also fixes a small typo in the example.
Signed-off-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 70331571
...@@ -171,6 +171,7 @@ enum { ...@@ -171,6 +171,7 @@ enum {
NLA_MSECS, NLA_MSECS,
NLA_NESTED, NLA_NESTED,
NLA_NUL_STRING, NLA_NUL_STRING,
NLA_BINARY,
__NLA_TYPE_MAX, __NLA_TYPE_MAX,
}; };
...@@ -188,12 +189,13 @@ enum { ...@@ -188,12 +189,13 @@ enum {
* NLA_STRING Maximum length of string * NLA_STRING Maximum length of string
* NLA_NUL_STRING Maximum length of string (excluding NUL) * NLA_NUL_STRING Maximum length of string (excluding NUL)
* NLA_FLAG Unused * NLA_FLAG Unused
* NLA_BINARY Maximum length of attribute payload
* All other Exact length of attribute payload * All other Exact length of attribute payload
* *
* Example: * Example:
* static struct nla_policy my_policy[ATTR_MAX+1] __read_mostly = { * static struct nla_policy my_policy[ATTR_MAX+1] __read_mostly = {
* [ATTR_FOO] = { .type = NLA_U16 }, * [ATTR_FOO] = { .type = NLA_U16 },
* [ATTR_BAR] = { .type = NLA_STRING, len = BARSIZ }, * [ATTR_BAR] = { .type = NLA_STRING, .len = BARSIZ },
* [ATTR_BAZ] = { .len = sizeof(struct mystruct) }, * [ATTR_BAZ] = { .len = sizeof(struct mystruct) },
* }; * };
*/ */
......
...@@ -67,6 +67,11 @@ static int validate_nla(struct nlattr *nla, int maxtype, ...@@ -67,6 +67,11 @@ static int validate_nla(struct nlattr *nla, int maxtype,
} }
break; break;
case NLA_BINARY:
if (pt->len && attrlen > pt->len)
return -ERANGE;
break;
default: default:
if (pt->len) if (pt->len)
minlen = pt->len; minlen = pt->len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment