Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3181837pxb; Tue, 12 Jan 2021 08:15:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtq30l8fGQqGfoCXCO0/Zc4wXK8EVLVc6/KQ6mWmyg/yMT6whB0Q0wi5JGJN6HUBZnETlN X-Received: by 2002:a17:906:415a:: with SMTP id l26mr1268170ejk.463.1610468144614; Tue, 12 Jan 2021 08:15:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610468144; cv=none; d=google.com; s=arc-20160816; b=TvPxflUOm2KmxhMm2WThdO4ThhNp4wekWBIYaFWqy1GJP0o+YtWTFmz/NTs4AhANg1 MhyJEatBrxvAZpw+R/Um2FqJp5FpQJ917OdpkTg0w0TjrFXa2tHnCXP6xgIz55uGnPB8 zkyAUUxpbajwgcC4uUuuYf1tAp8Mknw41rGamfNjWSFw42PYOerGoqKvZsAwKdCsl9bV qu5kTLFPDMCmVMJUDbjpgCaVUfNvvLljIwhCmaAIrIyO8E9FdCkqWQnqJnPDaCvxZDox B8ZSiXvx/It9Rb9wV8+o9rD9L8MiBa8uyi89ZPzbyoZfmmLh7HfXz8KAMG0/orUNEgD1 lPpw== 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:dkim-signature; bh=7GrmVz3g5PnC6MejB1/FJv7gDiKaAZjfigOkKnsP7RY=; b=m55MnpT2uTFqKz+iEia5t9Bz6DWzXyMhL6G3BWSwdSfThbf6RdQ/hYlUn32LMINOk4 sVIVsqP+XxDEPnsmc3iahI4+Ee2m80n/pmgc603qZcJMzaoZz1egU0wQd7Dk6V98og3e 77LGAg3xEZh9y5HkK7t+M/0hGbnd+upodlVPZs+73nEHbXwVzZ6O3PLFRs+eebHePt4h n1CNyTrduwce1z98AuG3u0Hpp5zyvvQjYtRIeKlEyTXR+1BRC+NvlFyEdDzGZzwLQ7au kfysFVlL9y+MZVuNqdrAYLbZThLW1y87jURYmQ9DJNdoB5slXyIvP26hCkPdvWoChjME DlNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gDfpJjm2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si1286547ejf.90.2021.01.12.08.15.24; Tue, 12 Jan 2021 08:15: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gDfpJjm2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387818AbhALQMy (ORCPT + 99 others); Tue, 12 Jan 2021 11:12:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21844 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391926AbhALQMs (ORCPT ); Tue, 12 Jan 2021 11:12:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610467882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7GrmVz3g5PnC6MejB1/FJv7gDiKaAZjfigOkKnsP7RY=; b=gDfpJjm2Wic4KapOMGhAGjFavNgHiW9aV8jDp7SOAD3V3wjSJIsswtntqhiHKc+GI6STFH aho4xLMjGqUi1GUPdnKlARYEuNLvMPrnkIHu3Y/BO2+eV94x8BZShGe7Selq8gnnmWjAOZ YzPEm6QWYVARE0fdmgzy/P+rPXpED+4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-579-NVLciomDN8y4JMLnP10Wfw-1; Tue, 12 Jan 2021 11:11:20 -0500 X-MC-Unique: NVLciomDN8y4JMLnP10Wfw-1 Received: by mail-wr1-f69.google.com with SMTP id r8so1342193wro.22 for ; Tue, 12 Jan 2021 08:11:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7GrmVz3g5PnC6MejB1/FJv7gDiKaAZjfigOkKnsP7RY=; b=cvP4Dew2/Qf3G+cX7VQtcBhcn5OmBExMXiRQCmiBtHvVb1sTsDlUQrKjQ9Zli0E2g6 MR49DYGmi4CMsPEcTWOKeUCBvXrIRTRBvpM4dC3quqq1wYLnaQpaJ2OdBN2fzyGMYhdM Nt7kg0oYYdwJqRkipUthnKRPT8EIj7rDSTOvdUB2ZDqlNMWcfeIAm5JdKTNuA61n8yWV MPNKnOhfcvpdNhGxffNw6oojcWXjf7TN4xzlzQh7DwZrnT6iCqaPFt2lonkkkCSRZk1G jiS/m8yYYPN2C4J0dPnR2qQjmXx4t+hHz+9ULSyv4njS2GfOLepgATouJXlvyvM0UYzv 3YPA== X-Gm-Message-State: AOAM532xkewUrWxoJ6GhGXgybldhYkL9dxRAfDhNi+cp2q5LX2GG3LzF Nhkuv+c0H2/s6keQMCQx5SfuinhmEbv+1UYjXbbfrpnBrTFFJF/Oo+tN/GtJh9DdB8pSB1B40N/ 1pL6JVto7W0tAo2uaj/FH6RYw X-Received: by 2002:a1c:7d94:: with SMTP id y142mr4317087wmc.105.1610467879455; Tue, 12 Jan 2021 08:11:19 -0800 (PST) X-Received: by 2002:a1c:7d94:: with SMTP id y142mr4317069wmc.105.1610467879236; Tue, 12 Jan 2021 08:11:19 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id e15sm5765658wrx.86.2021.01.12.08.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 08:11:18 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 2A2DF180322; Tue, 12 Jan 2021 17:11:17 +0100 (CET) From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= To: David Howells , Herbert Xu , "David S. Miller" Cc: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Tianjia Zhang , Gilad Ben-Yossef , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] crypto: public_key: check that pkey_algo is non-NULL before passing it to strcmp() Date: Tue, 12 Jan 2021 17:10:44 +0100 Message-Id: <20210112161044.3101-1-toke@redhat.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org When public_key_verify_signature() is called from asymmetric_key_verify_signature(), the pkey_algo field of struct public_key_signature will be NULL, which causes a NULL pointer dereference in the strcmp() check. Fix this by adding a NULL check. One visible manifestation of this is that userspace programs (such as the 'iwd' WiFi daemon) will be killed when trying to verify a TLS key using the keyctl(2) interface. Cc: stable@vger.kernel.org Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification") Signed-off-by: Toke Høiland-Jørgensen --- crypto/asymmetric_keys/public_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index 8892908ad58c..35b09e95a870 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c @@ -356,7 +356,7 @@ 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.30.0