Skip to content

Commit 4716c23

Browse files
ekanshibugregkh
authored andcommitted
misc: fastrpc: Remove buffer from list prior to unmap operation
[ Upstream commit 6102ceb ] fastrpc_req_munmap_impl() is called to unmap any buffer. The buffer is getting removed from the list after it is unmapped from DSP. This can create potential race conditions if multiple threads invoke unmap concurrently, where one thread may remove the entry from the list while another thread's unmap operation is still ongoing. Fix this by removing the buffer entry from the list before calling the unmap operation. If the unmap fails, the entry is re-added to the list so that userspace can retry the unmap, or alternatively, the buffer will be cleaned up during device release when the DSP process is torn down and all DSP-side mappings are freed along with remaining buffers in the list. Fixes: 2419e55 ("misc: fastrpc: add mmap/unmap support") Cc: stable@kernel.org Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com> Signed-off-by: Jianping Li <jianping.li@oss.qualcomm.com> Signed-off-by: Srinivas Kandagatla <srini@kernel.org> Link: https://patch.msgid.link/20260724223342.629168-3-srini@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b10e064 commit 4716c23

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎drivers/misc/fastrpc.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,6 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *
14091409
&args[0]);
14101410
if (!err) {
14111411
dev_dbg(dev, "unmmap\tpt 0x%09lx OK\n", buf->raddr);
1412-
spin_lock(&fl->lock);
1413-
list_del(&buf->node);
1414-
spin_unlock(&fl->lock);
14151412
fastrpc_buf_free(buf);
14161413
} else {
14171414
dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr);
@@ -1425,13 +1422,15 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
14251422
struct fastrpc_buf *buf = NULL, *iter, *b;
14261423
struct fastrpc_req_munmap req;
14271424
struct device *dev = fl->sctx->dev;
1425+
int err;
14281426

14291427
if (copy_from_user(&req, argp, sizeof(req)))
14301428
return -EFAULT;
14311429

14321430
spin_lock(&fl->lock);
14331431
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
14341432
if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
1433+
list_del(&iter->node);
14351434
buf = iter;
14361435
break;
14371436
}
@@ -1444,7 +1443,14 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
14441443
return -EINVAL;
14451444
}
14461445

1447-
return fastrpc_req_munmap_impl(fl, buf);
1446+
err = fastrpc_req_munmap_impl(fl, buf);
1447+
if (err) {
1448+
spin_lock(&fl->lock);
1449+
list_add_tail(&buf->node, &fl->mmaps);
1450+
spin_unlock(&fl->lock);
1451+
}
1452+
1453+
return err;
14481454
}
14491455

14501456
static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)

0 commit comments

Comments
 (0)