This is a note to let you know that I've just added the patch titled misc: fastrpc: Don't remove map on creater_process and device_release to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: misc-fastrpc-don-t-remove-map-on-creater_process-and-device_release.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 5bb96c8f9268e2fdb0e5321cbc358ee5941efc15 Mon Sep 17 00:00:00 2001 From: Abel Vesa <abel.vesa@xxxxxxxxxx> Date: Thu, 24 Nov 2022 17:49:40 +0000 Subject: misc: fastrpc: Don't remove map on creater_process and device_release From: Abel Vesa <abel.vesa@xxxxxxxxxx> 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: b49f6d83e290 ("misc: fastrpc: Fix a possible double free") Cc: stable <stable@xxxxxxxxxx> Co-developed-by: Ola Jeppsson <ola@xxxxxxxx> Signed-off-by: Ola Jeppsson <ola@xxxxxxxx> Signed-off-by: Abel Vesa <abel.vesa@xxxxxxxxxx> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxx> Link: https://lore.kernel.org/r/20221124174941.418450-3-srinivas.kandagatla@xxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/misc/fastrpc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -316,6 +316,13 @@ static void fastrpc_free_map(struct kref 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); } @@ -1266,12 +1273,7 @@ err_invoke: fl->init_mem = NULL; fastrpc_buf_free(imem); err_alloc: - if (map) { - spin_lock(&fl->lock); - list_del(&map->node); - spin_unlock(&fl->lock); - fastrpc_map_put(map); - } + fastrpc_map_put(map); err: kfree(args); @@ -1347,10 +1349,8 @@ static int fastrpc_device_release(struct fastrpc_context_put(ctx); } - list_for_each_entry_safe(map, m, &fl->maps, node) { - list_del(&map->node); + list_for_each_entry_safe(map, m, &fl->maps, node) fastrpc_map_put(map); - } list_for_each_entry_safe(buf, b, &fl->mmaps, node) { list_del(&buf->node); Patches currently in stable-queue which might be from abel.vesa@xxxxxxxxxx are queue-6.1/misc-fastrpc-don-t-remove-map-on-creater_process-and-device_release.patch queue-6.1/misc-fastrpc-fix-use-after-free-race-condition-for-maps.patch queue-6.1/misc-fastrpc-fix-use-after-free-and-race-in-fastrpc_map_find.patch