Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2302291ybc; Wed, 13 Nov 2019 12:11:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxEtCue2GVt6R3BbS5GMmSdQd6Pf5eS8ae009ricrDxGM20FepP4XEtv8L0yExCrh27nODN X-Received: by 2002:a05:6402:4c5:: with SMTP id n5mr5856674edw.157.1573675864328; Wed, 13 Nov 2019 12:11:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573675864; cv=none; d=google.com; s=arc-20160816; b=o4OU3O7MKdX+6b0dH3uwKxO7Qi9Bj3vdvGAVTdIUMfIEUXPWWBRpZ/AlGYEFbOrQ9n H2YT9eQ1d86t4973I/CQeCyzgyxiw+HyCAzh8SvRPIADemqhnrehWkxq5qvoR4mp0LxO pWxKc7H6CMZ+1Ugg4GQswz8+3j5Ol4FQ+s7mCNQSLyVLAx/na0YjiK8BbhaoCvTzr+d+ GcQwL8nxs60EnjX6GGqc5f7E3uTyHUx18adlxteBjgF4D3P22nvLacoiLSvJJ2PlFyhI sjUPonE6lR7SgEIrIkjPbqP0hV/xZuhm5oHCmtvawg7GpZSdE/RGlqONVTlu3ZsUs0VU Kprg== 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:to:from:subject; bh=vvx966CnO2wbDKzHUkbvUH8aRyNnRfHysCFVuDxoTeI=; b=uDTu/Akn+veynKv09+YJnwmZKF7lur/9BUCG88PMGdV2PI2A+FT9bSy1M+tP32Ikyj HwMRo5eN1K5tLgZq2izTWbxj1kQY3Ciip3pfXSzTkdhjqem4O+Crq5eolW+DBTQvInW1 fVyRmFfiES6+esQ5VGo5b8lGu0AkhU/LAt9SDxT4yrV/X2LOPJ5ck4AF1cuBWZWPWP+G Ygfr9S87dubkALAIpMvnoM/te//fSKIaeDkHn0eF2ujsI9SlYUqRDeb/i6BVkfnH65pf 26UKKISS3CgObp74oc98bY+F4V9CR3ltZtxJEVsUApUrEszWmJPu08Am0/0Ij7yUayGK M8qQ== 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 p17si2015137edm.269.2019.11.13.12.10.39; Wed, 13 Nov 2019 12:11:04 -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 S1727002AbfKMUJf (ORCPT + 99 others); Wed, 13 Nov 2019 15:09:35 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:12324 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfKMUJf (ORCPT ); Wed, 13 Nov 2019 15:09:35 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id xADK7fra091819 for ; Wed, 13 Nov 2019 15:09:34 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2w8n79qvym-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 13 Nov 2019 15:09:34 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 13 Nov 2019 20:09:31 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 13 Nov 2019 20:09:27 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xADK8oos19399068 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Nov 2019 20:08:50 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 843A842042; Wed, 13 Nov 2019 20:09:26 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7E9B042041; Wed, 13 Nov 2019 20:09:25 +0000 (GMT) Received: from dhcp-9-31-103-201.watson.ibm.com (unknown [9.31.103.201]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 13 Nov 2019 20:09:25 +0000 (GMT) Subject: Re: [PATCH v6 3/3] KEYS: Call the IMA hook to measure keys From: Mimi Zohar To: Lakshmi Ramasubramanian , dhowells@redhat.com, matthewgarrett@google.com, sashal@kernel.org, jamorris@linux.microsoft.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 13 Nov 2019 15:09:24 -0500 In-Reply-To: <20191113184658.2862-4-nramas@linux.microsoft.com> References: <20191113184658.2862-1-nramas@linux.microsoft.com> <20191113184658.2862-4-nramas@linux.microsoft.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: 8bit X-TM-AS-GCONF: 00 x-cbid: 19111320-4275-0000-0000-0000037D7AD7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19111320-4276-0000-0000-00003890DDFC Message-Id: <1573675764.4843.14.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-13_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=11 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911130164 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-11-13 at 10:46 -0800, Lakshmi Ramasubramanian wrote: > Call the IMA hook from key_create_or_update function to measure > the key when a new key is created or an existing key is updated. > > This patch adds the call to the IMA hook from key_create_or_update > function to measure the key on key create or update. > > Signed-off-by: Lakshmi Ramasubramanian > --- > include/linux/ima.h | 13 +++++++++++++ > security/keys/key.c | 9 +++++++++ > 2 files changed, 22 insertions(+) > > diff --git a/include/linux/ima.h b/include/linux/ima.h > index 6d904754d858..ec5afe319ab7 100644 > --- a/include/linux/ima.h > +++ b/include/linux/ima.h > @@ -25,6 +25,12 @@ extern int ima_post_read_file(struct file *file, void *buf, loff_t size, > extern void ima_post_path_mknod(struct dentry *dentry); > extern void ima_kexec_cmdline(const void *buf, int size); > > +#ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS > +extern void ima_post_key_create_or_update(struct key *keyring, > + struct key *key, > + unsigned long flags, bool create); > +#endif > + > #ifdef CONFIG_IMA_KEXEC > extern void ima_add_kexec_buffer(struct kimage *image); > #endif > @@ -101,6 +107,13 @@ static inline void ima_add_kexec_buffer(struct kimage *image) > {} > #endif > > +#ifndef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS > +static inline void ima_post_key_create_or_update(struct key *keyring, > + struct key *key, > + unsigned long flags, > + bool create) {} > +#endif > + > #ifdef CONFIG_IMA_APPRAISE > extern bool is_ima_appraise_enabled(void); > extern void ima_inode_post_setattr(struct dentry *dentry); > diff --git a/security/keys/key.c b/security/keys/key.c > index 764f4c57913e..9782d4d046fd 100644 > --- a/security/keys/key.c > +++ b/security/keys/key.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include "internal.h" > > @@ -936,6 +937,9 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref, > goto error_link_end; > } > > + /* let the ima module know about the created key. */ This comment and the one below doesn't provide any additional information.  Please remove them. > + ima_post_key_create_or_update(keyring, key, flags, true); > + > key_ref = make_key_ref(key, is_key_possessed(keyring_ref)); > > error_link_end: > @@ -965,6 +969,11 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref, > } > > key_ref = __key_update(key_ref, &prep); > + > + /* let the ima module know about the updated key. */ > + if (!IS_ERR(key_ref)) > + ima_post_key_create_or_update(keyring, key, flags, false); > + > goto error_free_prep; > } > EXPORT_SYMBOL(key_create_or_update);