Skip to content

Commit 4e84a34

Browse files
committed
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 d512c1f commit 4e84a34

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
@@ -2007,9 +2007,6 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *
20072007
&args[0]);
20082008
if (!err) {
20092009
dev_dbg(dev, "unmmap\tpt 0x%09lx OK\n", buf->raddr);
2010-
spin_lock(&fl->lock);
2011-
list_del(&buf->node);
2012-
spin_unlock(&fl->lock);
20132010
fastrpc_buf_free(buf);
20142011
} else {
20152012
dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr);
@@ -2023,13 +2020,15 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
20232020
struct fastrpc_buf *buf = NULL, *iter, *b;
20242021
struct fastrpc_req_munmap req;
20252022
struct device *dev = fl->sctx->dev;
2023+
int err;
20262024

20272025
if (copy_from_user(&req, argp, sizeof(req)))
20282026
return -EFAULT;
20292027

20302028
spin_lock(&fl->lock);
20312029
list_for_each_entry_safe(iter, b, &fl->mmaps, node) {
20322030
if ((iter->raddr == req.vaddrout) && (iter->size == req.size)) {
2031+
list_del(&iter->node);
20332032
buf = iter;
20342033
break;
20352034
}
@@ -2042,7 +2041,14 @@ static int fastrpc_req_munmap(struct fastrpc_user *fl, char __user *argp)
20422041
return -EINVAL;
20432042
}
20442043

2045-
return fastrpc_req_munmap_impl(fl, buf);
2044+
err = fastrpc_req_munmap_impl(fl, buf);
2045+
if (err) {
2046+
spin_lock(&fl->lock);
2047+
list_add_tail(&buf->node, &fl->mmaps);
2048+
spin_unlock(&fl->lock);
2049+
}
2050+
2051+
return err;
20462052
}
20472053

20482054
static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
@@ -2133,14 +2139,17 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
21332139

21342140
if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
21352141
err = -EFAULT;
2136-
goto err_assign;
2142+
goto err_copy;
21372143
}
21382144

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

21422148
return 0;
2143-
2149+
err_copy:
2150+
spin_lock(&fl->lock);
2151+
list_del(&buf->node);
2152+
spin_unlock(&fl->lock);
21442153
err_assign:
21452154
fastrpc_req_munmap_impl(fl, buf);
21462155

0 commit comments

Comments
 (0)