* [PATCH] misc: fastrpc: fix potential fastrpc_invoke_ctx leak
@ 2020-05-11 16:29 Srinivas Kandagatla
2020-05-12 1:18 ` Bjorn Andersson
0 siblings, 1 reply; 3+ messages in thread
From: Srinivas Kandagatla @ 2020-05-11 16:29 UTC (permalink / raw)
To: gregkh
Cc: linux-arm-msm, linux-kernel, arnd, Srinivas Kandagatla, Dan Carpenter
fastrpc_invoke_ctx can have refcount of 2 in error path where
rpmsg_send() fails to send invoke message. decrement the refcount
properly in the error path to fix this leak.
This also fixes below static checker warning:
drivers/misc/fastrpc.c:990 fastrpc_internal_invoke()
warn: 'ctx->refcount.refcount.ref.counter' not decremented on lines: 990.
Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
drivers/misc/fastrpc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 9065d3e71ff7..07065728e39f 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -949,8 +949,10 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
dma_wmb();
/* Send invoke buffer to remote dsp */
err = fastrpc_invoke_send(fl->sctx, ctx, kernel, handle);
- if (err)
+ if (err) {
+ fastrpc_context_put(ctx);
goto bail;
+ }
if (kernel) {
if (!wait_for_completion_timeout(&ctx->work, 10 * HZ))
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: fastrpc: fix potential fastrpc_invoke_ctx leak
2020-05-11 16:29 [PATCH] misc: fastrpc: fix potential fastrpc_invoke_ctx leak Srinivas Kandagatla
@ 2020-05-12 1:18 ` Bjorn Andersson
2020-05-12 10:42 ` Srinivas Kandagatla
0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Andersson @ 2020-05-12 1:18 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: gregkh, linux-arm-msm, linux-kernel, arnd, Dan Carpenter
On Mon 11 May 09:29 PDT 2020, Srinivas Kandagatla wrote:
> fastrpc_invoke_ctx can have refcount of 2 in error path where
> rpmsg_send() fails to send invoke message. decrement the refcount
> properly in the error path to fix this leak.
>
> This also fixes below static checker warning:
>
> drivers/misc/fastrpc.c:990 fastrpc_internal_invoke()
> warn: 'ctx->refcount.refcount.ref.counter' not decremented on lines: 990.
>
> Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
> drivers/misc/fastrpc.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 9065d3e71ff7..07065728e39f 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -949,8 +949,10 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
> dma_wmb();
> /* Send invoke buffer to remote dsp */
> err = fastrpc_invoke_send(fl->sctx, ctx, kernel, handle);
> - if (err)
> + if (err) {
> + fastrpc_context_put(ctx);
So we refcount ctx once for the invoke function and once between send
and callback. And this fastrpc_context_put() would counter the fact that
rpmsg_send() failed, so we will not get the "remote's" put().
I think that if you moved this call inside fastrpc_invoke_send() it's
relationship to the failing rpmsg_send() would be obvious.
Regards,
Bjorn
> goto bail;
> + }
>
> if (kernel) {
> if (!wait_for_completion_timeout(&ctx->work, 10 * HZ))
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: fastrpc: fix potential fastrpc_invoke_ctx leak
2020-05-12 1:18 ` Bjorn Andersson
@ 2020-05-12 10:42 ` Srinivas Kandagatla
0 siblings, 0 replies; 3+ messages in thread
From: Srinivas Kandagatla @ 2020-05-12 10:42 UTC (permalink / raw)
To: Bjorn Andersson; +Cc: gregkh, linux-arm-msm, linux-kernel, arnd, Dan Carpenter
On 12/05/2020 02:18, Bjorn Andersson wrote:
> On Mon 11 May 09:29 PDT 2020, Srinivas Kandagatla wrote:
>
>> fastrpc_invoke_ctx can have refcount of 2 in error path where
>> rpmsg_send() fails to send invoke message. decrement the refcount
>> properly in the error path to fix this leak.
>>
>> This also fixes below static checker warning:
>>
>> drivers/misc/fastrpc.c:990 fastrpc_internal_invoke()
>> warn: 'ctx->refcount.refcount.ref.counter' not decremented on lines: 990.
>>
>> Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context")
>> Reported-by: Dan Carpenter<dan.carpenter@oracle.com>
>> Signed-off-by: Srinivas Kandagatla<srinivas.kandagatla@linaro.org>
>> ---
>> drivers/misc/fastrpc.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> index 9065d3e71ff7..07065728e39f 100644
>> --- a/drivers/misc/fastrpc.c
>> +++ b/drivers/misc/fastrpc.c
>> @@ -949,8 +949,10 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
>> dma_wmb();
>> /* Send invoke buffer to remote dsp */
>> err = fastrpc_invoke_send(fl->sctx, ctx, kernel, handle);
>> - if (err)
>> + if (err) {
>> + fastrpc_context_put(ctx);
> So we refcount ctx once for the invoke function and once between send
> and callback. And this fastrpc_context_put() would counter the fact that
> rpmsg_send() failed, so we will not get the "remote's" put().
>
> I think that if you moved this call inside fastrpc_invoke_send() it's
> relationship to the failing rpmsg_send() would be obvious.
That works as well, and sounds much cleaner!
thanks,
srini
>
> Regards,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-12 10:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 16:29 [PATCH] misc: fastrpc: fix potential fastrpc_invoke_ctx leak Srinivas Kandagatla
2020-05-12 1:18 ` Bjorn Andersson
2020-05-12 10: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;
as well as URLs for NNTP newsgroup(s).