From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89404C54EBE for ; Mon, 16 Jan 2023 16:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233080AbjAPQZt (ORCPT ); Mon, 16 Jan 2023 11:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbjAPQZR (ORCPT ); Mon, 16 Jan 2023 11:25:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 511B22B291 for ; Mon, 16 Jan 2023 08:14:09 -0800 (PST) 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 E2BF76104D for ; Mon, 16 Jan 2023 16:14:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AD9FC433F0; Mon, 16 Jan 2023 16:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673885648; bh=fAWZzlzMdYPgr7mK+D6tuF+MN6mLhWTeK3l4++kkNCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jBpOQTjLEVjcnDrBn2wKgwonnoXjwKHThNJwjOPQ9vmRKhkl3TpljjQ2fS5tRJ7fv mMhnYpYGMQaRA1Sme7pyCSEu+KgKZO7+9G4GT9LU0iSVyzaWp4mTOB2g+Z9ZCQPQPT 8hOj4gdPYPQgi7wt6xphC0zjQSmEwjE9/ybl22d4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, GUO Zihua , Mimi Zohar , Sasha Levin Subject: [PATCH 5.4 132/658] integrity: Fix memory leakage in keyring allocation error path Date: Mon, 16 Jan 2023 16:43:40 +0100 Message-Id: <20230116154915.479450394@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230116154909.645460653@linuxfoundation.org> References: <20230116154909.645460653@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: GUO Zihua [ Upstream commit 39419ef7af0916cc3620ecf1ed42d29659109bf3 ] Key restriction is allocated in integrity_init_keyring(). However, if keyring allocation failed, it is not freed, causing memory leaks. Fixes: 2b6aa412ff23 ("KEYS: Use structure to capture key restriction function and data") Signed-off-by: GUO Zihua Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin --- security/integrity/digsig.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c index ea1aae3d07b3..12bae4714211 100644 --- a/security/integrity/digsig.c +++ b/security/integrity/digsig.c @@ -121,6 +121,7 @@ int __init integrity_init_keyring(const unsigned int id) { struct key_restriction *restriction; key_perm_t perm; + int ret; perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH; @@ -141,7 +142,10 @@ int __init integrity_init_keyring(const unsigned int id) perm |= KEY_USR_WRITE; out: - return __integrity_init_keyring(id, perm, restriction); + ret = __integrity_init_keyring(id, perm, restriction); + if (ret) + kfree(restriction); + return ret; } int __init integrity_add_key(const unsigned int id, const void *data, -- 2.35.1