[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230518100829.515143-1-sukrut.bellary@linux.com>
Date: Thu, 18 May 2023 03:08:29 -0700
From: Sukrut Bellary <sukrut.bellary@...ux.com>
To: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Amol Maheshwari <amahesh@....qualcomm.com>,
Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Sukrut Bellary <sukrut.bellary@...ux.com>,
linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
Shuah Khan <skhan@...uxfoundation.org>
Subject: [PATCH] misc: fastrpc: Fix double free of 'buf' in error path
smatch warning:
drivers/misc/fastrpc.c:1926 fastrpc_req_mmap() error: double free of 'buf'
In fastrpc_req_mmap() error path, the fastrpc buffer is freed in
fastrpc_req_munmap_impl() if unmap is successful.
But in the end, there is an unconditional call to fastrpc_buf_free().
So the above case triggers the double free of fastrpc buf.
Fix this by avoiding the call to the second fastrpc_buf_free() if
fastrpc_req_munmap_impl() is successful.
'err' is not updated as it needs to retain the err returned by
qcom_scm_assign_mem(), which is the starting point of this error path.
This is based on static analysis only. Compilation tested.
Reviewed-by: Shuah Khan <skhan@...uxfoundation.org>
Signed-off-by: Sukrut Bellary <sukrut.bellary@...ux.com>
---
drivers/misc/fastrpc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index f48466960f1b..1c3ab78f274f 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1921,7 +1921,10 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
return 0;
err_assign:
- fastrpc_req_munmap_impl(fl, buf);
+ if (!fastrpc_req_munmap_impl(fl, buf)) {
+ /* buf is freed */
+ return err;
+ }
err_invoke:
fastrpc_buf_free(buf);
--
2.34.1
Powered by blists - more mailing lists