Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754584AbbDOHIi (ORCPT ); Wed, 15 Apr 2015 03:08:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56629 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751301AbbDOHI3 (ORCPT ); Wed, 15 Apr 2015 03:08:29 -0400 Date: Wed, 15 Apr 2015 13:16:40 +0800 From: Honggang LI To: Erez Shitrit Cc: Roland Dreier , sean.hefty@intel.com, hal.rosenstock@gmail.com, kaber@trash.net, davem@davemloft.net, Alex Estrin , Doug Ledford , edumazet@google.com, Erez Shitrit , nicolas.dichtel@6wind.com, maheshb@google.com, jbenc@redhat.com, ebiederm@xmission.com, elfring@users.sourceforge.net, f.fainelli@gmail.com, linux@roeck-us.net, andrew@lunn.ch, sfeldma@gmail.com, alexander.h.duyck@intel.com, "linux-rdma@vger.kernel.org" , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH linux-next 1/4] infiniband/ipoib: fix possible NULL pointer dereference in ipoib_get_iflink Message-ID: <20150415051640.GB4881@honli.nay.redhat.com> References: <1429024817-21561-1-git-send-email-honli@redhat.com> <1429024817-21561-2-git-send-email-honli@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2209 Lines: 61 On Tue, Apr 14, 2015 at 07:30:03PM +0300, Erez Shitrit wrote: > > @@ -846,7 +846,10 @@ static int ipoib_get_iflink(const struct net_device *dev) > > { > > struct ipoib_dev_priv *priv = netdev_priv(dev); > > > > - return priv->parent->ifindex; > > + if (priv && priv->parent) > > + return priv->parent->ifindex; > > + else > > + return 0; > This will make parent interface to return 0 instead of its own ifindex. > I would suggest write something like that: > > + /* parent interface */ > + if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) > + return dev->ifindex; > + Hi, Erez Sorry for delay of reply. It was about 01:00 in the morning, so I went into bed. And thank you for the suggestion. You are right. After insert some printk statements in the driver, I confirmed it. ---------------------- console log -------------------- ipoib_get_iflink: priv = ffff880275e487c0, priv->parent = (null), priv->flags = 0x20f, dev = ffff880275e48000, dev->name = qib_ib1 qib_ib1, test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags) = 0 qib_ib1, idev->ifindex = 14 ipoib_get_iflink: priv = ffff8802765d27c0, priv->parent = (null), priv->flags = 0x20f, dev = ffff8802765d2000, dev->name = qib_ib2 qib_ib2, test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags) = 0 qib_ib2, idev->ifindex = 15 ipoib_get_iflink: priv = ffff8804741a47c0, priv->parent = ffff880275e48000, priv->flags = 0x224, dev = ffff8804741a4000, dev->name = qib_ib1.8003 qib_ib1.8003, test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags) = 1 qib_ib1.8003, idev->ifindex = 16 ---------------------- console log -------------------- I will rewrite the patch. > + /* child/vlan interface */ > + if (!priv->parent) > + return -1; > + > return priv->parent->ifindex; > > Thanks, > Erez. > > > } > > > > static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr) > > -- > > 1.8.3.1 > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/