From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AG47ELvGZQpwlUVtsgzYgv2ANMo8Dak1asey+DkW+zPwJwBUx5zwbN1mCffFWnzDG282BH6vUCPz ARC-Seal: i=1; a=rsa-sha256; t=1519676607; cv=none; d=google.com; s=arc-20160816; b=tFjaAKOi5RjNWecb+zNNDhdJmrB4nEXm7vdYN7pYfhc+fQPdLvoojcqiPMqls/Jegk p4vTtAdNrXEJk6E96OLLl2NCzGv9wPYfibT9P1jqRS9yFa5FpPQiS2Qtbg5DhnJ1/sQw A68eDuteiYBj8Wc8CmaS5zTK9ner0HyRYtoxrTjvQfVHpL0KnSTFWrDEYUXgwLO4ZDGi AHm+jaVjiUqZej+gQLbB8raGWTOiOtH7bwKU0RxsenwW1jo25XhlqkzIQbo9ES3CR322 FQbvfr4Gc2WKBgEy6ugi91W01CoA2HV6H/VVMNlr8QyV/OH9hx/5KfqaWFfQPF5DRe6l HXiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=HlRPxs2l5dGh96zvEGAK1/h1N2M4F1X1z5/om2eroXY=; b=IOOxejQK3PtvSgUnaKRF6gDlw79y9XH270vA3XbQCA0oS+vaMrCl9Mm6xV9VDJboIs 3OU+EggDvQ8YcyNV/9kFz5tUVYAxNDwtqxVE65wwepL4JDl9qTUg0XLkbX/3MJdW9NJi Cb34PLoqVMky1JIKagNDzXgtep3xYomPdS/0nHusvERIsLaspp+mOu1vojBfJbA0Jr3f p15+MTQswtOirRg4CJmlcd2+zHsgfTyUZYBw0+vqsw32SAkKdKoHp95r+DD7TD6v5Aaj H69ehRt2ltoAibP9fYTx9+jhH5vJpjpd4r5uW8pLBmEGNMPa+6FgZIXgjGP0O3Jo/ckN /CNg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 83.175.124.243 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 83.175.124.243 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1593496371074574553?= X-GMAIL-MSGID: =?utf-8?q?1593496418698961519?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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;