Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp213937yba; Fri, 12 Apr 2019 02:00:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxETPANEFG93KdNSzD807aPCrH3lX0wSeOnJKenmnalH7zwquP6OooK+IQ1jrwk+52ya/wG X-Received: by 2002:a63:3185:: with SMTP id x127mr6091693pgx.299.1555059654412; Fri, 12 Apr 2019 02:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555059654; cv=none; d=google.com; s=arc-20160816; b=E7V3yloEZyHAZwWKpvSA0qkZtlwEE2/4vQL4I/A43Cpi+5pmOCaz7dNHNK1BcSnWvW ty5hr12Z4/3UQD/lDE3ZKt6MPHPy2Rl0sTLfNZg2vc3kIFhfcTJDW5javKwQy/GS1P4s I4Zvkd3XnOOvUWpFos+a4cUPDk5VsXpS/bKKw0gpLJ8P/0jXC6Y5xkmQEO4eJGibL2B4 Qmm8j9LiP5rcZlhUUlKNnBHPwBecPr6NCa5QCCPVWlQFQHRJAZpyfOm5D0IhTj4f1+gi qvvmcF9dSDwcPnw0Lu3meCneLSn3ErAnjAOGJUTSyFM99edeq+KKzjLpOePSmuDrt+0w p8hQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=bSAd7U8tlK1c5XINJDLZed1vj3w8V08daB+Zbu7d/CE=; b=cWEnYDY4swUD/L6j4U6WHT/el6IPTsQQ3Dyup6bA9LTqVIfwZZczQMcbMuqUMXxFeC hY6oZoGtfAqKs87gmXAy7EGjdrxk28v20SzX/r/BNc7HOU8pjad4U9LgFlawwQ7SRgIV oTuqzCEEKUX09bKrFtTkfHmGprciSDpZPPXx6ATri3NQtHxYWBUTmv21J5x6WH7TBnfX tkUtNPHwGLi2Zsr44cT505fKIE3f3qW5S6sDGngfg//1A5V7lVOjohvxzwGjhjZtet8g 0x8XcHUknGz3VAG//72wtKyOpURtZ3AQjxgne0uYX742ETmz7PGCDsmTwyuwW0vnaRtw JlRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hRMMerL3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21si33765936pgk.283.2019.04.12.02.00.38; Fri, 12 Apr 2019 02:00:54 -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=@gmail.com header.s=20161025 header.b=hRMMerL3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727507AbfDLJAF (ORCPT + 99 others); Fri, 12 Apr 2019 05:00:05 -0400 Received: from mail-vk1-f193.google.com ([209.85.221.193]:45302 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbfDLJAF (ORCPT ); Fri, 12 Apr 2019 05:00:05 -0400 Received: by mail-vk1-f193.google.com with SMTP id h127so1986544vkd.12; Fri, 12 Apr 2019 02:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bSAd7U8tlK1c5XINJDLZed1vj3w8V08daB+Zbu7d/CE=; b=hRMMerL3cgx7Ik30Jv+mtFY8mnbaj/qQ6BQYR4Rz6NVfla/IE7YjlS+VI4JIB2d03Y uvhO99xJENymVFtEtb1nXdKThIrHcqhdJZo8OyZ4UhODosX8kr4ojLu5s5KjDPaiAYL7 cgDHI9ylN8z8wkM1WDASl6Eh8yMVzU2FD04AXY9xbn+UmigxMXeA1rNualvnmKGLgHE3 FwN9SvxBdUhBgXsFFI6yPqtD+W5wAdQA3qwCF4JIM74N6abYOnuJ6Tn8Psa9yEZ5914J dXU6KNER24hWV7NICP0AIdW1RyY2+RFcXAW9U4JcT5PeZX5UiUdd1QHqgEZ1vcEJFS0u cAsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=bSAd7U8tlK1c5XINJDLZed1vj3w8V08daB+Zbu7d/CE=; b=tyNpzg+9QYF9cmD11EVsTujHL0UYLZ0cZT7+SDkDkTZyNIHglB6ZRTftwEOGHozOcf z021V1Pvg26lzX1Xo1J/FSDyWVCVXrT0y8lEV8XIbjj9pswmD0dr/JdK4PBQPtOAmWOk aXdirQR8LPYsshASlTxtJdWVEL8rklK4GFh2y6hqsGCSLt3luwb9sqeuJzyoTDDKNuAb Sk9yO6z5sF6qZtRdAtpstzfpvN/BYJbpVr2mFSyyCOLhyy4pKgPCORXNR9sJ6aYp8qAB CnvRswcNes17X0CWe/P77Wwyd77CZRbRFusfLPpuYDd9LCht4ziLJ0lxNeU0GlNkkXcV oN1Q== X-Gm-Message-State: APjAAAVmM4K2KVDDXC7WFqAbL3gMXi8QwhM41rfCYWgQOCIQTV1xL9Uq XXtjzOGZ98Hu4XcN0kHS9wdpiFN7Y/JGiEf1RhUu7bNykHljqg== X-Received: by 2002:a1f:850c:: with SMTP id h12mr31268267vkd.70.1555059601428; Fri, 12 Apr 2019 02:00:01 -0700 (PDT) MIME-Version: 1.0 References: <1555036767-31170-1-git-send-email-92siuyang@gmail.com> <878swf645i.fsf@miraculix.mork.no> In-Reply-To: <878swf645i.fsf@miraculix.mork.no> From: Yang Xiao <92siuyang@gmail.com> Date: Fri, 12 Apr 2019 16:58:43 +0800 Message-ID: Subject: Re: [PATCH] USB: s2255 & stkwebcam: fix oops with malicious USB descriptors To: linux-usb@vger.kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Thanks for your response, firstly. The affected version ranges from v3.7 to v5.1. ------------------------------------------------------------- Below is the analysis of the vulnerability: As said in the comment, the driver expects at least one valid endpoint. If given malicious descritors that spcify 0 for the number of endpoints, then there is a null pointer deference when calling function usb_endpoint_is_bulk_in. for (i =3D 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint =3D &iface_desc->endpoint[i].desc; if (!dev->read_endpoint && usb_endpoint_is_bulk_in(endpoint= )) { /* we found the bulk in endpoint */ dev->read_endpoint =3D endpoint->bEndpointAddress; } } static inline int usb_endpoint_is_bulk_in( const struct usb_endpoint_descriptor *epd) { return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd); } static inline int usb_endpoint_xfer_bulk( const struct usb_endpoint_descriptor *epd) { return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) =3D=3D USB_ENDPOINT_XFER_BULK); } There is a call to function usb_endpoint_is_bulk_in after assignment to endpoint. And the field bmAttributes is accessed in function usb_endpoint_xfer_bulk (usb_endpoint_is_bulk_in -> usb_endpoint_xfer_bulk). Since the number of descriptors is 0, endpoint is assignment to NULL. Then NULL pointer deference in function usb_endpoint_xfer_bulk (oops). If you insist on a PoC, sorry for that. I found the vulnerability by analyzing the code staticlly. Below is the reply of your rant: Everyone wants to build a secury Linux kernel with different ways. Fuzzing, static analysis are all good ways. And there are many missing fixes when a vulnerability is found indeed, since there are much code clone in codebase. I agree with you on your explain about alllocating CVE numbers to arbitrary driver bugs. Complaint is useless. As main developer of kernel, I think you can disscuss the problem with other main developers. There should be a baseline. Which vulnerabilities should be assigned with a CVE number, and which should not. However, if there are real bugs or vulnerabilities, we still need to fix them, don't we? Besides, I am sorry for not explaining the patch clearly when I submitted the patch. I will try to analyse the possible vulnerability when submitting patches next time. Young On Fri, Apr 12, 2019 at 4:04 PM Bj=C3=B8rn Mork wrote: > > Please mark updated patches with a version number or some other > indication that it replaces a previous patch. Including a summary of > changes is also normal. > > And speaking of normal: We do build test our patches, don't we? > > > Young Xiao <92siuyang@gmail.com> writes: > > > From: Young Xiao > > > > The driver expects at least one valid endpoint. If given > > malicious descriptors that specify 0 for the number of endpoints, > > it will crash in the probe function. > > No, it won't. Did you test this? Can you provide the oops? > > This is perfectly fine as it is: > > dev =3D kzalloc(sizeof(struct s2255_dev), GFP_KERNEL); > .. > for (i =3D 0; i < iface_desc->desc.bNumEndpoints; ++i) { > endpoint =3D &iface_desc->endpoint[i].desc; > if (!dev->read_endpoint && usb_endpoint_is_bulk_in(endpoi= nt)) { > /* we found the bulk in endpoint */ > dev->read_endpoint =3D endpoint->bEndpointAddress= ; > } > } > > if (!dev->read_endpoint) { > dev_err(&interface->dev, "Could not find bulk-in endpoint= \n"); > goto errorEP; > } > > > drivers/media/usb/stkwebcam/stk-webcam.c | 6 ++++++ > > I didn't bother looking at this driver to see if your patch there makes > more sense. That is your home work now. Please explain why you believe > it is. An actual oops would be good. > > > Yes, and I do have some objections to this whole "protect against > malicious devices". How do you intend to protect against a USB device > disguising itself as a keyboard or ethernet adapater or whatever? > Allowing potentionally malicious devices is crazy enough for USB, and it > gets completely wacko when people start talking about it in the context > of firewire or PCIe > > Fixing bugs in drivers is fine. But it won't make any difference wrt > security if you connect malicious devices to your system. Don't do that > if you want a secure system. > > Allocating CVE numbers to arbitrary driver bugs is just adding > noise. This noise makes it harder for sysadmins and others to to notice > the really important problems. No one will care anymore if every kernel > release fixes thousands of CVEs. Which is pretty close to the truth if > you start allocating CVE numbers to any bug with a security impact. > > > > > > Bj=C3=B8rn --=20 Best regards! Young -----------------------------------------------------------