Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2421359ybi; Sun, 9 Jun 2019 11:20:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwVJNVWzQJUXsCCTlgzoXnKMsnt8NnF6IUCSiqclBmATKhf0p7o562U6QWHwaArfcTljJWR X-Received: by 2002:a17:90a:a00d:: with SMTP id q13mr17089461pjp.80.1560104441234; Sun, 09 Jun 2019 11:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560104441; cv=none; d=google.com; s=arc-20160816; b=t5R+zDaVf8BidbHhVf6MiGvEnmWJa+XwrxmXDS5gA9pOd+IP+DjIw+h9iA1OCU5dtG Q65WYg0akqyjUNSm2XMnjeurYT1qD4B2ems1mSfd0/DXx7xugbVG3LIZiJHVh18Ktl3J FA5weSTpY9dMTUj9KDOxtJ1a/Ztheba3Z+W+kB+VjtFbvpGbClYp03jlJ2EEJOSY00Sc Hh0fbjXNGmsHjjEt9LCf7djwzjfHwN/fSmI5jXK/frSJnoaUs+uPmmebtFLOP/vuUW/G E1GvtcfGUQ+hAviPaOxfDwHcwm93KF9LnO9bwnEAvHOYDynuHE8wz29RHcJy3VdDBlNN 7dpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7dzEDr3rjDtAaYJRsp9+muzLrGPq0+pwCgsr710vZz0=; b=pQIwUZT89iFxI25+Z5wVtoIdHc7z9t5GTNY5UwmCzbZoEay3cJS4H2P6crmGzw+fDi RxI/a3ZwL75C1tuzOnbq6uezqZOwV1XH8m78fb8DB8b1gN0wQPylOK5geghPx2TO2LdF q0tLG92uhfTIcfvIw2IB5+OiILVQQblTQ+22iEjdl8gHBKUJEOqKSXLvgmDRRLRk/l1g sbwLNc16grBm9qZwxEEuARXLhGYf7JI7xOA7aDRNmXMPc8jyf9LqUjqDPo8EWGhk3Ixs d/38wpsWHil6VaTIegSGwTeKPfbnuJha6kqstwdyQapP0v8Jaq6MtyzLpA9iVVEM98Al Ed3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KTVZVvSz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j14si8013421pfi.276.2019.06.09.11.20.25; Sun, 09 Jun 2019 11:20:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KTVZVvSz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388671AbfFIREq (ORCPT + 99 others); Sun, 9 Jun 2019 13:04:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:43594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388270AbfFIREn (ORCPT ); Sun, 9 Jun 2019 13:04:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A1D120833; Sun, 9 Jun 2019 17:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099881; bh=xx4eZjBUdw6PcUvBiq0Uqq2vHSsIT6uxOLvPY8gm5yE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTVZVvSzhoePcCFHWPCGYRx1gHnw3lQ0S3MSVu6ubwlur0znaTa0LYGhLqIMtrtgw ne3PrC5cHHWBZkxBY3pouIFO//+wTvqmJMkn33nxtkv7iF1MgR53UxVS8UC8CumCC+ Jvp7oejQFyj9BeCPglI0ylgW+AT020XwytlO21cE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Johan Hovold , syzbot+53f029db71c19a47325a@syzkaller.appspotmail.com Subject: [PATCH 4.4 201/241] media: usb: siano: Fix general protection fault in smsusb Date: Sun, 9 Jun 2019 18:42:23 +0200 Message-Id: <20190609164153.946110228@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164147.729157653@linuxfoundation.org> References: <20190609164147.729157653@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern commit 31e0456de5be379b10fea0fa94a681057114a96e upstream. The syzkaller USB fuzzer found a general-protection-fault bug in the smsusb part of the Siano DVB driver. The fault occurs during probe because the driver assumes without checking that the device has both IN and OUT endpoints and the IN endpoint is ep1. By slightly rearranging the driver's initialization code, we can make the appropriate checks early on and thus avoid the problem. If the expected endpoints aren't present, the new code safely returns -ENODEV from the probe routine. Signed-off-by: Alan Stern Reported-and-tested-by: syzbot+53f029db71c19a47325a@syzkaller.appspotmail.com CC: Reviewed-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/siano/smsusb.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) --- a/drivers/media/usb/siano/smsusb.c +++ b/drivers/media/usb/siano/smsusb.c @@ -391,6 +391,7 @@ static int smsusb_init_device(struct usb struct smsusb_device_t *dev; void *mdev; int i, rc; + int in_maxp; /* create device object */ dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL); @@ -402,6 +403,24 @@ static int smsusb_init_device(struct usb dev->udev = interface_to_usbdev(intf); dev->state = SMSUSB_DISCONNECTED; + for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { + struct usb_endpoint_descriptor *desc = + &intf->cur_altsetting->endpoint[i].desc; + + if (desc->bEndpointAddress & USB_DIR_IN) { + dev->in_ep = desc->bEndpointAddress; + in_maxp = usb_endpoint_maxp(desc); + } else { + dev->out_ep = desc->bEndpointAddress; + } + } + + pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep); + if (!dev->in_ep || !dev->out_ep) { /* Missing endpoints? */ + smsusb_term_device(intf); + return -ENODEV; + } + params.device_type = sms_get_board(board_id)->type; switch (params.device_type) { @@ -416,24 +435,12 @@ static int smsusb_init_device(struct usb /* fall-thru */ default: dev->buffer_size = USB2_BUFFER_SIZE; - dev->response_alignment = - le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) - - sizeof(struct sms_msg_hdr); + dev->response_alignment = in_maxp - sizeof(struct sms_msg_hdr); params.flags |= SMS_DEVICE_FAMILY2; break; } - for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { - if (intf->cur_altsetting->endpoint[i].desc. bEndpointAddress & USB_DIR_IN) - dev->in_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress; - else - dev->out_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress; - } - - pr_debug("in_ep = %02x, out_ep = %02x\n", - dev->in_ep, dev->out_ep); - params.device = &dev->udev->dev; params.buffer_size = dev->buffer_size; params.num_buffers = MAX_BUFFERS;