misc: fastrpc: Don't remove map on creater_process and device_release
commit 5bb96c8f9268e2fdb0e5321cbc358ee5941efc15 upstream.
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: b49f6d83e2
("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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
e0db5d44bc
commit
193cd85314
@@ -247,6 +247,13 @@ static void fastrpc_free_map(struct kref *ref)
|
|||||||
dma_buf_put(map->buf);
|
dma_buf_put(map->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (map->fl) {
|
||||||
|
spin_lock(&map->fl->lock);
|
||||||
|
list_del(&map->node);
|
||||||
|
spin_unlock(&map->fl->lock);
|
||||||
|
map->fl = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
kfree(map);
|
kfree(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1112,12 +1119,7 @@ err_invoke:
|
|||||||
fl->init_mem = NULL;
|
fl->init_mem = NULL;
|
||||||
fastrpc_buf_free(imem);
|
fastrpc_buf_free(imem);
|
||||||
err_alloc:
|
err_alloc:
|
||||||
if (map) {
|
fastrpc_map_put(map);
|
||||||
spin_lock(&fl->lock);
|
|
||||||
list_del(&map->node);
|
|
||||||
spin_unlock(&fl->lock);
|
|
||||||
fastrpc_map_put(map);
|
|
||||||
}
|
|
||||||
err:
|
err:
|
||||||
kfree(args);
|
kfree(args);
|
||||||
|
|
||||||
@@ -1194,10 +1196,8 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
|
|||||||
fastrpc_context_put(ctx);
|
fastrpc_context_put(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
list_for_each_entry_safe(map, m, &fl->maps, node) {
|
list_for_each_entry_safe(map, m, &fl->maps, node)
|
||||||
list_del(&map->node);
|
|
||||||
fastrpc_map_put(map);
|
fastrpc_map_put(map);
|
||||||
}
|
|
||||||
|
|
||||||
list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
|
list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
|
||||||
list_del(&buf->node);
|
list_del(&buf->node);
|
||||||
|
Reference in New Issue
Block a user