Received: by 10.213.65.68 with SMTP id h4csp1324913imn; Mon, 26 Mar 2018 05:31:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELszeXKbV6r5frY8lJ5PH6qZpuHtWk7CoNi4bxxwj029yEvJ7ALB9Sm+se5N+9pJSK8D3+cl X-Received: by 10.101.102.24 with SMTP id w24mr27302116pgv.326.1522067478000; Mon, 26 Mar 2018 05:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522067477; cv=none; d=google.com; s=arc-20160816; b=TBAfiYcohuY+MlPUnPkMhjmXC9cSKpu9sywoEC4qdquQ0VTxDYhbtgGr1L5tqvmdV7 l/0HPvUJWSLMPcP8sEOld64x7SwmcQShxUb/h6XVM+iHv1f8EclxTmBABVYNsp2VEbLq f4cDBlqoTtdI0T91eVTEwD2HSROoEqsCI7mBRXHns4kuUTzwNaMOPasMCgZdju/88KLC ZwRfA9Ym/UYeCGdEgEtOMCRAl3g71ESRgXeElxiTOlDUhn97fPLxEfYGGF1gAHc2+1tt cNOxSK7CI8KVOfvJEsenFizfJi05XZkXKCathqCHxIlqxkUjU3sCZsj5rl97VrhGkdJC ST7A== 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=2RXM2f+RUeBI3F1X6Ye9v9mYfIvTPBU6WjIet4KIvGs=; b=FWAybgstBc44qlZkYTQcG/zfH25mgbxyXO6rZ/se4+g+lgr1ktMTe9rVHN/Dd6QFZF 1oaTU82KegGsdIkAKqrNd3dIcK3JT4B+yrbrD6PeUu/8JN1dWSXryh9f9RGwmcEtgkCF A5qppmILpFqrbd/uP5zYLaJkZ3lYCee0Ly1pMEczwTt9JQpcr9YKedAQt7rQA3PrFfYb ykhSCZJ2zslK3Pi+JjcNalsvgmVaO1R9fqYVjXdWMyIXnZ0zsYKdUrmCSnoclewzcvMH zJTpAMlVZbKwb5knA+c0y8XxhB6/grXTr77MtTTm/J8S9n3/9KBz5jVCwPa0F/0SbwGH A98A== 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 i3-v6si14788223pli.274.2018.03.26.05.31.01; Mon, 26 Mar 2018 05:31:17 -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 S1752026AbeCZM3v (ORCPT + 99 others); Mon, 26 Mar 2018 08:29:51 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57644 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751141AbeCZM3t (ORCPT ); Mon, 26 Mar 2018 08:29:49 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2QCTTWn142071 for ; Mon, 26 Mar 2018 08:29:48 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 2gy0mw0pe4-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Mon, 26 Mar 2018 08:29:48 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Mar 2018 13:29:45 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 26 Mar 2018 13:29:40 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2QCTegT58654804; Mon, 26 Mar 2018 12:29:40 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 053C252043; Mon, 26 Mar 2018 12:20:58 +0100 (BST) Received: from localhost.localdomain (unknown [9.80.103.80]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 124305203F; Mon, 26 Mar 2018 12:20:55 +0100 (BST) Subject: Re: [PATCH v6 12/12] ima: Write modsig to the measurement list 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: Mon, 26 Mar 2018 08:29:37 -0400 In-Reply-To: <20180316203837.10174-13-bauerman@linux.vnet.ibm.com> References: <20180316203837.10174-1-bauerman@linux.vnet.ibm.com> <20180316203837.10174-13-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: 18032612-0020-0000-0000-000004096024 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032612-0021-0000-0000-0000429D8F29 Message-Id: <1522067377.3541.47.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-26_06:,, 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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803260136 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: > Define new "d-sig" template field which holds the digest that is expected > to match the one contained in the modsig. > > Also add modsig support to the "sig" template field, allowing the the > contents of the modsig to be included in the measurement list. Although including the appended signature in the template data doesn't make sense on its own, as the file digest (without the appended signature) is needed to validate the appended signature, defining a new template field and its usage should be independent of other changes. Mimi > > Suggested-by: Mimi Zohar > Signed-off-by: Thiago Jung Bauermann > --- > Documentation/security/IMA-templates.rst | 5 ++++ > security/integrity/ima/ima_template.c | 4 ++- > security/integrity/ima/ima_template_lib.c | 47 +++++++++++++++++++++++++++++-- > security/integrity/ima/ima_template_lib.h | 2 ++ > 4 files changed, 55 insertions(+), 3 deletions(-) > > diff --git a/Documentation/security/IMA-templates.rst b/Documentation/security/IMA-templates.rst > index 2cd0e273cc9a..f2a0f4225857 100644 > --- a/Documentation/security/IMA-templates.rst > +++ b/Documentation/security/IMA-templates.rst > @@ -68,6 +68,11 @@ descriptors by adding their identifier to the format string > - 'd-ng': the digest of the event, calculated with an arbitrary hash > algorithm (field format: [:]digest, where the digest > prefix is shown only if the hash algorithm is not SHA1 or MD5); > + - 'd-sig': the digest of the event for files that have an appended modsig. This > + field is calculated without including the modsig and thus will differ from > + the total digest of the file, but it is what should match the digest > + contained in the modsig (if it doesn't, the signature is invalid). It is > + shown in the same format as 'd-ng'; > - 'n-ng': the name of the event, without size limitations; > - 'sig': the file signature. > > diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c > index 30db39b23804..36fc32f538b5 100644 > --- a/security/integrity/ima/ima_template.c > +++ b/security/integrity/ima/ima_template.c > @@ -43,8 +43,10 @@ static struct ima_template_field supported_fields[] = { > .field_show = ima_show_template_string}, > {.field_id = "sig", .field_init = ima_eventsig_init, > .field_show = ima_show_template_sig}, > + {.field_id = "d-sig", .field_init = ima_eventdigest_sig_init, > + .field_show = ima_show_template_digest_ng}, > }; > -#define MAX_TEMPLATE_NAME_LEN 15 > +#define MAX_TEMPLATE_NAME_LEN 24 > > static struct ima_template_desc *ima_template; > static struct ima_template_desc *lookup_template_desc(const char *name); > diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c > index afb52a90e532..1dca082cce43 100644 > --- a/security/integrity/ima/ima_template_lib.c > +++ b/security/integrity/ima/ima_template_lib.c > @@ -220,7 +220,8 @@ int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp, > return 0; > } > > -static int ima_eventdigest_init_common(u8 *digest, u32 digestsize, u8 hash_algo, > +static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize, > + u8 hash_algo, > struct ima_field_data *field_data) > { > /* > @@ -323,6 +324,35 @@ int ima_eventdigest_ng_init(struct ima_event_data *event_data, > hash_algo, field_data); > } > > +/* > + * This function writes the digest of the file which is expected to match the > + * digest contained in the file's embedded signature. > + */ > +int ima_eventdigest_sig_init(struct ima_event_data *event_data, > + struct ima_field_data *field_data) > +{ > + struct evm_ima_xattr_data *xattr_value = event_data->xattr_value; > + enum hash_algo hash_algo = HASH_ALGO_SHA1; > + const u8 *cur_digest = NULL; > + u8 cur_digestsize = 0; > + int ret; > + > + if (!xattr_value || xattr_value->type != IMA_MODSIG) > + return 0; > + > + if (event_data->violation) /* recording a violation. */ > + goto out; > + > + ret = ima_get_modsig_hash(xattr_value, &hash_algo, &cur_digest, > + &cur_digestsize); > + if (ret) > + return ret; > + > + out: > + return ima_eventdigest_init_common(cur_digest, cur_digestsize, > + hash_algo, field_data); > +} > + > static int ima_eventname_init_common(struct ima_event_data *event_data, > struct ima_field_data *field_data, > bool size_limit) > @@ -379,10 +409,23 @@ int ima_eventsig_init(struct ima_event_data *event_data, > struct ima_field_data *field_data) > { > struct evm_ima_xattr_data *xattr_value = event_data->xattr_value; > + int xattr_len = event_data->xattr_len; > > if (!is_ima_sig(xattr_value)) > return 0; > > - return ima_write_template_field_data(xattr_value, event_data->xattr_len, > + /* > + * The xattr_value for IMA_MODSIG is a runtime structure containing > + * pointers. Get its raw data instead. > + */ > + if (xattr_value->type == IMA_MODSIG) { > + int rc; > + > + rc = ima_modsig_serialize_data(&xattr_value, &xattr_len); > + if (rc) > + return rc; > + } > + > + return ima_write_template_field_data(xattr_value, xattr_len, > DATA_FMT_HEX, field_data); > } > diff --git a/security/integrity/ima/ima_template_lib.h b/security/integrity/ima/ima_template_lib.h > index 6a3d8b831deb..3cd353e83f73 100644 > --- a/security/integrity/ima/ima_template_lib.h > +++ b/security/integrity/ima/ima_template_lib.h > @@ -38,6 +38,8 @@ int ima_eventname_init(struct ima_event_data *event_data, > struct ima_field_data *field_data); > int ima_eventdigest_ng_init(struct ima_event_data *event_data, > struct ima_field_data *field_data); > +int ima_eventdigest_sig_init(struct ima_event_data *event_data, > + struct ima_field_data *field_data); > int ima_eventname_ng_init(struct ima_event_data *event_data, > struct ima_field_data *field_data); > int ima_eventsig_init(struct ima_event_data *event_data, >