* [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path
@ 2023-06-02 11:36 Sukrut Bellary
2023-06-12 10:57 ` Srinivas Kandagatla
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sukrut Bellary @ 2023-06-02 11:36 UTC (permalink / raw)
To: Srinivas Kandagatla, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Dan Carpenter, Abel Vesa
Cc: Sukrut Bellary, linux-arm-msm, linux-kernel, kernel-janitors,
Shuah Khan
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.
Fixes: 72fa6f7820c4 ("misc: fastrpc: Rework fastrpc_req_munmap")
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Sukrut Bellary <sukrut.bellary@linux.com>
---
This is based on static analysis. Compilation tested.
---
Changes in v2:
- Fixed the commit message.
- Addressed the review comment about deleting buf from the list
before freeing.
- Link to v1: https://lore.kernel.org/all/20230518100829.515143-1-sukrut.bellary@linux.com/
---
drivers/misc/fastrpc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index f48466960f1b..b3b520fcfb75 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1882,7 +1882,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
&args[0]);
if (err) {
dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size);
- goto err_invoke;
+ fastrpc_buf_free(buf);
+ return err;
}
/* update the buffer to be able to deallocate the memory on the DSP */
@@ -1922,8 +1923,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
err_assign:
fastrpc_req_munmap_impl(fl, buf);
-err_invoke:
- fastrpc_buf_free(buf);
return err;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path
2023-06-02 11:36 [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path Sukrut Bellary
@ 2023-06-12 10:57 ` Srinivas Kandagatla
2023-06-12 10:58 ` Srinivas Kandagatla
2024-08-16 8:42 ` Srinivas Kandagatla
2 siblings, 0 replies; 6+ messages in thread
From: Srinivas Kandagatla @ 2023-06-12 10:57 UTC (permalink / raw)
To: Sukrut Bellary, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Dan Carpenter, Abel Vesa
Cc: linux-arm-msm, linux-kernel, kernel-janitors, Shuah Khan
On 02/06/2023 12:36, Sukrut Bellary wrote:
> 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.
>
> Fixes: 72fa6f7820c4 ("misc: fastrpc: Rework fastrpc_req_munmap")
> Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
> Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
> Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Not sure how was this reviewed-by picked up on this patch.
Suggested-by will be a right choice here.
Will manually edit before applying it.
--srini
> Signed-off-by: Sukrut Bellary <sukrut.bellary@linux.com>
> ---
> This is based on static analysis. Compilation tested.
> ---
> Changes in v2:
> - Fixed the commit message.
> - Addressed the review comment about deleting buf from the list
> before freeing.
> - Link to v1: https://lore.kernel.org/all/20230518100829.515143-1-sukrut.bellary@linux.com/
> ---
> drivers/misc/fastrpc.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index f48466960f1b..b3b520fcfb75 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -1882,7 +1882,8 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
> &args[0]);
> if (err) {
> dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size);
> - goto err_invoke;
> + fastrpc_buf_free(buf);
> + return err;
> }
>
> /* update the buffer to be able to deallocate the memory on the DSP */
> @@ -1922,8 +1923,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>
> err_assign:
> fastrpc_req_munmap_impl(fl, buf);
> -err_invoke:
> - fastrpc_buf_free(buf);
>
> return err;
> }
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path
2023-06-02 11:36 [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path Sukrut Bellary
2023-06-12 10:57 ` Srinivas Kandagatla
@ 2023-06-12 10:58 ` Srinivas Kandagatla
2024-08-15 9:25 ` Dan Carpenter
2024-08-16 8:42 ` Srinivas Kandagatla
2 siblings, 1 reply; 6+ messages in thread
From: Srinivas Kandagatla @ 2023-06-12 10:58 UTC (permalink / raw)
To: Amol Maheshwari, Arnd Bergmann, Greg Kroah-Hartman, Dan Carpenter,
Abel Vesa, Sukrut Bellary
Cc: linux-arm-msm, linux-kernel, kernel-janitors, Shuah Khan
On Fri, 02 Jun 2023 04:36:02 -0700, Sukrut Bellary wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] misc: fastrpc: Fix double free of 'buf' in error path
commit: 5b3006fffce89706a12741d7f657869ca2be1640
Best regards,
--
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path
2023-06-12 10:58 ` Srinivas Kandagatla
@ 2024-08-15 9:25 ` Dan Carpenter
2024-08-16 8:42 ` Srinivas Kandagatla
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2024-08-15 9:25 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Amol Maheshwari, Arnd Bergmann, Greg Kroah-Hartman, Abel Vesa,
Sukrut Bellary, linux-arm-msm, linux-kernel, kernel-janitors,
Shuah Khan
On Mon, Jun 12, 2023 at 11:58:01AM +0100, Srinivas Kandagatla wrote:
>
> On Fri, 02 Jun 2023 04:36:02 -0700, Sukrut Bellary wrote:
> > 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.
> >
> > [...]
>
> Applied, thanks!
>
> [1/1] misc: fastrpc: Fix double free of 'buf' in error path
> commit: 5b3006fffce89706a12741d7f657869ca2be1640
>
This patch wasn't actually applied. I'm not sure what went wrong.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path
2024-08-15 9:25 ` Dan Carpenter
@ 2024-08-16 8:42 ` Srinivas Kandagatla
0 siblings, 0 replies; 6+ messages in thread
From: Srinivas Kandagatla @ 2024-08-16 8:42 UTC (permalink / raw)
To: Dan Carpenter
Cc: Amol Maheshwari, Arnd Bergmann, Greg Kroah-Hartman, Abel Vesa,
Sukrut Bellary, linux-arm-msm, linux-kernel, kernel-janitors,
Shuah Khan
On 15/08/2024 10:25, Dan Carpenter wrote:
> On Mon, Jun 12, 2023 at 11:58:01AM +0100, Srinivas Kandagatla wrote:
>>
>> On Fri, 02 Jun 2023 04:36:02 -0700, Sukrut Bellary wrote:
>>> 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.
>>>
>>> [...]
>>
>> Applied, thanks!
>>
>> [1/1] misc: fastrpc: Fix double free of 'buf' in error path
>> commit: 5b3006fffce89706a12741d7f657869ca2be1640
>>
>
> This patch wasn't actually applied. I'm not sure what went wrong.
Am not sure either, its now applied!
thanks for checking this.
--srini
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path
2023-06-02 11:36 [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path Sukrut Bellary
2023-06-12 10:57 ` Srinivas Kandagatla
2023-06-12 10:58 ` Srinivas Kandagatla
@ 2024-08-16 8:42 ` Srinivas Kandagatla
2 siblings, 0 replies; 6+ messages in thread
From: Srinivas Kandagatla @ 2024-08-16 8:42 UTC (permalink / raw)
To: Amol Maheshwari, Arnd Bergmann, Greg Kroah-Hartman, Dan Carpenter,
Abel Vesa, Sukrut Bellary
Cc: linux-arm-msm, linux-kernel, kernel-janitors, Shuah Khan
On Fri, 02 Jun 2023 04:36:02 -0700, Sukrut Bellary wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] misc: fastrpc: Fix double free of 'buf' in error path
commit: b056e4e23acbbbf12fa011caa781f7cecbd5b311
Best regards,
--
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-16 8:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-02 11:36 [PATCH v2] misc: fastrpc: Fix double free of 'buf' in error path Sukrut Bellary
2023-06-12 10:57 ` Srinivas Kandagatla
2023-06-12 10:58 ` Srinivas Kandagatla
2024-08-15 9:25 ` Dan Carpenter
2024-08-16 8:42 ` Srinivas Kandagatla
2024-08-16 8:42 ` Srinivas Kandagatla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox