Path: csiph.com!aioe.org!bofh.it!news.nic.it!robomod From: Willy Tarreau Newsgroups: linux.kernel Subject: [PATCH 3.10 053/250] USB: serial: mos7840: fix NULL-deref at open Date: Thu, 08 Jun 2017 01:10:02 +0200 Message-ID: References: X-Original-To: linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux@roeck-us.net X-Mailer: git-send-email 2.8.0.rc2.1.gbe9624a Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 53 Organization: linux.* mail to news gateway X-Original-Cc: Johan Hovold , Willy Tarreau X-Original-Date: Thu, 8 Jun 2017 00:57:19 +0200 X-Original-Message-ID: <1496876436-32402-54-git-send-email-w@1wt.eu> X-Original-References: <1496876436-32402-1-git-send-email-w@1wt.eu> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1660312 From: Johan Hovold commit 5c75633ef751dd4cd8f443dc35152c1ae563162e upstream. Fix NULL-pointer dereference in open() should the device lack the expected endpoints: Unable to handle kernel NULL pointer dereference at virtual address 00000030 ... PC is at mos7840_open+0x88/0x8dc [mos7840] Note that we continue to treat the interrupt-in endpoint as optional for now. Fixes: 3f5429746d91 ("USB: Moschip 7840 USB-Serial Driver") Signed-off-by: Johan Hovold Signed-off-by: Willy Tarreau --- drivers/usb/serial/mos7840.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 7df7df6..5041b6c 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -2255,6 +2255,17 @@ static int mos7840_calc_num_ports(struct usb_serial *serial) return mos7840_num_ports; } +static int mos7840_attach(struct usb_serial *serial) +{ + if (serial->num_bulk_in < serial->num_ports || + serial->num_bulk_out < serial->num_ports) { + dev_err(&serial->interface->dev, "missing endpoints\n"); + return -ENODEV; + } + + return 0; +} + static int mos7840_port_probe(struct usb_serial_port *port) { struct usb_serial *serial = port->serial; @@ -2537,6 +2548,7 @@ static struct usb_serial_driver moschip7840_4port_device = { .tiocmset = mos7840_tiocmset, .tiocmiwait = usb_serial_generic_tiocmiwait, .get_icount = usb_serial_generic_get_icount, + .attach = mos7840_attach, .port_probe = mos7840_port_probe, .port_remove = mos7840_port_remove, .read_bulk_callback = mos7840_bulk_in_callback, -- 2.8.0.rc2.1.gbe9624a