From: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx> commit 4c76f331a9a173ac8fe1297a9231c2a38f88e368 upstream. 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: 71c689dc2e73 ("media: v4l2-ctrls: split up into four source files") Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/media/v4l2-core/v4l2-ctrls-api.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/drivers/media/v4l2-core/v4l2-ctrls-api.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c @@ -712,9 +712,10 @@ static int get_ctrl(struct v4l2_ctrl *ct for (i = 0; i < master->ncontrols; i++) cur_to_new(master->cluster[i]); ret = call_op(master, g_volatile_ctrl); - new_to_user(c, ctrl); + if (!ret) + ret = new_to_user(c, ctrl); } else { - cur_to_user(c, ctrl); + ret = cur_to_user(c, ctrl); } v4l2_ctrl_unlock(master); return ret; @@ -729,7 +730,10 @@ int v4l2_g_ctrl(struct v4l2_ctrl_handler if (!ctrl || !ctrl->is_int) return -EINVAL; ret = get_ctrl(ctrl, &c); - control->value = c.value; + + if (!ret) + control->value = c.value; + return ret; } EXPORT_SYMBOL(v4l2_g_ctrl); @@ -770,10 +774,11 @@ static int set_ctrl_lock(struct v4l2_fh int ret; v4l2_ctrl_lock(ctrl); - user_to_new(c, ctrl); - ret = set_ctrl(fh, ctrl, 0); + ret = user_to_new(c, ctrl); + if (!ret) + ret = set_ctrl(fh, ctrl, 0); if (!ret) - cur_to_user(c, ctrl); + ret = cur_to_user(c, ctrl); v4l2_ctrl_unlock(ctrl); return ret; } Patches currently in stable-queue which might be from mchehab+huawei@xxxxxxxxxx are queue-5.15/media-dvb_frontend-don-t-play-tricks-with-underflow-.patch queue-5.15/media-cx24116-prevent-overflows-on-snr-calculus.patch queue-5.15/media-adv7604-prevent-underflow-condition-when-repor.patch queue-5.15/media-pulse8-cec-fix-data-timestamp-at-pulse8_setup.patch queue-5.15/media-v4l2-ctrls-api-fix-error-handling-for-v4l2_g_ctrl.patch queue-5.15/media-dvbdev-prevent-the-risk-of-out-of-memory-acces.patch queue-5.15/media-v4l2-tpg-prevent-the-risk-of-a-division-by-zero.patch queue-5.15/media-s5p-jpeg-prevent-buffer-overflows.patch queue-5.15/media-stb0899_algo-initialize-cfr-before-using-it.patch