Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4428823imw; Tue, 19 Jul 2022 06:31:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sQHETmrJ8+G9ZDwpBreOGAmdklic1xMJ0Fmd4ZQnEHoU5cHl9Znkp2KfUHz1znCCAxD7Oo X-Received: by 2002:aa7:d80a:0:b0:43a:6f95:62a0 with SMTP id v10-20020aa7d80a000000b0043a6f9562a0mr42194736edq.284.1658237469079; Tue, 19 Jul 2022 06:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658237469; cv=none; d=google.com; s=arc-20160816; b=q+XHddVDbmmbgQ4JAD26xiGqQz4kUrUqPDXDAe2X3de7CCuySHpHlf6jhBBw13qsIZ P6Oh21Jine375/5m1WT2Vx114d0373RWGfl5snEpp+lAbCm+N+Z9utf1jk7xbmZEcoa5 dpMswDZpv2B9K5wPnnEiZ4JBK1oCjC9EQmhWfTkfyN9xNwOl/rg4eecURprHwiC1Ivc/ dpgwHjsqg8JEHPAfXks3+hi+1IP1tVYF5nnl/GWTJxFc4GvCLmN7pa0DsEORSQU1wX3P FovDd55wFuMGqYqV16CcIX9VdnAePysmf4DLjUTiyHqKwd7B/C2it1fLEe1A9NlY6QSO yWyA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6qHK4ozJ0fLb9ZAKvE/tx9It9eBmj8DE00INRnug2zI=; b=eVHf/ld3umCE43cIUQ2fdak7trDr6TAtJZC6uNABteBTF6ks82axzYRPbDNMWtkGwe mqBb0mvrbEdRuEmu/MYikXmtneqstKUi8S64zKQrHk6mMf24Z1Z1WKOXaiPxZeGX//Oi I+gjQv/npgTECc/1jIx6Sbl2XVI3D9hd6b6jqWmmFl6EaqydrwIWHP87DOSuKbmA2K23 Bq7mnsfV4/dIgDVVKAv8u6UqQJIxNOYTQq1M8LFwzdy/vl8Tt4R7VC1ymX1xZFrySHw4 0OprHKlgpSW0u5jXoaDN7kFKlElhxoYmn226sueZT43zqZskfctFFv1ZKTJD8CzEdNmN mplA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K21tQN5e; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp23-20020a1709073e1700b0072b3b8d31f8si22195505ejc.63.2022.07.19.06.30.44; Tue, 19 Jul 2022 06:31:09 -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=@linuxfoundation.org header.s=korg header.b=K21tQN5e; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239529AbiGSMVk (ORCPT + 99 others); Tue, 19 Jul 2022 08:21:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240007AbiGSMUL (ORCPT ); Tue, 19 Jul 2022 08:20:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D4F25A2F9; Tue, 19 Jul 2022 05:07:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 66DFD6165C; Tue, 19 Jul 2022 12:07:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 499A5C341C6; Tue, 19 Jul 2022 12:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232446; bh=hsMdpEFnoaS2cQ6HlPFwYe8QP9aAIs9OIjxUelmttBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K21tQN5eHAK/ySMC5h+y5dJKpeL9UfkzMWiAH5thbZ+4KsMKZG0NXWJCRdyZF6YBK EV3T+FAm8zTRSy6Kx5chHdj3wepz8fKG2529JiS9ujyfuwVOSvQ4mKYuaIarqK0odJ SsgoXwShjs/0Z5zYUbYBdIIE2GrjJl1Hpiop0hbM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Guozihua (Scott)" , Xiu Jianfeng , Mimi Zohar Subject: [PATCH 5.10 023/112] Revert "evm: Fix memleak in init_desc" Date: Tue, 19 Jul 2022 13:53:16 +0200 Message-Id: <20220719114628.248385487@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: Xiu Jianfeng commit 51dd64bb99e4478fc5280171acd8e1b529eadaf7 upstream. This reverts commit ccf11dbaa07b328fa469415c362d33459c140a37. Commit ccf11dbaa07b ("evm: Fix memleak in init_desc") said there is memleak in init_desc. That may be incorrect, as we can see, tmp_tfm is saved in one of the two global variables hmac_tfm or evm_tfm[hash_algo], then if init_desc is called next time, there is no need to alloc tfm again, so in the error path of kmalloc desc or crypto_shash_init(desc), It is not a problem without freeing tmp_tfm. And also that commit did not reset the global variable to NULL after freeing tmp_tfm and this makes *tfm a dangling pointer which may cause a UAF issue. Reported-by: Guozihua (Scott) Signed-off-by: Xiu Jianfeng Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/evm/evm_crypto.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) --- a/security/integrity/evm/evm_crypto.c +++ b/security/integrity/evm/evm_crypto.c @@ -73,7 +73,7 @@ static struct shash_desc *init_desc(char { long rc; const char *algo; - struct crypto_shash **tfm, *tmp_tfm = NULL; + struct crypto_shash **tfm, *tmp_tfm; struct shash_desc *desc; if (type == EVM_XATTR_HMAC) { @@ -118,16 +118,13 @@ unlock: alloc: desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm), GFP_KERNEL); - if (!desc) { - crypto_free_shash(tmp_tfm); + if (!desc) return ERR_PTR(-ENOMEM); - } desc->tfm = *tfm; rc = crypto_shash_init(desc); if (rc) { - crypto_free_shash(tmp_tfm); kfree(desc); return ERR_PTR(rc); }