Skip to content

Commit da1ba64

Browse files
quic-lxu5gregkh
authored andcommitted
misc: fastrpc: fix possible map leak in fastrpc_put_args
copy_to_user() failure would cause an early return without cleaning up the fdlist, which has been updated by the DSP. This could lead to map leak. Fix this by redirecting to a cleanup path on failure, ensuring that all mapped buffers are properly released before returning. Fixes: c68cfb7 ("misc: fastrpc: Add support for context Invoke method") Cc: stable@kernel.org Co-developed-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com> Signed-off-by: Ling Xu <quic_lxu5@quicinc.com> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Signed-off-by: Srinivas Kandagatla <srini@kernel.org> Link: https://lore.kernel.org/r/20250912131236.303102-4-srini@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9031626 commit da1ba64

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
10851085
struct fastrpc_phy_page *pages;
10861086
u64 *fdlist;
10871087
int i, inbufs, outbufs, handles;
1088+
int ret = 0;
10881089

10891090
inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
10901091
outbufs = REMOTE_SCALARS_OUTBUFS(ctx->sc);
@@ -1100,14 +1101,17 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
11001101
u64 len = rpra[i].buf.len;
11011102

11021103
if (!kernel) {
1103-
if (copy_to_user((void __user *)dst, src, len))
1104-
return -EFAULT;
1104+
if (copy_to_user((void __user *)dst, src, len)) {
1105+
ret = -EFAULT;
1106+
goto cleanup_fdlist;
1107+
}
11051108
} else {
11061109
memcpy(dst, src, len);
11071110
}
11081111
}
11091112
}
11101113

1114+
cleanup_fdlist:
11111115
/* Clean up fdlist which is updated by DSP */
11121116
for (i = 0; i < FASTRPC_MAX_FDLIST; i++) {
11131117
if (!fdlist[i])
@@ -1116,7 +1120,7 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
11161120
fastrpc_map_put(mmap);
11171121
}
11181122

1119-
return 0;
1123+
return ret;
11201124
}
11211125

11221126
static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx,

0 commit comments

Comments
 (0)