Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3639973pxv; Mon, 5 Jul 2021 02:11:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoKb5zS0dSe5zD+Jwi/YF8WB+dDgyY2bai6Uebt4hw8qgS5sCxDscAdh8oklJgO+af2z+v X-Received: by 2002:a17:907:7213:: with SMTP id dr19mr12343558ejc.107.1625476306252; Mon, 05 Jul 2021 02:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625476306; cv=none; d=google.com; s=arc-20160816; b=E3a6QsXD6QkQSpCUllfC41yYvEevfQlfwAjOCVjDGblEH3JMUCX9QxODsvFOqkh2tm o2ONX2klGSpS1RaXWoGRS05t40S0j0uxwmXaducu7+/gmoOV8pI1qL6MJFsHScKzKlMZ xrc4a7kHuBizV9kHqIBpHe/ZvsZYTDC+Rl/pNOv+Z8uxesl/9dzxaljbkapZPQoUFo88 cEEEsvZ2EZTrR/9J31WVEiwekncV0Z6jOobTrJro9GRyKURDn/dE7FWT9tm8ay5rvVNB aL6WzNPBM2w+geKNF79lnbjlcxfCIMKYpbGq+86sJzmADZVC0sjGG5ugCpEfUU2KcYXl pOVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Byvr3Jbrkx5Czxr73WPWMzjT6RZMf147zhd2Idx1mjk=; b=JRdKo5AgEY7/t5wo1PMMHUBkKPrf6ma230ELZDk90vksJ4w5UUk1t1CpD2vOrd6bJ/ E7VZyZoMSXBleh07sZsFyzALDwI6hXbzrMeKo5T0p2Zl0bi0SruOeS36rBlmjZG1n1O8 nyowQNa+LI0YFXd36vBLJCoQtIF41zzkuXhTj8QvCDzgieyDzHiTJqorhr14CSQ4Wfdp 5n3Pe9lG0gPqxduX4Jbi2wPe0KgvwbibGm7uk3PcFTgfkt5fW8Om41V1xgQDDab+9n2F XvkX1u9wgdxIRLry7no+A7yYN6tZxhxSqUMgaK1weAPq4Q8w3p4WyuSIHb1s4muhriXi WySQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si10577779ejl.652.2021.07.05.02.11.23; Mon, 05 Jul 2021 02:11:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230412AbhGEJMg (ORCPT + 99 others); Mon, 5 Jul 2021 05:12:36 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3358 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbhGEJMc (ORCPT ); Mon, 5 Jul 2021 05:12:32 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GJKPG0r2hz6M4HV; Mon, 5 Jul 2021 16:59:14 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.63.22) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 5 Jul 2021 11:09:53 +0200 From: Roberto Sassu To: , CC: , , , , , , , , Roberto Sassu Subject: [PATCH v3 2/3] ima: Return int in the functions to measure a buffer Date: Mon, 5 Jul 2021 11:09:21 +0200 Message-ID: <20210705090922.3321178-3-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210705090922.3321178-1-roberto.sassu@huawei.com> References: <20210705090922.3321178-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.204.63.22] X-ClientProxiedBy: lhreml752-chm.china.huawei.com (10.201.108.202) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ima_measure_critical_data() and process_buffer_measurement() currently don't return a result. A caller wouldn't be able to know whether those functions were executed successfully. This patch modifies the return type from void to int, and returns 0 if the buffer has been successfully measured, a negative value otherwise. Also, this patch does not modify the behavior of existing callers by processing the returned value. For those, the return value is ignored. Signed-off-by: Roberto Sassu --- include/linux/ima.h | 15 +++++++----- security/integrity/ima/ima.h | 10 ++++---- security/integrity/ima/ima_main.c | 40 ++++++++++++++++++------------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/include/linux/ima.h b/include/linux/ima.h index 81e830d01ced..60492263aa64 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -35,10 +35,10 @@ extern void ima_post_path_mknod(struct user_namespace *mnt_userns, extern int ima_file_hash(struct file *file, char *buf, size_t buf_size); extern int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size); extern void ima_kexec_cmdline(int kernel_fd, const void *buf, int size); -extern void ima_measure_critical_data(const char *event_label, - const char *event_name, - const void *buf, size_t buf_len, - bool hash); +extern int ima_measure_critical_data(const char *event_label, + const char *event_name, + const void *buf, size_t buf_len, + bool hash); #ifdef CONFIG_IMA_APPRAISE_BOOTPARAM extern void ima_appraise_parse_cmdline(void); @@ -144,10 +144,13 @@ static inline int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size static inline void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) {} -static inline void ima_measure_critical_data(const char *event_label, +static inline int ima_measure_critical_data(const char *event_label, const char *event_name, const void *buf, size_t buf_len, - bool hash) {} + bool hash) +{ + return -ENOENT; +} #endif /* CONFIG_IMA */ diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index f0e448ed1f9f..03db221324c3 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -264,11 +264,11 @@ void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file, struct evm_ima_xattr_data *xattr_value, int xattr_len, const struct modsig *modsig, int pcr, struct ima_template_desc *template_desc); -void process_buffer_measurement(struct user_namespace *mnt_userns, - struct inode *inode, const void *buf, int size, - const char *eventname, enum ima_hooks func, - int pcr, const char *func_data, - bool buf_hash); +int process_buffer_measurement(struct user_namespace *mnt_userns, + struct inode *inode, const void *buf, int size, + const char *eventname, enum ima_hooks func, + int pcr, const char *func_data, + bool buf_hash); void ima_audit_measurement(struct integrity_iint_cache *iint, const unsigned char *filename); int ima_alloc_init_template(struct ima_event_data *event_data, diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 8ef1fa357e0c..b512c06d8ee1 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -827,7 +827,7 @@ int ima_post_load_data(char *buf, loff_t size, return 0; } -/* +/** * process_buffer_measurement - Measure the buffer or the buffer data hash * @mnt_userns: user namespace of the mount the inode was found from * @inode: inode associated with the object being measured (NULL for KEY_CHECK) @@ -840,12 +840,15 @@ int ima_post_load_data(char *buf, loff_t size, * @buf_hash: measure buffer data hash * * Based on policy, either the buffer data or buffer data hash is measured + * + * Return: 0 if the buffer has been successfully measured, a negative value + * otherwise. */ -void process_buffer_measurement(struct user_namespace *mnt_userns, - struct inode *inode, const void *buf, int size, - const char *eventname, enum ima_hooks func, - int pcr, const char *func_data, - bool buf_hash) +int process_buffer_measurement(struct user_namespace *mnt_userns, + struct inode *inode, const void *buf, int size, + const char *eventname, enum ima_hooks func, + int pcr, const char *func_data, + bool buf_hash) { int ret = 0; const char *audit_cause = "ENOMEM"; @@ -867,7 +870,7 @@ void process_buffer_measurement(struct user_namespace *mnt_userns, u32 secid; if (!ima_policy_flag) - return; + return -ENOENT; template = ima_template_desc_buf(); if (!template) { @@ -889,7 +892,7 @@ void process_buffer_measurement(struct user_namespace *mnt_userns, secid, 0, func, &pcr, &template, func_data); if (!(action & IMA_MEASURE)) - return; + return -ENOENT; } if (!pcr) @@ -937,7 +940,7 @@ void process_buffer_measurement(struct user_namespace *mnt_userns, func_measure_str(func), audit_cause, ret, 0, ret); - return; + return ret; } /** @@ -977,18 +980,21 @@ void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) * and extend the pcr. Examples of critical data could be various data * structures, policies, and states stored in kernel memory that can * impact the integrity of the system. + * + * Return: 0 if the buffer has been successfully measured, a negative value + * otherwise. */ -void ima_measure_critical_data(const char *event_label, - const char *event_name, - const void *buf, size_t buf_len, - bool hash) +int ima_measure_critical_data(const char *event_label, + const char *event_name, + const void *buf, size_t buf_len, + bool hash) { if (!event_name || !event_label || !buf || !buf_len) - return; + return -ENOPARAM; - process_buffer_measurement(&init_user_ns, NULL, buf, buf_len, event_name, - CRITICAL_DATA, 0, event_label, - hash); + return process_buffer_measurement(&init_user_ns, NULL, buf, buf_len, + event_name, CRITICAL_DATA, 0, + event_label, hash); } static int __init init_ima(void) -- 2.25.1