Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5303156imu; Wed, 19 Dec 2018 08:51:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/UJ4IyE4WEG5yZAJQOuJYvG9ZEL/gB/NQVBP1J/Z4Dn5eZSDqRJYGYZ3cK1rxIRtVyI84qk X-Received: by 2002:a17:902:8641:: with SMTP id y1mr20885777plt.159.1545238279699; Wed, 19 Dec 2018 08:51:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545238279; cv=none; d=google.com; s=arc-20160816; b=0hS99twUQlgjXRdAxfsAAPTDKx8nropEelVfk3d9ngVuDhipjsOsOkhnJj5Jdbgso/ nDL/6SARrtUWUonQ7zcyPr9Ydq1gtQbLo0NwY7RYq/uJuu2fDX56EqntXvHX96QlYoZl Yy6SzhDaK90vf2sW/3K5PnKsWwsU5PZgVrHVRd9nQ+gTSuD9IGb+8U26Wz+jLn5J87sb rZNFXkLcelzVUWMMM8C2gJRg7g4ewNcPo2/P8Dvlp+pmIjTfOFmvIJlrP9aLmq3mGPHs A56hk2pVCvag1AgZ3yAvEQItSO046nyk7SaFQ3yS0ZqUmzg8n7KBe+atpkcNPzgBkmup gEdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=URlhHRdYm31zg5n1/ufG2xxVGWBH9VnczapWYR/uG/A=; b=RP0S+vM3fqjbbVnCXKM/b7jlwk2yMGxHmqRHfHd9iUbJkQnl/eu027WVku37g2J8up cd1UQjwEri1tSoKD3777XwuHp5AwLFDVD2/owVh3YeJE4ksfIFhwY+1dRDeeTdHjoc8C wQmMhLWmVl3vf5IEktgrmCHrzKoRSJmmEiG5KN4nMxvmfaOElMisHvM0CaMCR4bwoVBv GWnPzqxyS2z8XU466OQSmjL3hnYPuuHni9bBM1ZeTteubdsvFDb1YtJLePugxhlPy+EJ OIpb59KEuu4c9z//deTjVpJYkcieAKaGUiuO4FRBHwH4GU3DhK8iO19K2hV1VmAFYz0n TgSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kO1VMmZO; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si15861570pgk.341.2018.12.19.08.51.03; Wed, 19 Dec 2018 08:51:19 -0800 (PST) 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=@google.com header.s=20161025 header.b=kO1VMmZO; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729936AbeLSPNQ (ORCPT + 99 others); Wed, 19 Dec 2018 10:13:16 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:34725 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728281AbeLSPNP (ORCPT ); Wed, 19 Dec 2018 10:13:15 -0500 Received: by mail-io1-f67.google.com with SMTP id l22so505215ioh.1 for ; Wed, 19 Dec 2018 07:13:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=URlhHRdYm31zg5n1/ufG2xxVGWBH9VnczapWYR/uG/A=; b=kO1VMmZOTK9Pn6gMHGmDPcaUkq0XklAZIvXoe5SRlZN20GabTxruaW/B4SweWgydbS iF1FmAcX8xpavc+/VA3I0bs7Q8K2+MgDvpCO/SLBeUWnlRbBnt4Jr4IxVi6GINVgImbq CMCQ6RR8DVS8Bp9UuRgHcZpdSOJwePih03TxtjJRaIiGPeWb0jrzgSr+iXNwybFu1kK4 yIsNcTGMr3+hZCeddjEWihiKPhITQ1jsO3tnYPePlSnJSbQ91LqisN4VAmLd+cmIBp1h cUzRoweNQH3HNYsubT6G3Qwk3tPQP2btsw/9jUQQ+P7ud2b8VzYhfIU7afm1bSDhLqTl cssQ== 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; bh=URlhHRdYm31zg5n1/ufG2xxVGWBH9VnczapWYR/uG/A=; b=rwg5a4BwrbJOt7BVZWnMO4SJGYQtmtQvT2iHTNpxzbJGDU/Fyf+bXbWAFCRQ5s9bgT +ueJTO4IlpSm/nVg+PFLBb9HiF0UcedMCfXl43ActbymHvrsrAZi+3kiui/mQ6f0NQrB giymhhHlrxRib3LhvclIkTB+gdYLADdJYb0AarUISz/UO3J9l4nqxYlc5CEKydSvc7YN Nw/Dz1m0l62JYC7kNGDo3CHLqscj5JgVLSnWWuoz9ibZWQhZl1v8Id/nesR5/hCTU5Se vCmiRy2ZQBUESjmZWicHjqu0QOzN6KFQ65stgCNIbrFYXfWtkLMSzbbTGlnz5spmgMbX 0VuQ== X-Gm-Message-State: AJcUukcNhYSQd637boOLrsd0Wi4EOAb1J4EuXPmLQc95twOzoGfj44x/ j3ASzyn9xn19DeZZHKiLT9pcVAZZUtA/HQI7CbUqKA== X-Received: by 2002:a6b:e607:: with SMTP id g7mr1586979ioh.292.1545232393364; Wed, 19 Dec 2018 07:13:13 -0800 (PST) MIME-Version: 1.0 References: <20181219013248.94850-1-astrachan@google.com> <7327024.PA5BtzYvEC@avalon> In-Reply-To: <7327024.PA5BtzYvEC@avalon> From: Alistair Strachan Date: Wed, 19 Dec 2018 07:13:01 -0800 Message-ID: Subject: Re: [PATCH v2] media: uvcvideo: Fix 'type' check leading to overflow To: laurent.pinchart@ideasonboard.com Cc: linux-kernel@vger.kernel.org, syzkaller@googlegroups.com, mchehab@kernel.org, linux-media@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 19, 2018 at 12:16 AM Laurent Pinchart wrote: > > Hi Alistair, > > Thank you for the patch. > > On Wednesday, 19 December 2018 03:32:48 EET Alistair Strachan wrote: > > From: Laurent Pinchart > > Are you sure you don't want to keep authorship ? I've merely reviewed v1 and > proposed an alternative implementation :-) Let me know what you would prefer > and I'll apply this to my tree. Whatever attribution you think is best works for me! Thank you for picking up this patch. > > When initially testing the Camera Terminal Descriptor wTerminalType > > field (buffer[4]), no mask is used. Later in the function, the MSB is > > overloaded to store the descriptor subtype, and so a mask of 0x7fff > > is used to check the type. > > > > If a descriptor is specially crafted to set this overloaded bit in the > > original wTerminalType field, the initial type check will fail (falling > > through, without adjusting the buffer size), but the later type checks > > will pass, assuming the buffer has been made suitably large, causing an > > overflow. > > > > Avoid this problem by checking for the MSB in the wTerminalType field. > > If the bit is set, assume the descriptor is bad, and abort parsing it. > > > > Originally reported here: > > https://groups.google.com/forum/#!topic/syzkaller/Ot1fOE6v1d8 > > A similar (non-compiling) patch was provided at that time. > > > > Reported-by: syzbot > > Signed-off-by: Alistair Strachan > > Cc: Laurent Pinchart > > Cc: Mauro Carvalho Chehab > > Cc: linux-media@vger.kernel.org > > Cc: kernel-team@android.com > > --- > > v2: Use an alternative fix suggested by Laurent > > drivers/media/usb/uvc/uvc_driver.c | 14 +++++++++++--- > > 1 file changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/media/usb/uvc/uvc_driver.c > > b/drivers/media/usb/uvc/uvc_driver.c index bc369a0934a3..7fde3ce642c4 > > 100644 > > --- a/drivers/media/usb/uvc/uvc_driver.c > > +++ b/drivers/media/usb/uvc/uvc_driver.c > > @@ -1065,11 +1065,19 @@ static int uvc_parse_standard_control(struct > > uvc_device *dev, return -EINVAL; > > } > > > > - /* Make sure the terminal type MSB is not null, otherwise it > > - * could be confused with a unit. > > + /* > > + * Reject invalid terminal types that would cause issues: > > + * > > + * - The high byte must be non-zero, otherwise it would be > > + * confused with a unit. > > + * > > + * - Bit 15 must be 0, as we use it internally as a terminal > > + * direction flag. > > + * > > + * Other unknown types are accepted. > > */ > > type = get_unaligned_le16(&buffer[4]); > > - if ((type & 0xff00) == 0) { > > + if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) { > > uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " > > "interface %d INPUT_TERMINAL %d has invalid " > > "type 0x%04x, skipping\n", udev->devnum, > > -- > Regards, > > Laurent Pinchart > > >