Skip to content

Commit 5bb96c8

Browse files
abelvesagregkh
authored andcommitted
misc: fastrpc: Don't remove map on creater_process and device_release
Do not remove the map from the list on error path in fastrpc_init_create_process, instead call fastrpc_map_put, to avoid use-after-free. Do not remove it on fastrpc_device_release either, call fastrpc_map_put instead. The fastrpc_free_map is the only proper place to remove the map. This is called only after the reference count is 0. Fixes: b49f6d8 ("misc: fastrpc: Fix a possible double free") Cc: stable <stable@kernel.org> Co-developed-by: Ola Jeppsson <ola@snap.com> Signed-off-by: Ola Jeppsson <ola@snap.com> Signed-off-by: Abel Vesa <abel.vesa@linaro.org> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20221124174941.418450-3-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9446fa1 commit 5bb96c8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/misc/fastrpc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ static void fastrpc_free_map(struct kref *ref)
334334
dma_buf_put(map->buf);
335335
}
336336

337+
if (map->fl) {
338+
spin_lock(&map->fl->lock);
339+
list_del(&map->node);
340+
spin_unlock(&map->fl->lock);
341+
map->fl = NULL;
342+
}
343+
337344
kfree(map);
338345
}
339346

@@ -1434,12 +1441,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
14341441
fl->init_mem = NULL;
14351442
fastrpc_buf_free(imem);
14361443
err_alloc:
1437-
if (map) {
1438-
spin_lock(&fl->lock);
1439-
list_del(&map->node);
1440-
spin_unlock(&fl->lock);
1441-
fastrpc_map_put(map);
1442-
}
1444+
fastrpc_map_put(map);
14431445
err:
14441446
kfree(args);
14451447

@@ -1515,10 +1517,8 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
15151517
fastrpc_context_put(ctx);
15161518
}
15171519

1518-
list_for_each_entry_safe(map, m, &fl->maps, node) {
1519-
list_del(&map->node);
1520+
list_for_each_entry_safe(map, m, &fl->maps, node)
15201521
fastrpc_map_put(map);
1521-
}
15221522

15231523
list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
15241524
list_del(&buf->node);

0 commit comments

Comments
 (0)