Received: by 10.213.65.68 with SMTP id h4csp1124728imn; Thu, 22 Mar 2018 16:09:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELsYhXFDXKByjMOo806LD/DKHBP7VduMlGm5tgEyvyh3ukICQgslo4iZxGinzcbEJDWSZpsn X-Received: by 2002:a17:902:7790:: with SMTP id o16-v6mr2499431pll.106.1521760159477; Thu, 22 Mar 2018 16:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521760159; cv=none; d=google.com; s=arc-20160816; b=Lqn7XO19cICutgUjaXCHdF/tQ2guaQQsggZ1FLZqi6QXxLMK8M21P9amhrF6WMddE7 /ay6MHYap0PRY+rN3nnmYcBNtCBHap06xErq5voBLU/xZHQKdZpjdG818SIyEGiQE2oQ 62BIu+MXVWqNsQ6mOcnbsG8xrFD+x8HMJixZwhqN/nP3qkzvoAcM3nSt2WboRE2parRt 0iLGjCjGWKuoYPow8qXY+echd5QdH6zlMmORoms9HGPd14Nlq6o4hOK267tpWFgxxlj+ vjllNX8gWu/WSzIdoVsxPEaNuJTZhcJB8uXWaquU83CHFk4KNuOX7A/Jo9Zv59MGzCu9 FhRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject :arc-authentication-results; bh=7KHatcD2AHoNdtFept6+hcuSAHk+IsyqCjSYuaJupwQ=; b=EIWpP+NW06sCuOc96nrH+6lmhVB+06AM+8rhHzcctcS2ScDcAtjD0gLN98e699N7hz JmZh7RBz5vwBgRwUc7MlSgsWLdtS9CSz3rFqHZ+eo06fHnH9O394VIXWDOQcfIcRKMht nukSpMrUs/nJoHyCttGeqKVamzqyi8PkM0mdZAzaZtnhno0BhZs5jeSAJ0a6A7zqj94L L1+9ANYB+T32oBpDGf5d8bBaH5ZxmhOX6Tvv8mV17Udf+BCZg1xs35M1k30msNz0AeHW OBal8IM/ckHHPmdiEENMFOEEpAU8eA6Itk2H1W3v+KDfMhwsyNoPB568gI/3yoRu0dC0 TERQ== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si7120529plj.247.2018.03.22.16.09.04; Thu, 22 Mar 2018 16:09:19 -0700 (PDT) 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751831AbeCVXIM (ORCPT + 99 others); Thu, 22 Mar 2018 19:08:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54600 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbeCVXIJ (ORCPT ); Thu, 22 Mar 2018 19:08:09 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2MN7npn013576 for ; Thu, 22 Mar 2018 19:08:09 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gvkhjd2m2-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 22 Mar 2018 19:08:09 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 22 Mar 2018 23:08:06 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 22 Mar 2018 23:08:01 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2MN812k58065012; Thu, 22 Mar 2018 23:08:01 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21C2111C04A; Thu, 22 Mar 2018 23:00:30 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 329DB11C054; Thu, 22 Mar 2018 23:00:28 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.103.4]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 22 Mar 2018 23:00:28 +0000 (GMT) Subject: Re: [PATCH v6 03/12] PKCS#7: Introduce pkcs7_get_digest() From: Mimi Zohar To: Thiago Jung Bauermann , linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , David Howells , David Woodhouse , Jessica Yu , Herbert Xu , "David S. Miller" , "AKASHI, Takahiro" Date: Thu, 22 Mar 2018 19:07:58 -0400 In-Reply-To: <20180316203837.10174-4-bauerman@linux.vnet.ibm.com> References: <20180316203837.10174-1-bauerman@linux.vnet.ibm.com> <20180316203837.10174-4-bauerman@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 18032223-0040-0000-0000-000004445D51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032223-0041-0000-0000-000020E787EA Message-Id: <1521760078.3848.301.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-22_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803220258 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-03-16 at 17:38 -0300, Thiago Jung Bauermann wrote: > IMA will need to access the digest of the PKCS7 message (as calculated by > the kernel) before the signature is verified, so introduce > pkcs7_get_digest() for that purpose. > > Also, modify pkcs7_digest() to detect when the digest was already > calculated so that it doesn't have to do redundant work. Verifying that > sinfo->sig->digest isn't NULL is sufficient because both places which > allocate sinfo->sig (pkcs7_parse_message() and pkcs7_note_signed_info()) > use kzalloc() so sig->digest is always initialized to zero. > > Signed-off-by: Thiago Jung Bauermann > Cc: David Howells > Cc: Herbert Xu > Cc: "David S. Miller" Reviewed-by: Mimi Zohar > --- > crypto/asymmetric_keys/pkcs7_verify.c | 25 +++++++++++++++++++++++++ > include/crypto/pkcs7.h | 3 +++ > 2 files changed, 28 insertions(+) > > diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c > index 39e6de0c2761..bd02360f8be5 100644 > --- a/crypto/asymmetric_keys/pkcs7_verify.c > +++ b/crypto/asymmetric_keys/pkcs7_verify.c > @@ -33,6 +33,10 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, > > kenter(",%u,%s", sinfo->index, sinfo->sig->hash_algo); > > + /* The digest was calculated already. */ > + if (sig->digest) > + return 0; > + > if (!sinfo->sig->hash_algo) > return -ENOPKG; > > @@ -122,6 +126,27 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, > return ret; > } > > +int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u8 *len) > +{ > + struct pkcs7_signed_info *sinfo = pkcs7->signed_infos; > + int ret; > + > + /* > + * This function doesn't support messages with more than one signature. > + */ > + if (sinfo == NULL || sinfo->next != NULL) > + return -EBADMSG; > + > + ret = pkcs7_digest(pkcs7, sinfo); > + if (ret) > + return ret; > + > + *buf = sinfo->sig->digest; > + *len = sinfo->sig->digest_size; > + > + return 0; > +} > + > /* > * Find the key (X.509 certificate) to use to verify a PKCS#7 message. PKCS#7 > * uses the issuer's name and the issuing certificate serial number for > diff --git a/include/crypto/pkcs7.h b/include/crypto/pkcs7.h > index 6f51d0cb6d12..cfaea9c37f4a 100644 > --- a/include/crypto/pkcs7.h > +++ b/include/crypto/pkcs7.h > @@ -46,4 +46,7 @@ extern int pkcs7_verify(struct pkcs7_message *pkcs7, > extern int pkcs7_supply_detached_data(struct pkcs7_message *pkcs7, > const void *data, size_t datalen); > > +extern int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, > + u8 *len); > + > #endif /* _CRYPTO_PKCS7_H */ >