From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D085C4167B for ; Sun, 12 Nov 2023 13:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbjKLNlt (ORCPT ); Sun, 12 Nov 2023 08:41:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232450AbjKLNli (ORCPT ); Sun, 12 Nov 2023 08:41:38 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98314618D; Sun, 12 Nov 2023 05:29:26 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37370C43397; Sun, 12 Nov 2023 13:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699795766; bh=sVvZa4Bs+WNEGdDtsEb8bHpFXSQxWtwFIO+Tf2Ly7H0=; h=From:To:Cc:Subject:Date:From; b=oitVBDssK8tJUL7HKVoW8chRXZI0YAhrQIaQY4QngY3CH5NSHkVCvzhoEkH+SBtZx Ur6aXUcheRaA4bVdtG0tCiaYxILiUj2FtT1pUGPS8JLC74YrLu5PjgicHzGTz8kFup 5QdesJOgzvrTZ252ni9ynJNcopMyeZCgOZO7Yi+oRziuqKDGtrHyHoQhgkHoq6N96u iJ5PLzVUSop0tXS7NF3ENNMHNHkMKu/XCt7ggCOXYpccfff/pq14E6/vr/h2i1BfnI wGdfkgayZeVlL5QG6dhT4t2OGw5ejjIQKMvdrSX3du+V75PUpwv3H5w6E6jOx4DpXG rPgbJ2gn/Gi9g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rajeshwar R Shinde , syzbot+e27f3dbdab04e43b9f73@syzkaller.appspotmail.com, Hans Verkuil , Sasha Levin , hverkuil@xs4all.nl, linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 1/4] media: gspca: cpia1: shift-out-of-bounds in set_flicker Date: Sun, 12 Nov 2023 08:29:19 -0500 Message-ID: <20231112132923.176955-1-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.14.329 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rajeshwar R Shinde [ Upstream commit 099be1822d1f095433f4b08af9cc9d6308ec1953 ] Syzkaller reported the following issue: UBSAN: shift-out-of-bounds in drivers/media/usb/gspca/cpia1.c:1031:27 shift exponent 245 is too large for 32-bit type 'int' When the value of the variable "sd->params.exposure.gain" exceeds the number of bits in an integer, a shift-out-of-bounds error is reported. It is triggered because the variable "currentexp" cannot be left-shifted by more than the number of bits in an integer. In order to avoid invalid range during left-shift, the conditional expression is added. Reported-by: syzbot+e27f3dbdab04e43b9f73@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/20230818164522.12806-1-coolrrsh@gmail.com Link: https://syzkaller.appspot.com/bug?extid=e27f3dbdab04e43b9f73 Signed-off-by: Rajeshwar R Shinde Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/media/usb/gspca/cpia1.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/usb/gspca/cpia1.c b/drivers/media/usb/gspca/cpia1.c index e91d00762e94b..bf34479a87cc5 100644 --- a/drivers/media/usb/gspca/cpia1.c +++ b/drivers/media/usb/gspca/cpia1.c @@ -28,6 +28,7 @@ #include #include +#include #include "gspca.h" @@ -1032,6 +1033,8 @@ static int set_flicker(struct gspca_dev *gspca_dev, int on, int apply) sd->params.exposure.expMode = 2; sd->exposure_status = EXPOSURE_NORMAL; } + if (sd->params.exposure.gain >= BITS_PER_TYPE(currentexp)) + return -EINVAL; currentexp = currentexp << sd->params.exposure.gain; sd->params.exposure.gain = 0; /* round down current exposure to nearest value */ -- 2.42.0