Received: by 10.223.185.116 with SMTP id b49csp2117615wrg; Thu, 22 Feb 2018 08:23:59 -0800 (PST) X-Google-Smtp-Source: AH8x226g+Zyr4hy04s/E1zz6J2pWZ6mG+Vvu+Q3Ap6IvYmr4OvYuAUMdHRpZ0WjH9thjr3Q8vpy2 X-Received: by 2002:a17:902:8c92:: with SMTP id t18-v6mr5083443plo.449.1519316638936; Thu, 22 Feb 2018 08:23:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519316638; cv=none; d=google.com; s=arc-20160816; b=AIQiGbCh+unJG4xsFJ+NnZ4hqBQ+//AO5gKjJau3R5CzWFYk3o5EP2yGH+CkBwuyUd dSoB4GdDUZLKEz9lSktojzpqxf955fkYCk3mePW8X4lX8+8ppsxDD7PiBTlzVkGYFyes hcdHPh0sQPSfbh2yqAnccrpb2f/y3YLA309umwdMZncPfdyLiu1QDADfpw1AlLPsShU8 WCq1FQ9Qh5iC7L7M/etqNb0aaWSUljBWm6f/K86ihSADAjUJVtkwtJEYyyATmjAXcFFS UkduT5/+F7drX0V0WNf7yzsSG0bUG3PBluUuj1s+DrTpWrR2S1g3w4qFQN7pM3piomH5 ApWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:organization:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Qpj5LHAEDMzukxK2NFsU3ytaH5qwcuWcyxFM+YvOMFw=; b=cxarvACKy+IW7LOVqr4PzYuzlEIoD8N369GKqqCGWLd1e+vcpMcPZUZrrVtKOQqK9t 94JhEfvLyKDdGyb06pXjP/32namYKDXiPVs3ZIt8F81lR+pk7hvzvKfFQHtZj7TP6UMH qEGltF5d3yhfyJd+Wf66ae54pyiUa2EXbOAK7donDJkKt3aKwA3q4eO1/06hUUfifxtP SpZD7qNA/QUV14cgBoaglRimMTYpgWZuwGx4dq42tznjdvJOjRcymnWsrXvSnsbjuYjL CyRfYV3V609TcYKKXRfQOdRFEk1YmPHzgHHdYlx+O/IM4u+NUluA24GYRKaq+HtiCHMk SOxw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9-v6si233687plp.425.2018.02.22.08.23.44; Thu, 22 Feb 2018 08:23:58 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933376AbeBVQUy (ORCPT + 99 others); Thu, 22 Feb 2018 11:20:54 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39614 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933134AbeBVQUv (ORCPT ); Thu, 22 Feb 2018 11:20:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FD9B8182D0C; Thu, 22 Feb 2018 16:20:50 +0000 (UTC) Received: from warthog.procyon.org.uk.com (ovpn-120-250.rdu2.redhat.com [10.10.120.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id 294FA2026987; Thu, 22 Feb 2018 16:20:48 +0000 (UTC) From: David Howells To: jmorris@namei.org Cc: dhowells@redhat.com, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Eric Biggers Subject: [PATCH 3/6] PKCS#7: fix direct verification of SignerInfo signature Date: Thu, 22 Feb 2018 16:20:47 +0000 Message-Id: <151931644754.27713.14995018428445770576.stgit@warthog.procyon.org.uk> Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 In-Reply-To: <151931642737.27713.5082532296556836948.stgit@warthog.procyon.org.uk> References: <151931642737.27713.5082532296556836948.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 22 Feb 2018 16:20:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 22 Feb 2018 16:20:50 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers If none of the certificates in a SignerInfo's certificate chain match a trusted key, nor is the last certificate signed by a trusted key, then pkcs7_validate_trust_one() tries to check whether the SignerInfo's signature was made directly by a trusted key. But, it actually fails to set the 'sig' variable correctly, so it actually verifies the last signature seen. That will only be the SignerInfo's signature if the certificate chain is empty; otherwise it will actually be the last certificate's signature. This is not by itself a security problem, since verifying any of the certificates in the chain should be sufficient to verify the SignerInfo. Still, it's not working as intended so it should be fixed. Fix it by setting 'sig' correctly for the direct verification case. Fixes: 757932e6da6d ("PKCS#7: Handle PKCS#7 messages that contain no X.509 certs") Signed-off-by: Eric Biggers Signed-off-by: David Howells --- crypto/asymmetric_keys/pkcs7_trust.c | 1 + 1 file changed, 1 insertion(+) diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c index 1f4e25f10049..598906b1e28d 100644 --- a/crypto/asymmetric_keys/pkcs7_trust.c +++ b/crypto/asymmetric_keys/pkcs7_trust.c @@ -106,6 +106,7 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7, pr_devel("sinfo %u: Direct signer is key %x\n", sinfo->index, key_serial(key)); x509 = NULL; + sig = sinfo->sig; goto matched; } if (PTR_ERR(key) != -ENOKEY)