aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2024-02-05 12:10:31 +0100
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2024-02-16 11:46:32 +0100
commitee0f8674654023320ab61373e2da83e3e0044331 (patch)
tree0def147c4bb2cebe86b5e4a45e1c9ea1fa4b249d /drivers/media
parent8cda891db3948ef311594270b663bbad2475f790 (diff)
downloadlinux-ee0f8674654023320ab61373e2da83e3e0044331.tar.gz
media: v4l2-ctrls-core.c: check min/max for menu, controls
Menu controls that use the menu_skip_mask require that the min-max range is inside 0-63. Negative values obviously make no sense for menu controls, and the maximum value is currently limited by the number of bits of the menu_skip_mask value. However, if menu_skip_mask == 0, then larger menus are fine. If we ever need to add support for larger menus that support the skip mask, then more work is needed. In the places where the menu_skip_mask is checked, use BIT_ULL to get the bit to check and check if the bit number is < BITS_PER_LONG_LONG to avoid shifting out of range. With the new check in check_range this should never happen, but it is better to be safe and avoid static analyzer warnings. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/v4l2-core/v4l2-ctrls-api.c2
-rw-r--r--drivers/media/v4l2-core/v4l2-ctrls-core.c5
2 files changed, 4 insertions, 3 deletions
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c
index 002ea6588edf1..d9a422017bd9d 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
@@ -1179,7 +1179,7 @@ int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm)
return -EINVAL;
/* Use mask to see if this menu item should be skipped */
- if (ctrl->menu_skip_mask & (1ULL << i))
+ if (i < BITS_PER_LONG_LONG && (ctrl->menu_skip_mask & BIT_ULL(i)))
return -EINVAL;
/* Empty menu items should also be skipped */
if (ctrl->type == V4L2_CTRL_TYPE_MENU) {
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 0accb96001db0..c4d995f32191c 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -1504,11 +1504,12 @@ int check_range(enum v4l2_ctrl_type type,
return 0;
case V4L2_CTRL_TYPE_MENU:
case V4L2_CTRL_TYPE_INTEGER_MENU:
- if (min > max || def < min || def > max)
+ if (min > max || def < min || def > max ||
+ min < 0 || (step && max >= BITS_PER_LONG_LONG))
return -ERANGE;
/* Note: step == menu_skip_mask for menu controls.
So here we check if the default value is masked out. */
- if (step && ((1 << def) & step))
+ if (def < BITS_PER_LONG_LONG && (step & BIT_ULL(def)))
return -EINVAL;
return 0;
case V4L2_CTRL_TYPE_STRING: