Received: by 10.223.185.116 with SMTP id b49csp4192513wrg; Mon, 26 Feb 2018 12:55:59 -0800 (PST) X-Google-Smtp-Source: AH8x2245fsB0V2npwNKt/PYyYwiBoQigHC7IW0LaUOLFr7f3ZAP2p5CCnQUFTqmORW4bp4tvbMrj X-Received: by 10.98.71.3 with SMTP id u3mr11953711pfa.219.1519678559432; Mon, 26 Feb 2018 12:55:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519678559; cv=none; d=google.com; s=arc-20160816; b=DUmxk58xYZXZse3Jbm46cpvFNYQM9jWjocC3YP/MDKTlgz8raS3HPmoug2gI5wruFK JhCy8JEj+rltx6kzpOTboORufkWly1gYRlAexCKqsbl/YF5WdyiqyYYomEFDXWbuqh38 gpmu/TuVsayxhDLPJ9ZSe0XmIOCFIDBJLhW9HC8errWH2aEcoesYEdEZ2rdzDdGki+gU aNzJ1Uzm/XlMjubgzf7BIHIjPbKsqhGUe+FMRJpaiRaCEqvMiViRWqWkD+7Zc1/L/Dll /cUxHQ7VGxLZiInWqxi54BwKvQQ8aUe7f04Eb7yE6cxvWX/zFrDYTfkzvfNZyVlbwfld soNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HlRPxs2l5dGh96zvEGAK1/h1N2M4F1X1z5/om2eroXY=; b=sbIEwCN9yTH5DmZgZeeq3oly2UvoAwET2SXoSM4VUUmJNat6V4hiXQYU3SQLTFHfWw Lv/ia8f2rwSc2h2I0q6yLy442Jhq2m3Cg7NI84NYdbJKZ7mnTmMoMhCJqdKTYO5SYULx 2aNx21Ik+Eq7+QUmGsmquu+otE4ZmVvm4EP0K+UGf2DYQ4Cj15+RdL1D2Q3paEv0jZkK b3yrnYdzEBv4teXLaVhFCbeclDiaJoUOW1SpTqCb5BTD4bVVTawmDvFJEuHF3x+wEm4r 0HgZufQ2iQZBdtYdoGmnXH8z4uPzzjpTwHdrjt5f83eGZ2cjZxl75tLKk52lFUvnoIHV WPzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r22si5979612pgn.104.2018.02.26.12.55.43; Mon, 26 Feb 2018 12:55:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752670AbeBZUX3 (ORCPT + 99 others); Mon, 26 Feb 2018 15:23:29 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34796 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751448AbeBZUX0 (ORCPT ); Mon, 26 Feb 2018 15:23:26 -0500 Received: from localhost (clnet-b04-243.ikbnet.co.at [83.175.124.243]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1AAC0F1F; Mon, 26 Feb 2018 20:23:25 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , David Howells Subject: [PATCH 4.14 13/54] PKCS#7: fix certificate chain verification Date: Mon, 26 Feb 2018 21:21:50 +0100 Message-Id: <20180226202145.028369057@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180226202144.375869933@linuxfoundation.org> References: <20180226202144.375869933@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 971b42c038dc83e3327872d294fe7131bab152fc upstream. When pkcs7_verify_sig_chain() is building the certificate chain for a SignerInfo using the certificates in the PKCS#7 message, it is passing the wrong arguments to public_key_verify_signature(). Consequently, when the next certificate is supposed to be used to verify the previous certificate, the next certificate is actually used to verify itself. An attacker can use this bug to create a bogus certificate chain that has no cryptographic relationship between the beginning and end. Fortunately I couldn't quite find a way to use this to bypass the overall signature verification, though it comes very close. Here's the reasoning: due to the bug, every certificate in the chain beyond the first actually has to be self-signed (where "self-signed" here refers to the actual key and signature; an attacker might still manipulate the certificate fields such that the self_signed flag doesn't actually get set, and thus the chain doesn't end immediately). But to pass trust validation (pkcs7_validate_trust()), either the SignerInfo or one of the certificates has to actually be signed by a trusted key. Since only self-signed certificates can be added to the chain, the only way for an attacker to introduce a trusted signature is to include a self-signed trusted certificate. But, when pkcs7_validate_trust_one() reaches that certificate, instead of trying to verify the signature on that certificate, it will actually look up the corresponding trusted key, which will succeed, and then try to verify the *previous* certificate, which will fail. Thus, disaster is narrowly averted (as far as I could tell). Fixes: 6c2dc5ae4ab7 ("X.509: Extract signature digest and make self-signed cert checks earlier") Cc: # v4.7+ Signed-off-by: Eric Biggers Signed-off-by: David Howells Signed-off-by: Greg Kroah-Hartman --- crypto/asymmetric_keys/pkcs7_verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c @@ -273,7 +273,7 @@ static int pkcs7_verify_sig_chain(struct sinfo->index); return 0; } - ret = public_key_verify_signature(p->pub, p->sig); + ret = public_key_verify_signature(p->pub, x509->sig); if (ret < 0) return ret; x509->signer = p;