Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 608018F72 for ; Sun, 12 Nov 2023 13:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TSny24Ei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F2E0C433CC; Sun, 12 Nov 2023 13:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699795756; bh=lmoJ+SAiwdomhCe4WWGZql0wKkDSVgGhP0boOEHX0eU=; h=From:To:Cc:Subject:Date:From; b=TSny24EihZ1AbS565rEgNiAnq4XiFUydRgNIwFx5BAuPG9mcVtF7KbkpToEPquwIf 2D4alLI5iXFlGOWP9Y1jdZ5NepoJkh8EGMLm40PdZ1uTpz0jlZxpcogWFdz8su314j qGGE1SiKg0F6ArmgCuGAOxwLSen0UA7ZF+ZlkeR1YsWvF6rj87xdz6Fq1Vg+XzyMwf jYhYBFNGlM1eWyrHtcwxkXBcbkOijcnA+lsOFBfk4DrLW0fpyUVpPilF+LTNb9mqDy lWfUcRKIu60oQgxa2ayBFpxHVdg6qgVCUPjuuMWGP6XxN35GV+aAWs/nFakJPtPYcV TfA77KJfNbEoQ== 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.19 1/5] media: gspca: cpia1: shift-out-of-bounds in set_flicker Date: Sun, 12 Nov 2023 08:29:08 -0500 Message-ID: <20231112132913.176824-1-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.298 Content-Transfer-Encoding: 8bit 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 2b09af8865f40..5e785343528cc 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" @@ -1033,6 +1034,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