From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F2277E for ; Sun, 22 Jan 2023 15:09:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 038E3C433EF; Sun, 22 Jan 2023 15:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1674400165; bh=bgEPntYsatbRrx+vjYFC3iN0gYSKOYPfoZT0Yz9ek3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dO/2ZE+CtGT/bSog5U7cWlGp5TvDUJbGYI6+aC5umO6V5ue8oA6k22jrSA8cz6MIx qWq7CYTLYEO2jYHIrr1oC+kU7WdtvLgu9EG/MXOvDMPDkchSIjaGCmrJSb3B9w9Yoz qtn1NNLaMPeRrEyg7gRQQaq1xLvHc1OjmrF9tD8U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Ola Jeppsson , Abel Vesa , Srinivas Kandagatla Subject: [PATCH 5.4 27/55] misc: fastrpc: Dont remove map on creater_process and device_release Date: Sun, 22 Jan 2023 16:04:14 +0100 Message-Id: <20230122150223.359295982@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230122150222.210885219@linuxfoundation.org> References: <20230122150222.210885219@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Abel Vesa 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 Co-developed-by: Ola Jeppsson Signed-off-by: Ola Jeppsson Signed-off-by: Abel Vesa Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20221124174941.418450-3-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/misc/fastrpc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -218,6 +218,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); } @@ -1080,12 +1087,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); @@ -1161,10 +1163,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); - } fastrpc_session_free(cctx, fl->sctx); fastrpc_channel_ctx_put(cctx);