Patchwork netlink: allow empty nested attributes

login
register
mail settings
Submitter Patrick McHardy
Date Nov. 27, 2008, 12:57 p.m.
Message ID <492E992F.7040703@trash.net>
Download mbox | patch
Permalink /patch/11181/
State Accepted
Delegated to: David Miller
Headers show

Comments

Patrick McHardy - Nov. 27, 2008, 12:57 p.m.

David Miller - Nov. 28, 2008, 11:05 a.m.
From: Patrick McHardy <kaber@trash.net>
Date: Thu, 27 Nov 2008 13:57:19 +0100

> commit 57b0afc97f8249f0b4f665aa285ed89a9178ba42
> Author: Patrick McHardy <kaber@trash.net>
> Date:   Thu Nov 27 13:40:31 2008 +0100
> 
>     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>

Applied, thanks Patrick.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

commit 57b0afc97f8249f0b4f665aa285ed89a9178ba42
Author: Patrick McHardy <kaber@trash.net>
Date:   Thu Nov 27 13:40:31 2008 +0100

    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>

diff --git a/net/netlink/attr.c b/net/netlink/attr.c
index c83fea7..56c3ce7 100644
--- a/net/netlink/attr.c
+++ b/net/netlink/attr.c
@@ -83,6 +83,12 @@  static int validate_nla(struct nlattr *nla, int maxtype,
 		if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN + nla_len(nla))
 			return -ERANGE;
 		break;
+	case NLA_NESTED:
+		/* a nested attributes is allowed to be empty; if its not,
+		 * it must have a size of at least NLA_HDRLEN.
+		 */
+		if (attrlen == 0)
+			break;
 	default:
 		if (pt->len)
 			minlen = pt->len;