From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933375AbXG2SWj (ORCPT ); Sun, 29 Jul 2007 14:22:39 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1762983AbXG2SWa (ORCPT ); Sun, 29 Jul 2007 14:22:30 -0400 Received: from pentafluge.infradead.org ([213.146.154.40]:55223 "EHLO pentafluge.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762254AbXG2SW3 (ORCPT ); Sun, 29 Jul 2007 14:22:29 -0400 Date: Mon, 30 Jul 2007 00:04:46 +0530 (IST) From: Satyam Sharma X-X-Sender: satyam@enigma.security.iitk.ac.in To: Domen Puncer cc: Jesper Juhl , Linux Kernel Mailing List , netdev@vger.kernel.org, Steven Hirsch , "David S. Miller" Subject: Re: [PATCH] sb1000: prevent a potential NULL pointer dereference in sb1000_dev_ioctl() In-Reply-To: Message-ID: References: <200707290002.42722.jesper.juhl@gmail.com> <20070729043707.GA8343@nd47.coderock.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org > On Sun, 29 Jul 2007, Domen Puncer wrote: > > > On 29/07/07 00:02 +0200, Jesper Juhl wrote: > > > Hi, > > > > > > Here's a small patch, prompted by a find by the Coverity checker, > > > that removes a potential NULL pointer dereference from > > > drivers/net/sb1000.c::sb1000_dev_ioctl(). > > > The checker spotted that we do a NULL test of 'dev', yet we > > > dereference the pointer prior to that check. > > > This patch simply moves the dereference after the NULL test. > > > > But... it can't be called without a valid 'dev', no? > > A quick 'grep do_ioctl net/' confirms that all calls are in > > the form of 'dev->do_ioctl(dev, ...'. > > Yup, I think so too ... > > > > > @@ -991,11 +991,13 @@ static int sb1000_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) > > > short PID[4]; > > > int ioaddr[2], status, frequency; > > > unsigned int stats[5]; > > > - struct sb1000_private *lp = netdev_priv(dev); > > > + struct sb1000_private *lp; > > > > > > if (!(dev && dev->flags & IFF_UP)) > > > return -ENODEV; > > I think we could get rid of the !dev check itself. Actually, the IFF_UP > check /also/ looks suspect to me for two reasons: (1) I remember Stephen > Hemminger once telling me dev->flags is legacy and unsafe, and one of > the netif_xxx() functions be used instead, and, (2) I wonder if we really > require the interface to be up and *running* when we do this ioctl. Updated patch below. [PATCH] sb1000: Remove bogus checks In net_device->do_ioctl() of the sb1000 driver (sb1000_dev_ioctl): (1) !dev condition is always false -- this function cannot be called with NULL net_device. (2) !(dev->flags & IFF_UP) is bogus because the functions of this ioctl can (and should) be allowed even when the interface is not up and running. So let's remove these checks. Signed-off-by: Satyam Sharma Cc: Jesper Juhl Cc: Domen Puncer --- drivers/net/sb1000.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/drivers/net/sb1000.c b/drivers/net/sb1000.c index 1de3eec..f60fe98 100644 --- a/drivers/net/sb1000.c +++ b/drivers/net/sb1000.c @@ -993,9 +993,6 @@ static int sb1000_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) unsigned int stats[5]; struct sb1000_private *lp = netdev_priv(dev); - if (!(dev && dev->flags & IFF_UP)) - return -ENODEV; - ioaddr[0] = dev->base_addr; /* mem_start holds the second I/O address */ ioaddr[1] = dev->mem_start;