Received: by 10.223.185.111 with SMTP id b44csp545443wrg; Fri, 9 Mar 2018 09:10:40 -0800 (PST) X-Google-Smtp-Source: AG47ELsQMfQ3UJOlIuGmvVVVil/2PKQG/CWlpKt4WmD2MGoR/AO2P5ruVaTpFD/k4JCKRebpzBX/ X-Received: by 10.99.175.8 with SMTP id w8mr24506645pge.390.1520615440029; Fri, 09 Mar 2018 09:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520615439; cv=none; d=google.com; s=arc-20160816; b=AzgLG6KRF795//T7dfiWpscRKjI8TTMPyw3EefCNF4jp9SssdbsxUwApwNDlcs2Y+b zGHm3M7IJvs6OfvFF+VsQlqEm37BM+A757VbDaED47uk8LmpnP4jA6Q0YRJ10vrmyt6S r+GNPYIzXX3M0ASjRpH+og/TVO3LLsJXYRWL+5XrfP6e3epM9WjnCIRWC4H3OBLu5QNf 5YK7xSbrkYEeiAJuGK8CVOe6WM+avdh4b9/R0OC5AvKrPuD03Yi1dJOxKHoz0dvgxygb VYOKAoSmaxATA6jagvf4+Ky4sOvBzd2+1x09SwwbIBXlbNmiHtTkxQjgHPXllfb6SkrM KU6Q== 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=Bbs3iuv23L59d1WqoeufYuyGjZ3IJx3pHYx6pPjTO8o=; b=WfG0ojUVeJG2Xv4sjRuH+Rz4ROGoMUsPZnowQBsVgc+X+fvchOOSaDP3gX/HabBEIZ 1+/ILkMcm0vP1XO72BbDE/Litsw1n12SdqYXTWs0JEfx7WaB5QNIn4W1BmzZXj+pjdUF E1oQ+6A9K5pDBK150i1Wbnu5NY9uWLuQU+lROlQdIOakLUWeA7+YCPZT3jVwCUQrazbB q7WxRPmiNRHHEfBVFVsYl3f+0OVAClDFWgDRyX+fkS3pmbur3fsYCvUCH+4k5H+aqyjn BnGFCegOMKR/3Q/0HroUpP5fgCuqeQmUuiqqkHjUExbcEkoR4D8Eg/RB0FNsz9eE99+W 4Pbw== 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 n11-v6si1125337plp.253.2018.03.09.09.10.24; Fri, 09 Mar 2018 09:10:39 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932195AbeCIRJ1 (ORCPT + 99 others); Fri, 9 Mar 2018 12:09:27 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49978 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbeCIRJZ (ORCPT ); Fri, 9 Mar 2018 12:09:25 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w29H7WUV130195 for ; Fri, 9 Mar 2018 12:09:25 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gkw89b1v6-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Fri, 09 Mar 2018 12:09:25 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Mar 2018 17:09:22 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 9 Mar 2018 17:09:20 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w29H9KaW51577082; Fri, 9 Mar 2018 17:09:20 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D52ABA4053; Fri, 9 Mar 2018 17:02:14 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C8C1A4040; Fri, 9 Mar 2018 17:02:14 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.101.51]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 9 Mar 2018 17:02:13 +0000 (GMT) Subject: Re: [PATCH v2 3/3] ima: support platform keyring for kernel appraisal From: Mimi Zohar To: Nayna Jain , dhowells@redhat.com Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org Date: Fri, 09 Mar 2018 12:09:18 -0500 In-Reply-To: <20180309153803.25859-3-nayna@linux.vnet.ibm.com> References: <20180309153803.25859-1-nayna@linux.vnet.ibm.com> <20180309153803.25859-3-nayna@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: 18030917-0008-0000-0000-000004D9EB73 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030917-0009-0000-0000-00001E6D10AA Message-Id: <1520615358.3911.1.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-09_09:,, 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-1803090209 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-03-09 at 21:08 +0530, Nayna Jain wrote: > Distros may sign the kernel images and, possibly, the initramfs with > platform trusted keys. On secure boot enabled systems or embedded devices, > these signatures are to be validated using keys on the platform keyring. > > This patch enables IMA-appraisal to access the platform keyring, based on a > new Kconfig option "IMA_USE_PLATFORM_KEYRING". > > Signed-off-by: Nayna Jain Thanks, Nayna! Signed-off-by: Mimi Zohar > --- > Changelog: > > v2: > * Rename integrity_load_keyring() to integrity_find_keyring() > * Fix the patch description per line length as suggested by Mimi > > security/integrity/digsig.c | 15 +++++++++++++++ > security/integrity/ima/Kconfig | 10 ++++++++++ > security/integrity/ima/ima_appraise.c | 22 +++++++++++++++++----- > security/integrity/ima/ima_init.c | 4 ++++ > security/integrity/integrity.h | 17 ++++++++++++++++- > 5 files changed, 62 insertions(+), 6 deletions(-) > > diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c > index 6f9e4ce568cd..cfeb977bced9 100644 > --- a/security/integrity/digsig.c > +++ b/security/integrity/digsig.c > @@ -34,6 +34,8 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = { > ".ima", > #endif > "_module", > + ".platform_keys", > + > }; > > #ifdef CONFIG_INTEGRITY_TRUSTED_KEYRING > @@ -78,6 +80,19 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, > return -EOPNOTSUPP; > } > > +#ifdef CONFIG_IMA_USE_PLATFORM_KEYRING > +int __init integrity_find_keyring(const unsigned int id) > +{ > + > + keyring[id] = find_keyring_by_name(keyring_name[id], 0); > + if (IS_ERR(keyring[id])) > + if (PTR_ERR(keyring[id]) != -ENOKEY) > + return PTR_ERR(keyring[id]); > + return 0; > + > +} > +#endif > + > int __init integrity_init_keyring(const unsigned int id) > { > const struct cred *cred = current_cred(); > diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig > index 35ef69312811..2e89d4f8a364 100644 > --- a/security/integrity/ima/Kconfig > +++ b/security/integrity/ima/Kconfig > @@ -227,3 +227,13 @@ config IMA_APPRAISE_SIGNED_INIT > default n > help > This option requires user-space init to be signed. > + > +config IMA_USE_PLATFORM_KEYRING > + bool "IMA uses keys from Platform Keyring for verification" > + depends on PLATFORM_KEYRING > + depends on IMA_APPRAISE > + depends on INTEGRITY_ASYMMETRIC_KEYS > + default n > + help > + This option enables IMA appraisal to look for the platform > + trusted keys in .platform_keys keyring. > diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c > index f2803a40ff82..5fec29f40595 100644 > --- a/security/integrity/ima/ima_appraise.c > +++ b/security/integrity/ima/ima_appraise.c > @@ -276,13 +276,25 @@ int ima_appraise_measurement(enum ima_hooks func, > (const char *)xattr_value, rc, > iint->ima_hash->digest, > iint->ima_hash->length); > - if (rc == -EOPNOTSUPP) { > - status = INTEGRITY_UNKNOWN; > - } else if (rc) { > + if (rc) { > + if (rc == -EOPNOTSUPP) { > + status = INTEGRITY_UNKNOWN; > + break; > + } > + if (func == KEXEC_KERNEL_CHECK) { > + rc = integrity_digsig_verify( > + INTEGRITY_KEYRING_PLATFORM, > + (const char *)xattr_value, > + xattr_len, > + iint->ima_hash->digest, > + iint->ima_hash->length); > + if (!rc) { > + status = INTEGRITY_PASS; > + break; > + } > + } > cause = "invalid-signature"; > status = INTEGRITY_FAIL; > - } else { > - status = INTEGRITY_PASS; > } > break; > default: > diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c > index 29b72cd2502e..5778647c6bc4 100644 > --- a/security/integrity/ima/ima_init.c > +++ b/security/integrity/ima/ima_init.c > @@ -122,6 +122,10 @@ int __init ima_init(void) > if (rc) > return rc; > > + rc = integrity_find_keyring(INTEGRITY_KEYRING_PLATFORM); > + if (rc) > + pr_info("Platform keyring is not found. (rc=%d)\n", rc); > + > rc = ima_init_crypto(); > if (rc) > return rc; > diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h > index 50a8e3365df7..3d3b7171ead2 100644 > --- a/security/integrity/integrity.h > +++ b/security/integrity/integrity.h > @@ -136,13 +136,23 @@ int integrity_kernel_read(struct file *file, loff_t offset, > #define INTEGRITY_KEYRING_EVM 0 > #define INTEGRITY_KEYRING_IMA 1 > #define INTEGRITY_KEYRING_MODULE 2 > -#define INTEGRITY_KEYRING_MAX 3 > +#define INTEGRITY_KEYRING_PLATFORM 3 > +#define INTEGRITY_KEYRING_MAX 4 > > #ifdef CONFIG_INTEGRITY_SIGNATURE > > int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, > const char *digest, int digestlen); > > +#ifdef CONFIG_IMA_USE_PLATFORM_KEYRING > +int __init integrity_find_keyring(const unsigned int id); > +#else > +static inline int __init integrity_find_keyring(const unsigned int id) > +{ > + return 0; > +} > +#endif > + > int __init integrity_init_keyring(const unsigned int id); > int __init integrity_load_x509(const unsigned int id, const char *path); > #else > @@ -154,6 +164,11 @@ static inline int integrity_digsig_verify(const unsigned int id, > return -EOPNOTSUPP; > } > > +static inline int __init integrity_find_keyring(const unsigned int id) > +{ > + return 0; > +} > + > static inline int integrity_init_keyring(const unsigned int id) > { > return 0;