From patchwork Fri Oct 18 05:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 13841149 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 584E617DE36; Fri, 18 Oct 2024 05:53:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729230807; cv=none; b=OrARssVwApJfIJ/bsJ1HRrDbwQYlmVvspo0f1nTgz+o87IrhaFb3+Eu8mzgoR9iZV3T6Iar2jNLxN5zLvwMC4XZnjnn7BzqwV9PAEqzDlC2LKkROO6B4veJ0ibA8g77Up1Yd2JXphmO1ermIEZxrso+jY1NfPVz5Le2sOcvS5GY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729230807; c=relaxed/simple; bh=DHJgypSXNIsIfOeTJX/YlS19CLFwnkCqj3yo7u5yJ2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tfc7cuKwlMe7yj4RbdptQxkAOGidQ90J6vJuUzb14skDMN8EV7OFlIHfKyZxFcgKRhxObdTho2yR2zmwNoLe6HIaum2I9A0tsjiXu8sduhL85imD9bu+c7pa2x4FQJ681/9YeYuSLs3LcPXtouWENELU8kLFkTBGEV5HYWhpOy0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O2V9amAP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O2V9amAP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C46CDC4CED7; Fri, 18 Oct 2024 05:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729230806; bh=DHJgypSXNIsIfOeTJX/YlS19CLFwnkCqj3yo7u5yJ2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O2V9amAPkS5QKtYA9KhunCg5Pvu7Wo66lRXGGzJjCP4ZA4RyiPvAZCh7uWG0yX0NY 6aiy1qg8AaIuaz26yb9YZcHoTnT1iY6vyC//eqrJRUupTnUhoEW2+2UbIj7e5mLLtQ OY6yP/4gXswxRIfVmYOdKE/PTUA0VUDElFVEBkhZNIDiAQw97Y/1EUXoTVCYKtGZmr JYutbIBZggim+PQwlBdYe1VKGCIWePAmsYutBRWWnoyBr/4BL4yoGWVaQ5doFVHG29 9T0Va4lRFwT/KE4aqIZHF+GXDzLpoiJOcjExb3o+ea9qjxMPMOYKhunppH24+H+zT9 sb4lgfvmCmQMQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98) (envelope-from ) id 1t1fvQ-00000005Mdx-1FuL; Fri, 18 Oct 2024 07:53:24 +0200 From: Mauro Carvalho Chehab To: Cc: Mauro Carvalho Chehab , Hans Verkuil , Mauro Carvalho Chehab , Ricardo Ribalda , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 01/13] media: v4l2-ctrls-api: fix error handling for v4l2_g_ctrl() Date: Fri, 18 Oct 2024 07:53:03 +0200 Message-ID: <4d36ccf66f48a870c9bc0f7e9fda595505c4d342.1729230718.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab 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@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-ctrls-api.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c index e5a364efd5e6..a0de7eeaf085 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-api.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c @@ -753,9 +753,10 @@ static int get_ctrl(struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c) 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; @@ -770,7 +771,10 @@ int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) 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); @@ -811,10 +815,12 @@ static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, int ret; v4l2_ctrl_lock(ctrl); - user_to_new(c, ctrl); + ret = user_to_new(c, ctrl); + if (ret) + return 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; }