Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp9243106rwb; Thu, 24 Nov 2022 09:53:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4J3RYpXAc0JfFSGZ5qTXQzfjZLKvd//ziNuYAujQ7O08WIMmRWizDBHgJAs543bSdTbebO X-Received: by 2002:a17:906:361a:b0:7ae:129b:2ce7 with SMTP id q26-20020a170906361a00b007ae129b2ce7mr15661691ejb.92.1669312417670; Thu, 24 Nov 2022 09:53:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669312417; cv=none; d=google.com; s=arc-20160816; b=Ul54l/asNdcFtkRmGzHR3dcWycwUwKniCgem6W5ElE/5ecJ4K3xdvhJGI7+WBPukPB hV1dSeGQv2/QW/V4go52cDqhMh2ZbUKS+yyrqaGsC4L4PCQ8AOfSfOuaPRygYVgI1SeW tx6NnxMTrbgpFCxixmXsYTM6ga5AKrq+Ynz9HoazPQTdiYQ4i0WEYRSCCiEPQG7UGI6i U+52fQJTIZX3TOhFFzK9YSqnOo2dOMhYhsaZqXbuoCH58BLVjVWUA686m882Bt9lzFkb cAfFvCRGXtcByz5Qnpkl//oyWTRpSlTrJboW7mfU93BQyzf0AybOZk1R6vzdmotamBW/ FnRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WnrDbdRJkbksqZItXruR6kyL5+sqtubhQgH9dDxfehQ=; b=Kjl3gQS07KonB0XJqik+dQN8wsESwnAzNPipPX+pZf15sgJcXyEg/w2oke4n/vJbDc /Nvf/8fdIOSUPGX/QsUBVXsmK00sMy6r1jnibKozQ6ga0WoGhEgMC3YM5G95IC+sDuuX 2VUKAtRT9DoamLlGLw/pu0DS4zPfocn6+LgH0JK/vZu74NDyt5J+gnesaZ8hUYfA5v4G bbNlkUDzE+OVntgl7fdW8X4wgtTKudrcru/5RrpH8jrXijpRG8kosPAo4vp0u6F6Q/p9 /l84EQqct6DaKLdE6V2DChdp43MF0w6mYIO2mQCk83kchgF1sEf4JZ4fq9/mKQPSl9J/ wMBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xoMkl3Ee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020aa7df85000000b0046799762e48si1006131edy.437.2022.11.24.09.53.16; Thu, 24 Nov 2022 09:53:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xoMkl3Ee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229706AbiKXRuB (ORCPT + 87 others); Thu, 24 Nov 2022 12:50:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbiKXRty (ORCPT ); Thu, 24 Nov 2022 12:49:54 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D50914A2EB for ; Thu, 24 Nov 2022 09:49:49 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id x5so3459424wrt.7 for ; Thu, 24 Nov 2022 09:49:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WnrDbdRJkbksqZItXruR6kyL5+sqtubhQgH9dDxfehQ=; b=xoMkl3EeeMJyo2ElRyotEqbHF4q3toa1fIBVElAPlmfzfxIlN/Tv9nzrFEvqKil4U/ T75C7W15kUrJq4v5/Pp6sX+DBu/0JPFeMJE04JZ0B8+1qRZkB74QFhAfJu5fQpuMLsg2 NG15tCUEQrlJI+1nTxOou0+jKdYTrAdqzZJOEgc1r5sMNasBL/fbyfIRDVQtVyVrpxxp AmwszvnbzSEqM2HkdCprCvHXGKr8ZH4y7QeTTjJNynOcy3ezTJtZVTfc3lrNqUCFSMoF l765G/f21FSHhFSMS984AihwFVeebbBXbkIfHYV59Lch5+Gn3B6BUAbGu5rLbXl1F7wm D8jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WnrDbdRJkbksqZItXruR6kyL5+sqtubhQgH9dDxfehQ=; b=mnVCSLw8rQ4keoJMScOGohluU/WMOlRXl94NfnuX/qjjG4IG+ea7+dHwstu+R89m5g XIZ/HuwhlWqpIJ/WqKavG/oDFJaa3U+/9ztQ57uTuth4qcOWXO2AOLhLK4PJrWHghp0g 3yMosvXIZYc1eL6CoxWTro5ZCZ9OFKCyUwiwQk1IZxzoVTvG3/iSl0P9l5ciHKYciWBF tXP/4mkffY2lScYtZ5V1vuzscssGL3vrxE3RXEsRBekyBeIBGyjg3ViLiAdkcL5ippnc JinTb/0S9KKWiZ1nhD2HjHrNcrx9v5cooDvtimP6Y827ZH/SsabGGNTcXTUWCDISyqVf io6Q== X-Gm-Message-State: ANoB5pnDhMnArzJ2dkWuhLu7wk5lvFZ+Lna7QUoG56Ye/D5WFI8b9dkx t2MKxKhjb5g65/nXw0TMoX1dow== X-Received: by 2002:a5d:6b46:0:b0:236:56a6:823e with SMTP id x6-20020a5d6b46000000b0023656a6823emr20762122wrw.495.1669312188150; Thu, 24 Nov 2022 09:49:48 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id l11-20020a1c790b000000b003b4a699ce8esm6250863wme.6.2022.11.24.09.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 09:49:47 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Abel Vesa , Ola Jeppsson , Srinivas Kandagatla Subject: [PATCH 2/3] misc: fastrpc: Don't remove map on creater_process and device_release Date: Thu, 24 Nov 2022 17:49:40 +0000 Message-Id: <20221124174941.418450-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221124174941.418450-1-srinivas.kandagatla@linaro.org> References: <20221124174941.418450-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Abel Vesa 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") Co-developed-by: Ola Jeppsson Signed-off-by: Ola Jeppsson Signed-off-by: Abel Vesa Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index fc2173c59f8b..9ecbf673d321 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -316,6 +316,13 @@ static void fastrpc_free_map(struct kref *ref) 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 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, 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 inode *inode, struct file *file) 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); -- 2.25.1