Skip to content

Commit 4c76f33

Browse files
committed
media: v4l2-ctrls-api: fix error handling for v4l2_g_ctrl()
As detected by Coverity, the error check logic at get_ctrl() is broken: if ptr_to_user() fails to fill a control due to an error, no errors are returned and v4l2_g_ctrl() returns success on a failed operation, which may cause applications to fail. Add an error check at get_ctrl() and ensure that it will be returned to userspace without filling the control value if get_ctrl() fails. Fixes: 71c689d ("media: v4l2-ctrls: split up into four source files") Cc: stable@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent fa88dc7 commit 4c76f33

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/media/v4l2-core/v4l2-ctrls-api.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,10 @@ static int get_ctrl(struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c)
753753
for (i = 0; i < master->ncontrols; i++)
754754
cur_to_new(master->cluster[i]);
755755
ret = call_op(master, g_volatile_ctrl);
756-
new_to_user(c, ctrl);
756+
if (!ret)
757+
ret = new_to_user(c, ctrl);
757758
} else {
758-
cur_to_user(c, ctrl);
759+
ret = cur_to_user(c, ctrl);
759760
}
760761
v4l2_ctrl_unlock(master);
761762
return ret;
@@ -770,7 +771,10 @@ int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
770771
if (!ctrl || !ctrl->is_int)
771772
return -EINVAL;
772773
ret = get_ctrl(ctrl, &c);
773-
control->value = c.value;
774+
775+
if (!ret)
776+
control->value = c.value;
777+
774778
return ret;
775779
}
776780
EXPORT_SYMBOL(v4l2_g_ctrl);
@@ -811,10 +815,11 @@ static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
811815
int ret;
812816

813817
v4l2_ctrl_lock(ctrl);
814-
user_to_new(c, ctrl);
815-
ret = set_ctrl(fh, ctrl, 0);
818+
ret = user_to_new(c, ctrl);
819+
if (!ret)
820+
ret = set_ctrl(fh, ctrl, 0);
816821
if (!ret)
817-
cur_to_user(c, ctrl);
822+
ret = cur_to_user(c, ctrl);
818823
v4l2_ctrl_unlock(ctrl);
819824
return ret;
820825
}

0 commit comments

Comments
 (0)