Patchwork [net-next,1/2] caif_usb: Check driver name before reading driver state in netdev notifier

login
register
mail settings
Submitter Ben Hutchings
Date Dec. 7, 2012, 4:17 p.m.
Message ID <1354897046.2707.7.camel@bwh-desktop.uk.solarflarecom.com>
Download mbox | patch
Permalink /patch/204571/
State Accepted
Delegated to: David Miller
Headers show

Comments

Ben Hutchings - Dec. 7, 2012, 4:17 p.m.
In cfusbl_device_notify(), the usbnet and usbdev variables are
initialised before the driver name has been checked.  In case the
device's driver is not cdc_ncm, this may result in reading beyond the
end of the netdev private area.  Move the initialisation below the
driver name check.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
Compile-tested only.

Ben.

 net/caif/caif_usb.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
David Miller - Dec. 9, 2012, 5:34 a.m.
From: Ben Hutchings <bhutchings@solarflare.com>
Date: Fri, 7 Dec 2012 16:17:26 +0000

> In cfusbl_device_notify(), the usbnet and usbdev variables are
> initialised before the driver name has been checked.  In case the
> device's driver is not cdc_ncm, this may result in reading beyond the
> end of the netdev private area.  Move the initialisation below the
> driver name check.
> 
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>

Applied.
--
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

diff --git a/net/caif/caif_usb.c b/net/caif/caif_usb.c
index fd7cbf5..582f80c 100644
--- a/net/caif/caif_usb.c
+++ b/net/caif/caif_usb.c
@@ -126,8 +126,8 @@  static int cfusbl_device_notify(struct notifier_block *me, unsigned long what,
 	struct net_device *dev = arg;
 	struct caif_dev_common common;
 	struct cflayer *layer, *link_support;
-	struct usbnet	*usbnet = netdev_priv(dev);
-	struct usb_device	*usbdev = usbnet->udev;
+	struct usbnet *usbnet;
+	struct usb_device *usbdev;
 	struct ethtool_drvinfo drvinfo;
 
 	/*
@@ -141,6 +141,9 @@  static int cfusbl_device_notify(struct notifier_block *me, unsigned long what,
 	if (strncmp(drvinfo.driver, "cdc_ncm", 7) != 0)
 		return 0;
 
+	usbnet = netdev_priv(dev);
+	usbdev = usbnet->udev;
+
 	pr_debug("USB CDC NCM device VID:0x%4x PID:0x%4x\n",
 		le16_to_cpu(usbdev->descriptor.idVendor),
 		le16_to_cpu(usbdev->descriptor.idProduct));