From: Dan Carpenter <error27@gmail.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Ricardo Ribalda <ribalda@chromium.org>
Cc: Hans de Goede <hansg@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH v2] media: uvcvideo: Add sanity check to uvc_mapping_get_menu_value()
Date: Fri, 16 Oct 2026 11:31:38 +0300 [thread overview]
Message-ID: <atHg6s8VaFxNzuR6@stanley.mountain> (raw)
Smatch warned that "idx" could be too large, leading to an out of bounds
read. When we reviewed the callers it was a false positive. However,
add a sanity check here anyway, just for future proofing and being
consistent with the rest of the code.
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
v2: It's not a real bug but Ricardo asked me to add the sanity check
anyway. Use BITS_PER_TYPE() instead of BITS_PER_LONG.
drivers/media/usb/uvc/uvc_ctrl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index d2f722bc3459..249c68783474 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -538,7 +538,8 @@ static void uvc_mapping_set_s32(struct uvc_control_mapping *mapping,
static int uvc_mapping_get_menu_value(const struct uvc_control_mapping *mapping,
u32 idx)
{
- if (!test_bit(idx, &mapping->menu_mask))
+ if (idx >= BITS_PER_TYPE(mapping->menu_mask) ||
+ !test_bit(idx, &mapping->menu_mask))
return -EINVAL;
if (mapping->menu_mapping)
--
2.53.0
next reply other threads:[~2026-10-16 8:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 8:31 Dan Carpenter [this message]
2026-10-16 9:20 ` [PATCH v2] media: uvcvideo: Add sanity check to uvc_mapping_get_menu_value() Ricardo Ribalda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=atHg6s8VaFxNzuR6@stanley.mountain \
--to=error27@gmail.com \
--cc=hansg@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.