Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp626229pxv; Thu, 1 Jul 2021 06:02:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1gn1/15/A8NSlpqt71m4uOIVsfhtx7PsVwhrZgBVnzYXeF1A3B0oEURYuo0b19IlNe+2F X-Received: by 2002:a17:907:7da9:: with SMTP id oz41mr3692959ejc.39.1625144567346; Thu, 01 Jul 2021 06:02:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625144567; cv=none; d=google.com; s=arc-20160816; b=fMMOTK6hn/aJIvnVI0ADfnQLmeuMgwpLWyosFyIsyGXDI8zGpvlNuKEzrmawNe4yhN W24yN2sZwEj3Pda+YS0nI7TD4THGfgkVhWcZwE9amCUli3ruKWViRJA4eYRg7mooz4Hq tBbdi0WTq6tZ9rtWtJx38rOKIJUK/c7R1otpECywwIcCqp3XBxEtYkvc500qMSTe55tV 7AkkuaEnbGLxqWBTf5iO7NcodvTERsn+dewoI8eHH9xytR3jAOURsMjEs5YiAl0O/a4I 8KOYRLoIyBkccI4amxWWna0zP0hBKAkvNV5Ryd++tNcHUx2kEHVVmVl/auOM+5DqR85G uwQw== 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=jdnm3L6QW/IGvRuPBIuMuOtWe+L1jfGCxY7h2bccN9M=; b=rmJp5yajfwBGeiiPOzOzkMEiTjRQCDUj+7jNvnySkN0Vu+m+m8J/HjjZDSODEvAt/S nb16xGeL1PotNHN8drWAEoOYMOCh5gMNCY671gmgNKiO1k0jhvRah1690JJbPY2Jzudp qg5OlsmxW+iiwTA2lzBhvdTLiQTjmSU+BZDhU/e9BocahcfxEJXSjKM8emKPk97inVsf 0KPL/PXHUe+L+A0QEO5iaAr8XKOgIT6tpFMmT6wC8mXbk4LHO5U3X1T4WmkI6N8HtrrP 39lDuL+jKZYrQIwNPuG/O7YE5ddTPDZPSwC60r8o2LYd7plaYBBxpWDNyJrwBE8a+MAO mekw== 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 nc21si6268827ejc.247.2021.07.01.06.01.49; Thu, 01 Jul 2021 06:02:47 -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 S236557AbhGAM6t (ORCPT + 99 others); Thu, 1 Jul 2021 08:58:49 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3339 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236536AbhGAM6o (ORCPT ); Thu, 1 Jul 2021 08:58:44 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GFycS0x6vz6L7Rq; Thu, 1 Jul 2021 20:45:44 +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; Thu, 1 Jul 2021 14:56:11 +0200 From: Roberto Sassu To: , CC: , , , , , , , , Roberto Sassu Subject: [PATCH v2 1/3] ima: Introduce ima_get_current_hash_algo() Date: Thu, 1 Jul 2021 14:55:50 +0200 Message-ID: <20210701125552.2958008-2-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210701125552.2958008-1-roberto.sassu@huawei.com> References: <20210701125552.2958008-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: lhreml749-chm.china.huawei.com (10.201.108.199) 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 This patch introduces the new function ima_get_current_hash_algo(), that callers in the other kernel subsystems might use to obtain the hash algorithm selected by IMA. Its primary use will be to determine which algorithm has been used to calculate the digest written by ima_measure_critical_data() to the location passed as a new parameter (in a subsequent patch). Since the hash algorithm does not change after the IMA setup phase, there is no risk of races (obtaining a digest calculated with a different algorithm than the one returned). Signed-off-by: Roberto Sassu --- include/linux/ima.h | 7 +++++++ security/integrity/ima/ima_main.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/ima.h b/include/linux/ima.h index 61d5723ec303..81e830d01ced 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -11,9 +11,11 @@ #include #include #include +#include struct linux_binprm; #ifdef CONFIG_IMA +extern enum hash_algo ima_get_current_hash_algo(void); extern int ima_bprm_check(struct linux_binprm *bprm); extern int ima_file_check(struct file *file, int mask); extern void ima_post_create_tmpfile(struct user_namespace *mnt_userns, @@ -64,6 +66,11 @@ static inline const char * const *arch_get_ima_policy(void) #endif #else +static inline enum hash_algo ima_get_current_hash_algo(void) +{ + return HASH_ALGO__LAST; +} + static inline int ima_bprm_check(struct linux_binprm *bprm) { return 0; diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 287b90509006..8ef1fa357e0c 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -76,6 +76,11 @@ static int __init hash_setup(char *str) } __setup("ima_hash=", hash_setup); +enum hash_algo ima_get_current_hash_algo(void) +{ + return ima_hash_algo; +} + /* Prevent mmap'ing a file execute that is already mmap'ed write */ static int mmap_violation_check(enum ima_hooks func, struct file *file, char **pathbuf, const char **pathname, -- 2.25.1