media: uvcvideo: Add sanity check to uvc_mapping_get_menu_value()
Subsystems (3)
PATCH v2 1/1 media: uvcvideo: Add sanity check to uvc_mapping_get_menu_value()
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.
---
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(-)
drivers/media/usb/uvc/uvc_ctrl.c +2 -1
@@ -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)
Signature · 1 line
2.53.0
Hi Dan
Thanks for v2.
Quoted 31 lines · Dan Carpenter
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 <[email protected]>---
v2: It's not a real bug but Ricardo asked me to add the sanity check anyway. UseBITS_PER_TYPE()instead ofBITS_PER_LONG.drivers/media/usb/uvc/uvc_ctrl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/usb/uvc/uvc_ctrl.c +2
-2@@ -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
Signature · 1 line
Ricardo Ribalda