Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp1126196imk; Sun, 3 Jul 2022 18:10:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vnd4x+cpfIsabRDxQhVufl7WE4ilngf78zVKUNqzSlTxT4InpKtSnM4YidZmKGEaU+aXxy X-Received: by 2002:a17:907:8a25:b0:726:c9f2:2f5e with SMTP id sc37-20020a1709078a2500b00726c9f22f5emr25518900ejc.286.1656897035850; Sun, 03 Jul 2022 18:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656897035; cv=none; d=google.com; s=arc-20160816; b=NmNmo+pAef0/jSvWVHfCXqs3GOXnGxNCQDoQnWosTGBItXxzdPRchEis9pKNRuXew0 eH87uhH2Vcr8LAwT3yOg+IXRMwjRWayfq6SdRB/FmfsGV7+RC573/Pol8ITlWAMDUa+K Vl2QMaUInDS9MrNtqIium7Znwj0zsFajPHml09048vowTQO89tnK9RsLVAbD/s7EqP19 KMSlrWqCXUYvHskhB5zTJ1Z7+Ckai5d5i/tXaLZd67zOAF1jzjpXfEmeFVEthiCNB9zD YHlv6oCrMxKkZQD+WF/lS1EIpVIdWEiDkpT6yIw1PfToUolAqkoVX1rHJkK2kqL7qHZW AtzQ== 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:dkim-signature; bh=jzC9qteMihzoRDzWXOyq7ds47NBYNyeOA6hb71U3VdU=; b=H0RUUJuMeRyq8AKtePB1CI5og/HmAquHG0aRUUgaj+j/HCSSgcC+FElDTEZo3DGVym GshnXGILECSQl8D2x3rORXaIjXPI0tzFubCdOtLAz+wcTsZmPx9OuPS/2LmgXttBlPA7 Lw2qLDvnY/9To3TdVDNsnrx1nM8bg5DrBWxQVYHnV35xCNlYIoXFQyCwQk4MzaMLb2Z9 mOJV+qz6Mh02zA29jjFo8+O4rCkue8hdyEKrnMmy2pMHi34zulNvcb7sn6kxUW/sy71W qUhFz1FE9JwyrLunN8crwK0fb9tA61QH+/8iOOCA+o7NGUYupB/MmgLSvmgD2BChMSnc +TNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=H+NEAKie; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr14-20020a170907720e00b0071576eb9e6bsi16892994ejc.211.2022.07.03.18.10.09; Sun, 03 Jul 2022 18:10:35 -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; dkim=pass header.i=@163.com header.s=s110527 header.b=H+NEAKie; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbiGDBAb (ORCPT + 99 others); Sun, 3 Jul 2022 21:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiGDBAb (ORCPT ); Sun, 3 Jul 2022 21:00:31 -0400 Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF4FD25F6; Sun, 3 Jul 2022 18:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=jzC9q teMihzoRDzWXOyq7ds47NBYNyeOA6hb71U3VdU=; b=H+NEAKielNlgZocGG050p 9TuCgpW1y+pR3a0/uYx6PObBwhMEPwuaNCaXE6OTAouFTHxt88+Ki7X6A3Q9EjNI B2VSr6BmT19bngDjQLbd3w/WsCPFGYNygVYWbIYDCgtk8BggsJCdseaatnI7YGSc 6PlwnkoswJdGSV6DpbXrEI= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp2 (Coremail) with SMTP id GtxpCgC3vw95O8Ji6QXPNA--.21733S4; Mon, 04 Jul 2022 09:00:07 +0800 (CST) From: Jianglei Nie To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] ima/evm: Fix potential memory leak in ima_init_crypto() Date: Mon, 4 Jul 2022 08:59:32 +0800 Message-Id: <20220704005932.2217025-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgC3vw95O8Ji6QXPNA--.21733S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gw13Xw47KF1DAFWxuF1ftFb_yoWfuwbE93 90934xX347Za1kX3yjvFZ2vrW0grWkCFy0gry2ywnrCa45Ar45WF17JFs3J34UArWUJr4q gws8JFW2ywnFqjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREsXoDUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiFRc0jF5mLnq5LgAAsB X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 ima_init_crypto() allocates a memory chunk for "ima_algo_array" with kcalloc(). When some errors occur, the function jumps to "out_array" and releases the "ima_algo_array[i].tfm". But "ima_algo_array" is not released, which will lead to a memory leak. We can release the ima_algo_array with kfree() when some errors occur to fix the memory leak. Signed-off-by: Jianglei Nie --- security/integrity/ima/ima_crypto.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index a7206cc1d7d1..64499056648a 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -205,6 +205,7 @@ int __init ima_init_crypto(void) crypto_free_shash(ima_algo_array[i].tfm); } + kfree(ima_algo_array); out: crypto_free_shash(ima_shash_tfm); return rc; -- 2.25.1