Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netlink: allow empty nested attributes

validate_nla() currently doesn't allow empty nested attributes. This
makes userspace code unnecessarily complicated when starting and ending
the nested attribute is done by generic upper level code and the inner
attributes are dumped by a module.

Add a special case to accept empty nested attributes. When the nested
attribute is non empty, the same checks as before are performed.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Patrick McHardy and committed by
David S. Miller
ea5693cc ed77a89c

+6
+6
net/netlink/attr.c
··· 83 83 if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN + nla_len(nla)) 84 84 return -ERANGE; 85 85 break; 86 + case NLA_NESTED: 87 + /* a nested attributes is allowed to be empty; if its not, 88 + * it must have a size of at least NLA_HDRLEN. 89 + */ 90 + if (attrlen == 0) 91 + break; 86 92 default: 87 93 if (pt->len) 88 94 minlen = pt->len;