Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4446170imw; Tue, 19 Jul 2022 06:48:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tK6ZkJxLmUl5BWMpkp9ayBQhPxHM45B6hpAzcHrxDB2yytxWdQhWV60Zf8fNG+385grAGd X-Received: by 2002:a17:907:7388:b0:72b:9be1:e32d with SMTP id er8-20020a170907738800b0072b9be1e32dmr29983536ejc.611.1658238527836; Tue, 19 Jul 2022 06:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238527; cv=none; d=google.com; s=arc-20160816; b=NHiFkfzz1yPwGYPnc1P8XVDh3IBv79HK6/OKLzemkVVqSWrsLs4kkhmGjZ/1LFEppk FH4ux3ZKzQxLTBQcqtkYmcC+h2WSW8Y/cQ4kuCKtvebmr1GsQDabPeD4uj2jxKeBxBD4 du8E+c6AkUnrC4taews1BzJ3/EbKwHSvo18+B6XfntdZOlanW9qVbKfRmpWp86GT7NUX 6tjNEqXnYu06G4ihh/9C3kh+QR/eh1bN40lcHK1oBnkkbY9tR8rh1pl/4UAyiEcyETLB GKKTCyihoGYlTzhzONnSjybf10UrckyvHc6wZHfE6FE/9/crUMXvQXj5/czwb0vf66tH Jtpg== 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=McZPxC54v1rBapQ1vjz44Cnqtbs38SAKxb3p5zG1Ki8=; b=cZrryRhM+oXyExKHFXHMK2QJCYDpTCGy+9HxbJVI2EU2+8yfEb13y4gLPRPWmiFK6g +xcBFi3MIi67CZ7L/Upv1E1SgCQrs4DYP6+FJbw7+m75Gc4hbfZhnf+TBMpy5+geV1Mm +zDdUZY97BqdQFUftmlDjcZVtmgPF1OWpc8DdBqSAaxPy6yzQ/ZsBfKMNKAPXlp9wG5f JAQkV7fJ4jLdUl1kqQxrdgmYLK5H1h5NWWomKFkh8SkIGv8o0RpA0WBg6ssL4G0hT9kr tV3m7ILrEPdA7gyuCc38UyH/qBuQYeST3tCCFFh38wp1I8/wr2upgiDDEjsw3dc5TdCj GT6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z9IfqoiA; 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 dx20-20020a170906a85400b0072b3b4f015csi16657742ejb.311.2022.07.19.06.48.23; Tue, 19 Jul 2022 06:48:47 -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=Z9IfqoiA; 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 S237590AbiGSMKM (ORCPT + 99 others); Tue, 19 Jul 2022 08:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238521AbiGSMIv (ORCPT ); Tue, 19 Jul 2022 08:08:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55B6345F63; Tue, 19 Jul 2022 05:01:52 -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 ams.source.kernel.org (Postfix) with ESMTPS id CCE8FB81A8F; Tue, 19 Jul 2022 12:01:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28CC0C341C6; Tue, 19 Jul 2022 12:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232109; bh=Z1JtSfxrx09o6ta6fOCcZnqAzuj3UPKp2mD7YWnzRFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z9IfqoiAHH3fPvC3DUSEL65ceQzRkO8d5mYxkwlniNbY94/6gs1NIQXPTUf9uYmcv hnNSEi+NApCn7xUWEmX601wp/4Mx+ukisg9CR4EZebvQ0/HtAuK0LxtfxLIqEmy0jh b2Xy+14AoYpXSg0LEukh2vnPijSJNmSXLPKAvkYM= 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.4 16/71] Revert "evm: Fix memleak in init_desc" Date: Tue, 19 Jul 2022 13:53:39 +0200 Message-Id: <20220719114553.824287941@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114552.477018590@linuxfoundation.org> References: <20220719114552.477018590@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 @@ -75,7 +75,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) { @@ -120,16 +120,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); }