From patchwork Mon Apr 8 15:45:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Riesch X-Patchwork-Id: 234819 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.180.67]) by ozlabs.org (Postfix) with ESMTP id 163942C0110 for ; Tue, 9 Apr 2013 01:53:33 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936625Ab3DHPxN (ORCPT ); Mon, 8 Apr 2013 11:53:13 -0400 Received: from ns.omicron.at ([212.183.10.25]:43175 "EHLO ns.omicron.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936519Ab3DHPxM (ORCPT ); Mon, 8 Apr 2013 11:53:12 -0400 X-Greylist: delayed 396 seconds by postgrey-1.27 at vger.kernel.org; Mon, 08 Apr 2013 11:53:11 EDT Received: from counter.omicron.at ([212.183.10.29]) by ns.omicron.at (8.13.1/8.13.1) with ESMTP id r38FkAVk000544; Mon, 8 Apr 2013 17:46:15 +0200 Received: from mary.at.omicron.at (mary.at.omicron.at [172.22.100.48]) by counter.omicron.at (8.14.4/8.14.4) with ESMTP id r38FkASd027328; Mon, 8 Apr 2013 17:46:10 +0200 Received: from MicRie11.omicron.at (172.22.2.144) by mary-special.at.omicron.at (172.22.100.48) with Microsoft SMTP Server id 8.3.297.1; Mon, 8 Apr 2013 17:46:09 +0200 From: Michael Riesch To: CC: Michael Riesch , "David S. Miller" , Greg Kroah-Hartman , Jiri Benc , "Theodore Ts'o" , Subject: [PATCH] rtnetlink: Call nlmsg_parse() with correct header length Date: Mon, 8 Apr 2013 17:45:26 +0200 X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Message-ID: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Michael Riesch Cc: "David S. Miller" Cc: Greg Kroah-Hartman Cc: Jiri Benc Cc: "Theodore Ts'o" Cc: linux-kernel@vger.kernel.org Acked-by: Mark Rustad --- Habidere, I encountered a netlink kernel warning when running avahi 0.6.31 on my system with kernel v3.4.35 (it appears several times): netlink: 12 bytes leftover after parsing attributes. Searching the web showed that commit "115c9b81928360d769a76c632bae62d15206a94a rtnetlink: Fix problem with buffer allocation" introduced this behaviour[1]. Now I - knowing nothing about netlink whatsoever - assume that the nlmsg_parse function is called with the wrong header length. In user space the request message consists out of the message header (struct nlmsghdr, 16 bytes) and an ifinfomsg (struct ifinfomsg, 16 bytes). After that, request attributes could follow. nlmsg_parse checks for this attributes after a given header length. In rtnl_get_link() this header length is sizeof(struct ifinfomsg), but in rtnl_calcit() as well as in rntl_dump_ifinfo() the header length is sizeof(struct rtgenmsg), which is 1 byte. With this patch I got rid of these warnings. However, I do not know whether this is the correct solution, so I am looking forward to your comments. Regards, Michael [1] http://lists.infradead.org/pipermail/libnl/2012-April/000515.html net/core/rtnetlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 900fc61..ebf6ace 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1065,7 +1065,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) rcu_read_lock(); cb->seq = net->dev_base_seq; - if (nlmsg_parse(cb->nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX, + if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX, ifla_policy) >= 0) { if (tb[IFLA_EXT_MASK]) @@ -1909,7 +1909,7 @@ static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh) u32 ext_filter_mask = 0; u16 min_ifinfo_dump_size = 0; - if (nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX, + if (nlmsg_parse(nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX, ifla_policy) >= 0) { if (tb[IFLA_EXT_MASK]) ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);