Skip to content

Commit 5d08c5a

Browse files
ekanshibuJianping-Li
authored andcommitted
FROMLIST: misc: fastrpc: Remove buffer from list prior to unmap operation
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 any other thread removes the entry from list while unmap operation is ongoing. Remove the entry before calling unmap operation. Link: https://lore.kernel.org/all/20260409062617.1182-3-jianping.li@oss.qualcomm.com/ Fixes: 2419e55 ("misc: fastrpc: add mmap/unmap support") 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: Jianping Li <jianping.li@oss.qualcomm.com>
1 parent 10c92d2 commit 5d08c5a

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,9 +1958,6 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *
19581958
&args[0]);
19591959
if (!err) {
19601960
dev_dbg(dev, "unmmap\tpt 0x%09lx OK\n", buf->raddr);
1961-
spin_lock(&fl->lock);
1962-
list_del(&buf->node);
1963-
spin_unlock(&fl->lock);
19641961
fastrpc_buf_free(buf);
19651962
} else {
19661963
dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr);
@@ -1974,13 +1971,15 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
19741971
struct fastrpc_buf *buf = NULL, *iter, *b;
19751972
struct fastrpc_req_munmap req;
19761973
struct device *dev = fl->sctx->dev;
1974+
int err;
19771975

19781976
if (copy_from_user(&req, argp, sizeof(req)))
19791977
return -EFAULT;
19801978

19811979
spin_lock(&fl->lock);
19821980
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
19831981
if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
1982+
list_del(&iter->node);
19841983
buf = iter;
19851984
break;
19861985
}
@@ -1993,7 +1992,14 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
19931992
return -EINVAL;
19941993
}
19951994

1996-
return fastrpc_req_munmap_impl(fl, buf);
1995+
err = fastrpc_req_munmap_impl(fl, buf);
1996+
if (err) {
1997+
spin_lock(&fl->lock);
1998+
list_add_tail(&buf->node, &fl->mmaps);
1999+
spin_unlock(&fl->lock);
2000+
}
2001+
2002+
return err;
19972003
}
19982004

19992005
static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
@@ -2083,14 +2089,17 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
20832089

20842090
if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
20852091
err = -EFAULT;
2086-
goto err_assign;
2092+
goto err_copy;
20872093
}
20882094

20892095
dev_dbg(dev, "mmap\t\tpt 0x%09lx OK [len 0x%08llx]\n",
20902096
buf->raddr, buf->size);
20912097

20922098
return 0;
2093-
2099+
err_copy:
2100+
spin_lock(&fl->lock);
2101+
list_del(&buf->node);
2102+
spin_unlock(&fl->lock);
20942103
err_assign:
20952104
fastrpc_req_munmap_impl(fl, buf);
20962105

0 commit comments

Comments
 (0)