Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp361820pxv; Wed, 30 Jun 2021 07:18:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbWpTnxq4lXXq2DhuNSFPooSvSrVUk1Ns4a7Awcqx/L+rZULY8ALSx8TgDYEfws0oStJ2z X-Received: by 2002:a05:6402:1776:: with SMTP id da22mr46458726edb.133.1625062705890; Wed, 30 Jun 2021 07:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625062705; cv=none; d=google.com; s=arc-20160816; b=g8zJQcVbYCduDA6BYRJs4swyPDp3rFN71ucRXVxubxmiBPnNHIGXPNqlJ8yx9KBkEU jTu5Y6jBtJr5ZPPUlVomkCn9nZuD52BGYYOz87sdCxjfrBQ6gRwwgcc1FXM/RFciMGZs 7t7vUjLYLSngKNdrTYKh7sopTwUfOK1SQzpfjbNX8k/iRlo+fkatD/tjBadLn+oytKlg IoCtBcbWDwLrnf6BqlDbMvH2KE8arjxcipwR7T679Uu+/QHAQxda0p1/wnEpV7Dx2Uba OB/QgWzzgshvu0n+d5gILKZwu2EJRZquHNrluQOHW5N7nNyDUihv6Z4a71OkKt557nNh W+MQ== 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=kEq3efZGzogv4QBS/oBMXklYwOR1Ko579y0VYXNlup5wsCOw9sxdWsAzefLcBHAd4u 7GAgqqeAKdZYfreJ9fXqTkEuM8ghQcVfw0kKziM7QqqE4R9k6NZfoXbliWYVw7xMOUf/ estgBm1lGWXBkqgbdKyfcxsUKKHxaXMzzEUCSms9a06JypsSvDycJvigc1Gc/hnSyvwd JFPNtJdcL9FasyPYsgSQk12ozP1DgbQqgGChI8iOrkKnk35jPGCwVgXZL4sGAKW01W/w dNnJFtb1dH4aj6KBb0unTlcrkncYwXzKU3wgWdJm38JcwOqVJpuIGpx4S447Jr0rc9+F Y2yg== 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 p15si20576655edr.433.2021.06.30.07.18.01; Wed, 30 Jun 2021 07:18:25 -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 S235271AbhF3OT0 (ORCPT + 99 others); Wed, 30 Jun 2021 10:19:26 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3333 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234855AbhF3OTV (ORCPT ); Wed, 30 Jun 2021 10:19:21 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GFNN74Strz6D8Vp; Wed, 30 Jun 2021 22:03:03 +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; Wed, 30 Jun 2021 16:16:50 +0200 From: Roberto Sassu To: , CC: , , , , , , , , Roberto Sassu Subject: [PATCH 1/3] ima: Introduce ima_get_current_hash_algo() Date: Wed, 30 Jun 2021 16:16:33 +0200 Message-ID: <20210630141635.2862222-2-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210630141635.2862222-1-roberto.sassu@huawei.com> References: <20210630141635.2862222-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: lhreml754-chm.china.huawei.com (10.201.108.204) 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