Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2282363imc; Tue, 12 Mar 2019 10:31:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxU2smslscoEI/IIhx1IVrGaW6Wsu+IXUPbg/Se3tgn97LwcB3DF3bh8RYelIVNnlW1vHVw X-Received: by 2002:a65:510c:: with SMTP id f12mr36683096pgq.40.1552411904498; Tue, 12 Mar 2019 10:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552411904; cv=none; d=google.com; s=arc-20160816; b=iYxX1D1oPppMMxp3SWYTdTcVWCNMe6gY+vnLYlULgU+xGbnGaExR4lXS+wjC+Vlo11 sRDiZ/LphLdhn+jx4g/oCbVB4yK/ygwEP4Ghony99xGOnx71znvP8TOabN+XvO9TqTtU bIOBPzlo1PLXWmR9IL9AeYKUHeifzl+YH0e/fRC+yjaEMIGVyGzsb5e/cbwS+dtIEfUQ 7F0Lgnl5QS50nlZSrJ78mUocJGaY3V+zxxeUdfqKqVHfX97MKNDGmMbSsIexbP447uvK 6c6LRVBfk77kAG43goCxiuY3/4GY1EryEfiJQlwW3Tr94hwxipKdyVfU599lOH6QTWsj sxjQ== 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=dRtgsNM4e3GqYcx5ZII6rwByzd1ucnIa+kk1kNDi8bM=; b=zlqu8DMwKXQ+6NFIlnSHlUTKt7spdqBnwohy118FqN5CBGHF9mcOoa9TjwxzMOuNMI 2z0wOyDT43O9T8Jn9A/MPUSoKDaWJqB9UYSedHuOLdNzsh8x5NKwLPJDQ1r8JSHFeZ8u mNVKUsNtrR97mKVM9DPPPiRY3xmdUKTr5nX789oiGhv0nqWQITrLJx5fqF7Ton9ewsoB AhGU1fg/aqALztb7FgkWp9HhiMHCMoXOx0dR0fKs01ML0EPbg1Tft+tnj/qBOwkx7RhP ylz//lCYoN+SnaNsdS4/rVWsh2WbPzaKe9RGNvWNYkTqjoHoThBOP2dW4jxZI1kJBau0 FRAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=igCYS+rX; 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 a63si8872360pfb.267.2019.03.12.10.31.28; Tue, 12 Mar 2019 10:31:44 -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=igCYS+rX; 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 S1729529AbfCLRRR (ORCPT + 99 others); Tue, 12 Mar 2019 13:17:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:57778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729019AbfCLRQJ (ORCPT ); Tue, 12 Mar 2019 13:16:09 -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 0E5812183F; Tue, 12 Mar 2019 17:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410969; bh=8xSJeDtXk9xVdngmmovu5aR1EOhcq5cKKEiUr6uN82Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=igCYS+rXpXKu9lO28oKMI/bXSu4jJXHj0Em0jWMHAx++AkfPaXs6B0LCEAs1TG5mf ulcWBp3fXBWqS/k3M1mAkp9GIA6lTD/0qhasybROg5hgevQsq7eV6bdo9tromwJKAS gviifcxvmaoE6Vn5pq2QUZ8YdMQ9VnKoRZskkFh0= 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.14 043/135] media: uvcvideo: Fix type check leading to overflow Date: Tue, 12 Mar 2019 10:08:10 -0700 Message-Id: <20190312170345.095097787@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170341.127810985@linuxfoundation.org> References: <20190312170341.127810985@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.14-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 @@ -1054,11 +1054,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,