Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2282093imc; Tue, 12 Mar 2019 10:31:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3z//6kr0slBbAZ+S2iYPUyFmKXzanIVRAAWoqR623SbofL6YXivpTtDVHkjhnHrsbFg7m X-Received: by 2002:a63:3d0e:: with SMTP id k14mr18571641pga.302.1552411884141; Tue, 12 Mar 2019 10:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552411884; cv=none; d=google.com; s=arc-20160816; b=AY2hRCvrIWHw+XmrBmkZP7OEx+JXIIECKiP3VPxXsEkfZoNcUD2xAkQe2KLkH2p19x LWNZHGZMeGNWu2tvZaPQM1Yk9h84ZbQQEn+s/r7OEHUJvCyZVXR5FYOyOCXflNq1TUSP QWQesBXPWn6byQKRV5NGQqop2R4KQbl8pLHpPaioGqMYEF1WU7AbB2T4cNXavVYP/aFG BatTsQG2/2izc7EZXdGf+ebtOdEG62R+ZdKFfISvcF6VtMV6GpI1o8PreqMciDoP5UH9 Nf/IMRgZcKpGxRZgvuzMOAVGxp9dXY4UUxbUXuz66qIDUL7U9Hme5+fS4mufiFGVuDrb 2GGA== 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=DCNNDf4v8DmAtXTrX/xjIgLXo6MCaRBjpZi01fS5FQQ=; b=kP7dcLrbJZyrOvDflSi6dlg+6pcVGIoZ5gvz11vQ8/PapKi187T+kBdqezBxDlwT0n avgAqxzt+9aCOccKV6adpGo5OXGPbySk6DdViGXDblxBk2XzJVJEgBXJjNxgN0NAdYKc 4cFgq5rR4NyinGTfWnkpVYAEJ7Ah34TUHHSJooqnRFJ+7Gkm5cfZ60LUDkailzQCrGHK VUZBRyIgobqXB22spUxxM3pwTJsQBqvk+fCkInKX43kTEZogFoyMxFiW1OKGVgTvVziZ n9eKr4PWYg/rW2b8/9+mPoXMsfXR/ldDEDIrlUV8ot5x+U2XpjiuKz5QG9aXaF4aJqqO 05eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hGVFNhxx; 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 g8si8100297pgd.52.2019.03.12.10.31.07; Tue, 12 Mar 2019 10:31:24 -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=hGVFNhxx; 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 S1728042AbfCLR2r (ORCPT + 99 others); Tue, 12 Mar 2019 13:28:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:33336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728705AbfCLRRa (ORCPT ); Tue, 12 Mar 2019 13:17:30 -0400 Received: from localhost (unknown [104.133.8.98]) (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 981102186A; Tue, 12 Mar 2019 17:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552411049; bh=76zfqqA456lbefSmPjMYjDNwfhSnb+6C9sI7raRGh7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hGVFNhxxWQ4c43GNzf2269F6C6vmn94QeVV7JrCy3q8ClDcebxJ5axlScWjQjTCX5 ujglTt5vuqDvqZvhMtn8v2GHCigVBWKq6Jkcu4k5RoRVDV+f8a+ezp4crAhytD+I1F imMG+UlsszLlUHCIvw6rWUHPaYWZfV32f1yMo/p8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Alistair Strachan , Laurent Pinchart , Mauro Carvalho Chehab Subject: [PATCH 4.9 33/96] media: uvcvideo: Fix type check leading to overflow Date: Tue, 12 Mar 2019 10:09:51 -0700 Message-Id: <20190312171037.011214050@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312171034.530434962@linuxfoundation.org> References: <20190312171034.530434962@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alistair Strachan commit 47bb117911b051bbc90764a8bff96543cbd2005f upstream. 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 Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_driver.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1019,11 +1019,19 @@ static int uvc_parse_standard_control(st 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,