Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp738722rwd; Thu, 18 May 2023 03:19:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42/qWOmyUZjNj4ZudJQ/yYaMqlBOGs5UEpiv2kyZiqqYjaOODcGwnRoQAi/mYFpQgZAHZx X-Received: by 2002:a17:90b:3613:b0:246:5f9e:e4cf with SMTP id ml19-20020a17090b361300b002465f9ee4cfmr2040260pjb.43.1684405178877; Thu, 18 May 2023 03:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684405178; cv=none; d=google.com; s=arc-20160816; b=MT3dLV2yWaq3+m+PxFOTVER8On05Zf8XTEpt+K9IWKN0lzTkpUqq158PGLbxaxwh7/ c1/zSsssDukGwfWahVgfuovYZfqDXCEPTzQxbwcq8qNgd4Bx4q5XS6iyJxcdZ0DQ5AGt oZmVsm9RlqirJ1zeh8rhYGTgw7ebzpv+te1oHwrrlGcu9L/PBGfzMzE0dqOYOIX4iShl gy23l+/G3B8k1/Kzqf8+bPCSgE4dp8ka1jnPiCcM9uk9ibMFEZXNXcLiweMURXKCyb4T pcuzPNoptVa0QDVMpBlnWAYxzQi/JUar3JjlkbNAE16b10rmB/dbgiXD2XbUOoG8Kjuu zSXQ== 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 :message-id:date:subject:cc:to:from; bh=rTItOvZyqAvodhACTuaNIkuq7MW1RtbhnQpTTB2wrgw=; b=wsvnx2IPVwBxNGua62Jh8goZm0zOryYoj7r1vngNWPMjsrD1bbyZtwk4Z6+UK5ndiN +d3JIlqs73RQpgikUKaGaDBFYr6txiMdwQmgHIKuGh0UD4reckoEhlq7aPwNoFfxaPga nLI+UYRuaUsNL5vozzwSJNOSDJceK74NiqFjVZurLjWN0kgYtFbUHrlZWyyyeuT7SB8L lP0m4d9vHUbtE1mIXCKJzk3t78CwpL918rVZBInLOfeMBqYZ69MjrqUDRTaXrxcEASam iKLXG5q2wYvyXKC2aRbErP9XlgCMqgOTThNVTdBcjjTmY0I5RBy70Z9uIzsuWZlKmCUg XFwA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a17090a9b8500b00250807ec16dsi1176207pjp.97.2023.05.18.03.19.04; Thu, 18 May 2023 03:19:38 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230363AbjERKJO (ORCPT + 99 others); Thu, 18 May 2023 06:09:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230188AbjERKJM (ORCPT ); Thu, 18 May 2023 06:09:12 -0400 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D4E31BD3; Thu, 18 May 2023 03:09:11 -0700 (PDT) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1ae50da739dso12997235ad.1; Thu, 18 May 2023 03:09:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684404551; x=1686996551; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rTItOvZyqAvodhACTuaNIkuq7MW1RtbhnQpTTB2wrgw=; b=jn9hQcaq7D7/lxJF6u+hVoHQAA8EnZuDuCN/MY1RX5EgDe622Q3MHWmNJuA7aMjSt+ E0wnE6OrjBwMYNEtu7YVDq8Vpcco/LDMtMuSSJveXz6gcZlrtJN8P8J8HeGj/LV9m41O ihGYfWWEE9vrbqBRIav7E5ClC7AxnBDjCdGkkb3bSjxIP11HJ69eruv1wsBJgm5WnYfa lDkzqPTH6qLIISoBXbJTFxPrc3Zcq4MNq1egUHu0ehnEIYi0eS629cBOMSZr9YJBymkj 1Ck0JTNMuEbbiwDWExtXm0EopiZjgLN+73sfb+CexCVxpRIAH2g0KdnQ9KsXCOX7TeVc 9Yaw== X-Gm-Message-State: AC+VfDzmpUDQb6EY8ylfTd1foD2/HkoJWW7SIeZK6mZPVbDIlte+W91z Cy3s6PtY5+SeqKhMgHekGXw= X-Received: by 2002:a17:903:24e:b0:1ae:32d3:43b2 with SMTP id j14-20020a170903024e00b001ae32d343b2mr2046272plh.25.1684404550505; Thu, 18 May 2023 03:09:10 -0700 (PDT) Received: from dev-linux.lan (cpe-70-95-21-110.san.res.rr.com. [70.95.21.110]) by smtp.gmail.com with ESMTPSA id jb15-20020a170903258f00b001ae626d051bsm1031202plb.70.2023.05.18.03.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 03:09:10 -0700 (PDT) From: Sukrut Bellary To: Srinivas Kandagatla , Amol Maheshwari , Arnd Bergmann , Greg Kroah-Hartman Cc: Sukrut Bellary , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Shuah Khan Subject: [PATCH] misc: fastrpc: Fix double free of 'buf' in error path Date: Thu, 18 May 2023 03:08:29 -0700 Message-Id: <20230518100829.515143-1-sukrut.bellary@linux.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 smatch warning: drivers/misc/fastrpc.c:1926 fastrpc_req_mmap() error: double free of 'buf' In fastrpc_req_mmap() error path, the fastrpc buffer is freed in fastrpc_req_munmap_impl() if unmap is successful. But in the end, there is an unconditional call to fastrpc_buf_free(). So the above case triggers the double free of fastrpc buf. Fix this by avoiding the call to the second fastrpc_buf_free() if fastrpc_req_munmap_impl() is successful. 'err' is not updated as it needs to retain the err returned by qcom_scm_assign_mem(), which is the starting point of this error path. This is based on static analysis only. Compilation tested. Reviewed-by: Shuah Khan Signed-off-by: Sukrut Bellary --- drivers/misc/fastrpc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index f48466960f1b..1c3ab78f274f 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1921,7 +1921,10 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) return 0; err_assign: - fastrpc_req_munmap_impl(fl, buf); + if (!fastrpc_req_munmap_impl(fl, buf)) { + /* buf is freed */ + return err; + } err_invoke: fastrpc_buf_free(buf); -- 2.34.1