Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2269044imc; Tue, 12 Mar 2019 10:15:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHpBdlgKTIPXDBSCtMru/ELFLbTG/vGisiltBaZERaFSBhmD2QbNdbNzXq/XkQX/seU3a9 X-Received: by 2002:a63:fb16:: with SMTP id o22mr35211973pgh.209.1552410955254; Tue, 12 Mar 2019 10:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552410955; cv=none; d=google.com; s=arc-20160816; b=vuCQGKszaIJtStjEGwcvjodYZTWl63SujSIOscfHntKAh0olqkHHn7EVrNxTBloFKT jo+vCc9fdiOeStc47DXjRglH9RcFsT4t9Ydp80Fr637d3329wmx4wTq3h9N1OZYFzON1 FLC7gemXARZboP2BOZCFLrSMiKgdXK9Bku0OoeO9wn/EiuAFLDWqKdjErkRyYzQm+Mcz pgLXPVB+KeTiNMy7dGloD8X6QYFAXhD5jUtl+BC6pU+3uO5Gz4P4Ev9TbTo9cemLLal+ CfTfoFDmGY0tCsKVKKEt/G/H7hTyoGicstBqlXRFWxIVeaTH4rtrhv80hdCExIHmBnCS E4qQ== 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=4tFCVxmUFuC663YrXME6BpgSR9cqy2lpGTBsjDUUbSs=; b=gofccBMQgw7Yx17Ihj9P7X4PsdxQ/x/o6a2ACvX/HmNNC75BRrF0NZnozqlmceCe9v LXIVWUBx7mO0Go6BkgObX9kFfsv6GHn692V2MBzsxEywfSZptIhuKMOQU6h7QM+T/7ll nn3PcHcwP8/D8NWXE0VoF7609WtOKP4hjS9HreCkbiYXWcGDKKbNiZ6NqFC1iYbC8b5Y MFjHV1k3WMMJDVbNUloxKGkBkp6ePO12MO2cAffxaaSEVbAaxxixizMA/yxCIVJ4BXgQ XvevuX6KODeWeEJy0ZAXr1KRlmr9Av35n+fx/PreLLJtdJ2RZC/V9dYMtBGuRFwJ3qx4 4heQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jyLZ1QVi; 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 c15si8491633pls.144.2019.03.12.10.15.39; Tue, 12 Mar 2019 10:15:55 -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=jyLZ1QVi; 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 S1728375AbfCLRO3 (ORCPT + 99 others); Tue, 12 Mar 2019 13:14:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:51190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbfCLRNp (ORCPT ); Tue, 12 Mar 2019 13:13:45 -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 7173D217F5; Tue, 12 Mar 2019 17:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410824; bh=MEboQdbhKz0F5dibhx8+nxR6PNG+5HMK0oHOfTNNKEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jyLZ1QViux8SNZsKrlnoJcVjc3sJExZ0FyY0z9foQ3IOJ4tjQWyYNRnPLw27ht8Xp 4xYS0KXC6KXMKltTbOyo3WppJggQXf/zoIdVWGImtrD5zVXIXeM8D79xsyf+N31M1/ MgW+iK8C/xKwJxkW6wbN437ByVPlTsHfVBQ+YEBw= 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.19 001/149] media: uvcvideo: Fix type check leading to overflow Date: Tue, 12 Mar 2019 10:06:59 -0700 Message-Id: <20190312170349.553837037@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170349.421581206@linuxfoundation.org> References: <20190312170349.421581206@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.19-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 @@ -1065,11 +1065,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,