misc: fastrpc: Fix use-after-free and race in fastrpc_map_find
authorAbel Vesa <abel.vesa@linaro.org>
Thu, 24 Nov 2022 17:49:39 +0000 (17:49 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Jan 2023 06:24:35 +0000 (07:24 +0100)
commita50c5c25b6e7d2824698c0e6385f882a18f4a498
tree75e4cc819e13fdca3840bc1063b0e1313412a616
parentbab5687f4d1b01da8f2bdbcd38d7863ed17be555
misc: fastrpc: Fix use-after-free and race in fastrpc_map_find

commit 9446fa1683a7e3937d9970248ced427c1983a1c5 upstream.

Currently, there is a race window between the point when the mutex is
unlocked in fastrpc_map_lookup and the reference count increasing
(fastrpc_map_get) in fastrpc_map_find, which can also lead to
use-after-free.

So lets merge fastrpc_map_find into fastrpc_map_lookup which allows us
to both protect the maps list by also taking the &fl->lock spinlock and
the reference count, since the spinlock will be released only after.
Add take_ref argument to make this suitable for all callers.

Fixes: 8f6c1d8c4f0c ("misc: fastrpc: Add fdlist implementation")
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-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/fastrpc.c