Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6135406rdb; Thu, 14 Dec 2023 09:10:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfFYJDIfyKt985sOpZkCJVqj0K/1LKBOg6mBBmTSqbKlOz0sJxVgdJI85dylK5WYcchqxG X-Received: by 2002:a50:99c4:0:b0:552:2852:cb1 with SMTP id n4-20020a5099c4000000b0055228520cb1mr1672575edb.47.1702573800013; Thu, 14 Dec 2023 09:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702573799; cv=none; d=google.com; s=arc-20160816; b=sdCvwNEaBF1lxzbyglI4ZouinMJeU+k/YqUQovKD2Pue0QHIyy1jpm22t4tk75EPEO Rm5AzNYUf7CeTILV/mYJx80GE31evCraAeQSktWP9LeQhA3Z6hB72hfF2t3TkHsx9t3s A8Tpo9ZvgLRFQqHntbtqUNjZ2g5NBVjggVBalf44oc5yFz3ZiTJaRMxuQe+SHxJUqsl3 zp03HYuOmDgt1UTQYT0pEvfH7XPqsS+DdGZtDAsQx90lQYD/cnJGfmoxhsByjnzpRA96 HSkQuHkqOwR7XWCd/3tBdxiv/l34CbXLMYUWaObGS9m+3uOZ3OkwZI7X0QTirJpcXhfo tUZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=0Fqb01NJcQ4HTLYvfGcBGVr8CbCP8GTSmGYr+Qa+Tqg=; fh=e4uGr9b4mUXyBbS3/T8oKWuNGdTPau3Pm4RSvXRKvaA=; b=e/OaxFoyxYfRo2SF61+Y9xr2kt8koi10exLf2ZALl08gr01IlIWk8loa+gIHmBx/HQ 9JzJhIlQF2ZOyfGwc/sak5GEJ82Mel6RJZ2OEvgL9wtVcsemd0r/Vd7VPrdxQ+k9Obll f0TeJZS1NXb8BCWJyqhdXexcdKFm4E3B99TV5zKVPLBAeRMIrPL0L3VoPAt+JFrf+o+Z LOoeXF4M1Jmxcbi+nWxLtfZO3A0beAMAJfJTMxcOl7prmIuX1TFevkLFjWPT0fyF49Qu t/vLuKOcvqE0aSjPLYsm7YaQQE92qou4moaRMOvifKnJq8hhQPbUycY5hT6Nddqrd4p2 EFJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-586-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n8-20020a05640205c800b00550f51cd678si5098623edx.4.2023.12.14.09.09.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 09:09:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-586-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B62641F2109D for ; Thu, 14 Dec 2023 17:09:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A5B163DE9; Thu, 14 Dec 2023 17:09:56 +0000 (UTC) X-Original-To: linux-nfs@vger.kernel.org Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67025126; Thu, 14 Dec 2023 09:09:51 -0800 (PST) Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4SrdlN5SkGz9y2yb; Fri, 15 Dec 2023 00:55:44 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id C22DF14074C; Fri, 15 Dec 2023 01:09:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwBXlHSpNntl4xuLAg--.58219S4; Thu, 14 Dec 2023 18:09:38 +0100 (CET) From: Roberto Sassu To: viro@zeniv.linux.org.uk, brauner@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com, shuah@kernel.org, mic@digikod.net Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Roberto Sassu , Stefan Berger Subject: [PATCH v8 02/24] ima: Align ima_file_mprotect() definition with LSM infrastructure Date: Thu, 14 Dec 2023 18:08:12 +0100 Message-Id: <20231214170834.3324559-3-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231214170834.3324559-1-roberto.sassu@huaweicloud.com> References: <20231214170834.3324559-1-roberto.sassu@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content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6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFa9-UUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgALBF1jj5OoKQAAsu From: Roberto Sassu Change ima_file_mprotect() definition, so that it can be registered as implementation of the file_mprotect hook. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger Reviewed-by: Casey Schaufler Reviewed-by: Mimi Zohar --- include/linux/ima.h | 5 +++-- security/integrity/ima/ima_main.c | 6 ++++-- security/security.c | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/linux/ima.h b/include/linux/ima.h index 910a2f11a906..b66353f679e8 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -23,7 +23,8 @@ extern void ima_post_create_tmpfile(struct mnt_idmap *idmap, extern void ima_file_free(struct file *file); extern int ima_file_mmap(struct file *file, unsigned long reqprot, unsigned long prot, unsigned long flags); -extern int ima_file_mprotect(struct vm_area_struct *vma, unsigned long prot); +extern int ima_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, + unsigned long prot); extern int ima_load_data(enum kernel_load_data_id id, bool contents); extern int ima_post_load_data(char *buf, loff_t size, enum kernel_load_data_id id, char *description); @@ -84,7 +85,7 @@ static inline int ima_file_mmap(struct file *file, unsigned long reqprot, } static inline int ima_file_mprotect(struct vm_area_struct *vma, - unsigned long prot) + unsigned long reqprot, unsigned long prot) { return 0; } diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index cc1217ac2c6f..b3f5e8401056 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -455,7 +455,8 @@ int ima_file_mmap(struct file *file, unsigned long reqprot, /** * ima_file_mprotect - based on policy, limit mprotect change * @vma: vm_area_struct protection is set to - * @prot: contains the protection that will be applied by the kernel. + * @reqprot: protection requested by the application + * @prot: protection that will be applied by the kernel * * Files can be mmap'ed read/write and later changed to execute to circumvent * IMA's mmap appraisal policy rules. Due to locking issues (mmap semaphore @@ -465,7 +466,8 @@ int ima_file_mmap(struct file *file, unsigned long reqprot, * * On mprotect change success, return 0. On failure, return -EACESS. */ -int ima_file_mprotect(struct vm_area_struct *vma, unsigned long prot) +int ima_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, + unsigned long prot) { struct ima_template_desc *template = NULL; struct file *file; diff --git a/security/security.c b/security/security.c index d7b15ea67c3f..c87ba1bbd7dc 100644 --- a/security/security.c +++ b/security/security.c @@ -2819,7 +2819,7 @@ int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, ret = call_int_hook(file_mprotect, 0, vma, reqprot, prot); if (ret) return ret; - return ima_file_mprotect(vma, prot); + return ima_file_mprotect(vma, reqprot, prot); } /** -- 2.34.1