Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6010331pxb; Mon, 14 Feb 2022 13:04:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGJSDKEaKwwIS2Zj0jMUHbn/QO29rtnx4l/La5YTJhun2ECeAKj/qjJdGK7GubxiA5X8TU X-Received: by 2002:a17:902:7441:: with SMTP id e1mr672354plt.71.1644872657686; Mon, 14 Feb 2022 13:04:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644872657; cv=none; d=google.com; s=arc-20160816; b=aoQVcCqOXtw/NMjSZHzL/rIcpEUy1diPMYgV8umOImekD6oKjQYLiJjzZKJJRhWFnj 70p4gu7GzEkAzrTdfCuOR4fEY20k6nnP1S20B/CsWtOnB6V+XlZFcMpmEcryOt9M62Rr XOu8nMOROQBRcy9Rq0hFEEcPDQjo+D3vEh64WHX6yk7R9p0rwoyNC/HKA8G5cD4wVdub DrFa5RQyGgPVFCPdomJBGrmOnVlyr4hX3C8HoXvA21xyrVRq8gj5+e3ygu+wJr7qqfor +MraTUJI3CASzKz7Otcxx/rRIi6PkHm6iA8CiVXEdKW7bQJS82D80HeqKcFgmHAew2f9 FXkQ== 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=p2LIU8+dNaKVt04TovipeNaT5GGjtZp0HdUw1UhhCro=; b=aPhPrdBoCpOQ3qRVteM1SSSEMwmIG+al36F1BalrZkbgWIR7TPT66szADuOgGgj+7B SL/TpgBq8SaXKGgd/ukeHCnhwVfn3WmfseUB9cAbXPb55aADCB/5B9e+IjlPEG3JK9ka Ko4EpvUmOHYlEsmHjxFWzcA99A243DL4W8fTMup3uMoLXWdpCycl6yT+N5V9Dx1h7UPI 0yQI4y3MiJJun1PvH0zunqtAMTYlfy5hKTJj6ilvF7sLVEpldYIf+gyJYiG+bq9FdGh7 r6b/Vx9tP5D0sP6NtQzjoHIJcTMrYfu563BkGRnAmCVpjHFDpWxP21ZIerJYngpvCjPE md6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HTDb9TUu; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 196si770489pgb.133.2022.02.14.13.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:04:17 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HTDb9TUu; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D1C151FC413; Mon, 14 Feb 2022 12:26:24 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344506AbiBNKAI (ORCPT + 99 others); Mon, 14 Feb 2022 05:00:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345126AbiBNJ4g (ORCPT ); Mon, 14 Feb 2022 04:56:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E899A811B2; Mon, 14 Feb 2022 01:45:12 -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 8688B61277; Mon, 14 Feb 2022 09:45:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EEBAC340E9; Mon, 14 Feb 2022 09:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831912; bh=LBylFngLp5Sc0TB3vzfnAJqZtAbcj0oRjimFAAhmYCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTDb9TUuq6kKEtApNkdcfedol05xJdpjBQ2ZVvGmM5065pQPrfbO9Yz3QLCiB9F1T +2seTUEaA6BdmrakuqbrC0h4XbUWcBZ5MSqHKrCMb6YBN0KrBn0UXvjaD8E0xLHXwn Z2me1cOut+L4rpci96xEd9XGhwXaFr4WLXfLgnoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Stefan Berger , Tianjia Zhang , Mimi Zohar Subject: [PATCH 5.15 002/172] ima: fix reference leak in asymmetric_verify() Date: Mon, 14 Feb 2022 10:24:20 +0100 Message-Id: <20220214092506.441904458@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092506.354292783@linuxfoundation.org> References: <20220214092506.354292783@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 From: Eric Biggers commit 926fd9f23b27ca6587492c3f58f4c7f4cd01dad5 upstream. Don't leak a reference to the key if its algorithm is unknown. Fixes: 947d70597236 ("ima: Support EC keys for signature verification") Cc: # v5.13+ Signed-off-by: Eric Biggers Reviewed-by: Stefan Berger Reviewed-by: Tianjia Zhang Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/digsig_asymmetric.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/security/integrity/digsig_asymmetric.c +++ b/security/integrity/digsig_asymmetric.c @@ -109,22 +109,25 @@ int asymmetric_verify(struct key *keyrin pk = asymmetric_key_public_key(key); pks.pkey_algo = pk->pkey_algo; - if (!strcmp(pk->pkey_algo, "rsa")) + if (!strcmp(pk->pkey_algo, "rsa")) { pks.encoding = "pkcs1"; - else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) + } else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) { /* edcsa-nist-p192 etc. */ pks.encoding = "x962"; - else if (!strcmp(pk->pkey_algo, "ecrdsa") || - !strcmp(pk->pkey_algo, "sm2")) + } else if (!strcmp(pk->pkey_algo, "ecrdsa") || + !strcmp(pk->pkey_algo, "sm2")) { pks.encoding = "raw"; - else - return -ENOPKG; + } else { + ret = -ENOPKG; + goto out; + } pks.digest = (u8 *)data; pks.digest_size = datalen; pks.s = hdr->sig; pks.s_size = siglen; ret = verify_signature(key, &pks); +out: key_put(key); pr_debug("%s() = %d\n", __func__, ret); return ret;