From patchwork Thu Nov 27 12:57:19 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick McHardy X-Patchwork-Id: 11181 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id E69BADDDE7 for ; Thu, 27 Nov 2008 23:57:27 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752339AbYK0M5X (ORCPT ); Thu, 27 Nov 2008 07:57:23 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751460AbYK0M5X (ORCPT ); Thu, 27 Nov 2008 07:57:23 -0500 Received: from stinky.trash.net ([213.144.137.162]:49456 "EHLO stinky.trash.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751125AbYK0M5W (ORCPT ); Thu, 27 Nov 2008 07:57:22 -0500 Received: from [192.168.0.100] (unknown [78.42.204.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by stinky.trash.net (Postfix) with ESMTP id 39995948A5; Thu, 27 Nov 2008 13:57:20 +0100 (MET) Message-ID: <492E992F.7040703@trash.net> Date: Thu, 27 Nov 2008 13:57:19 +0100 From: Patrick McHardy User-Agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018) MIME-Version: 1.0 To: "David S. Miller" CC: Thomas Graf , Johannes Berg , Linux Netdev List Subject: netlink: allow empty nested attributes Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org commit 57b0afc97f8249f0b4f665aa285ed89a9178ba42 Author: Patrick McHardy 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 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;