Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp171453pxu; Thu, 7 Jan 2021 01:30:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwezTkeEwXTmbo7ZYzVKQ7egqh3qXVtVZYYwAVRAtcFOyxsYhMdV65NFCkXi5uoelK8PqZS X-Received: by 2002:a17:906:c82c:: with SMTP id dd12mr5769090ejb.66.1610011844705; Thu, 07 Jan 2021 01:30:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610011844; cv=none; d=google.com; s=arc-20160816; b=k6uc9iUqHOhDw6xtX4o/3ZViFsaJr9hzU6U5XaY2gxsTa5/oWQ1dt00G8yjw8zq46H KowltzQ+T9xmVa8Ke+YYO5wsbd4Crf5ahMVjYBkvdspR3tPHOm8YitdCkmAdvtna2eVr ozdZOgzMIjoqySasNXky4AU6OJUq7TdZcWNOJgswlcPJQlSd7sw4yCmTmnKmBbquOZk/ VXJ+5JcMApDwcKNPCQR+53OdyJkEPrwebxiP8TcR94Ai43dQrbJ04SwiDnNIjEdg+eLF Q2hGdOgNqk+iqN/FjcE2rYqwgHEN4jgkfp+xAChq8KtNuPS466hPsZAjZTlv4b6up6+b r+vQ== 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; bh=ifT+mO9X/QGggvsK3N41aEK4VhPgX1ZywGhDkJl1IM8=; b=mD4z4mZQlYdUICOZOG0YtUKo9YieFfq6Ai8YezkJo2mH0sTyaBiRIfS6wTJ7JttrXG K7h4xS9uS7+nA113pmf1LwgAnUwPpvMADvCkHLPouLGTMV+O2+uE+nhF1xwYz/ev8h/T 5/riVikR1iKcXVPgxp7RLzNdwwTveYTNAiT4del+GAIw2MwMlbZY+MVMSCIaL7VoiBF6 /d3GWpEdiMusyVsdDz4o5zCS+njV2FVLVX2H8EIYT9WDH6IbWtLHZm2BHWJNQ2GrTtZ7 QhgKUgS9PdbdQ+MOwFgeWw9ukTY7VUx1eajlaxFwWETFGvyQBLld1FI912OxXtfzpBtv TyXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si2148800ejd.240.2021.01.07.01.30.24; Thu, 07 Jan 2021 01:30:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbhAGJ3k (ORCPT + 99 others); Thu, 7 Jan 2021 04:29:40 -0500 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:51345 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726326AbhAGJ3j (ORCPT ); Thu, 7 Jan 2021 04:29:39 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0UKze1KK_1610011735; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0UKze1KK_1610011735) by smtp.aliyun-inc.com(127.0.0.1); Thu, 07 Jan 2021 17:28:55 +0800 From: Tianjia Zhang To: David Howells , Herbert Xu , "David S. Miller" , Gilad Ben-Yossef , Tobias Markus , Tee Hao Wei , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tianjia Zhang Subject: [PATCH] X.509: Fix crash caused by NULL pointer Date: Thu, 7 Jan 2021 17:28:55 +0800 Message-Id: <20210107092855.76093-1-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.3.ge56e4f7 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On the following call path, `sig->pkey_algo` is not assigned in asymmetric_key_verify_signature(), which causes runtime crash in public_key_verify_signature(). keyctl_pkey_verify asymmetric_key_verify_signature verify_signature public_key_verify_signature This patch simply check this situation and fixes the crash caused by NULL pointer. Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification") Cc: stable@vger.kernel.org # v5.10+ Reported-by: Tobias Markus Signed-off-by: Tianjia Zhang --- crypto/asymmetric_keys/public_key.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index 8892908ad58c..788a4ba1e2e7 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -356,7 +356,8 @@ int public_key_verify_signature(const struct public_key *pkey, if (ret) goto error_free_key; - if (strcmp(sig->pkey_algo, "sm2") == 0 && sig->data_size) { + if (sig->pkey_algo && strcmp(sig->pkey_algo, "sm2") == 0 && + sig->data_size) { ret = cert_sig_digest_update(sig, tfm); if (ret) goto error_free_key; -- 2.19.1.3.ge56e4f7