Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp204354rdb; Thu, 31 Aug 2023 07:16:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhd8B5D0GgW41WMaCHRZ2fJl2KfopE8a2oZ3zHYXw6EDyAn38ojcLfJ8UN/ZYLfdeYpLgA X-Received: by 2002:a17:90b:f91:b0:270:1406:fcf with SMTP id ft17-20020a17090b0f9100b0027014060fcfmr4978539pjb.45.1693491376602; Thu, 31 Aug 2023 07:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693491376; cv=none; d=google.com; s=arc-20160816; b=VGQVA3E9j41qvCqbBVUiQ3Emt9sr7vxnWxKnv5Cyim4I1yI7k8Fjg0oNHSKycgCk4Y DJZAbXS28lvyhhr+2X2JD1dd9cLE7HKIVqES/Oh+WkJaY7s+/pDBK5cLeD94ufOVaFY9 sU99CcYlwjOHGtAaaO/D0jgV+Nhl2QOd7cR9+w5lKxXCjGIOu8fNHFM0DDVgWR8BEVOO vWN3h9Dd/Hq3rAb8jGlan11UMM+RG9BubMYN9AnTGRSDGsN7m6CAfvrjrHlcQooOs4tl xFDhr6TM5HE3HGPUM5ONGKXjgFdfFnUngMVAHoWKor9ocyHkM0LGKCsrL0Z6DuM4w91N 0ciA== 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=xBSbJ06nRPp5TxIvNMdYqPLaFj4E15Kf9kiPZ8LR0LA=; fh=ZhQZvtUJr/vinStRe/fLjcmSrOCsze6H5x9tCaYQJfY=; b=WXfSXhM7MqLNDQyNWvU23xUrf4xndr6TPv5/TUCkaEwKDbrRJrTh5juFBqL3CKZu3H d/mCDHwACCWcjfbELRWjpLTcyAKCuBZ5QOKL5h889ZItTBf2ltZruDUbnmZErGl7OZfi OMcUxoWVWqknJVfaIm/r8Dad9BCODhW++JkQa5kz++kFWFLlZBV92Gfg1NbSAF6P4Qvn f2qgRK4nhypntd0zirAQlVb/bJrZlq0jI4KjbthoTAxbRXB5NhviGMnYEvQ+qvpIvSju BORgmDnVaBXhrnHXfA1MH3VuaAQlzgev8ckUY+7Njug5mEBiEFocyZLNrWWZ+WaP6/SG IXXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170903110d00b001b9d03d0dcasi1218563plh.143.2023.08.31.07.16.14; Thu, 31 Aug 2023 07:16:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343924AbjHaKro (ORCPT + 12 others); Thu, 31 Aug 2023 06:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238639AbjHaKrm (ORCPT ); Thu, 31 Aug 2023 06:47:42 -0400 Received: from frasgout12.his.huawei.com (unknown [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A177BE57; Thu, 31 Aug 2023 03:47:03 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4RbyCC2FWgz9xtRp; Thu, 31 Aug 2023 18:32:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwBXC7t9bvBkiGfdAQ--.39787S19; Thu, 31 Aug 2023 11:45:59 +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, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, Roberto Sassu , Stefan Berger Subject: [PATCH v2 17/25] security: Introduce inode_post_create_tmpfile hook Date: Thu, 31 Aug 2023 12:41:28 +0200 Message-Id: <20230831104136.903180-18-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831104136.903180-1-roberto.sassu@huaweicloud.com> References: <20230831104136.903180-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LxC2BwBXC7t9bvBkiGfdAQ--.39787S19 X-Coremail-Antispam: 1UD129KBjvJXoWxGFy7tFWrtw18CFykKr17ZFb_yoWrGry5pF 4fK3W5Gws5XFy7Wr1kAF4Uuw1SgayagrWUJrZagwnIyFn7tr1ftF4Skr12kF1fJrW8W342 q3ZFkrZxGr17trJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVWxJr0_GcWl84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E 14v26F4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26F1j6w1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJr0_GcWlIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Cr1j6rxdYxBIdaVFxhVjvjDU0xZFpf9x07UdfHUUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAGBF1jj5Nc0wAAsu X-CFilter-Loop: Reflected X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,MAY_BE_FORGED, RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Roberto Sassu In preparation for moving IMA and EVM to the LSM infrastructure, introduce the inode_post_create_tmpfile hook. Signed-off-by: Roberto Sassu Reviewed-by: Stefan Berger --- fs/namei.c | 1 + include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 8 ++++++++ security/security.c | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index c8c4ab26b52a..efed0e1e93f5 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3700,6 +3700,7 @@ static int vfs_tmpfile(struct mnt_idmap *idmap, inode->i_state |= I_LINKABLE; spin_unlock(&inode->i_lock); } + security_inode_post_create_tmpfile(idmap, dir, file, mode); ima_post_create_tmpfile(idmap, dir, file, mode); return 0; } diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index b1634b5de98c..9ae573b83737 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -121,6 +121,8 @@ LSM_HOOK(int, 0, inode_init_security_anon, struct inode *inode, const struct qstr *name, const struct inode *context_inode) LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry, umode_t mode) +LSM_HOOK(void, LSM_RET_VOID, inode_post_create_tmpfile, struct mnt_idmap *idmap, + struct inode *dir, struct file *file, umode_t mode) LSM_HOOK(int, 0, inode_link, struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) LSM_HOOK(int, 0, inode_unlink, struct inode *dir, struct dentry *dentry) diff --git a/include/linux/security.h b/include/linux/security.h index f210bd66e939..5f296761883f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -338,6 +338,9 @@ int security_inode_init_security_anon(struct inode *inode, const struct qstr *name, const struct inode *context_inode); int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode); +void security_inode_post_create_tmpfile(struct mnt_idmap *idmap, + struct inode *dir, struct file *file, + umode_t mode); int security_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry); int security_inode_unlink(struct inode *dir, struct dentry *dentry); @@ -788,6 +791,11 @@ static inline int security_inode_create(struct inode *dir, return 0; } +static inline void +security_inode_post_create_tmpfile(struct mnt_idmap *idmap, struct inode *dir, + struct file *file, umode_t mode) +{ } + static inline int security_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) diff --git a/security/security.c b/security/security.c index 56c1c1e66fd1..e5acb11f6ebd 100644 --- a/security/security.c +++ b/security/security.c @@ -1920,6 +1920,24 @@ int security_inode_create(struct inode *dir, struct dentry *dentry, } EXPORT_SYMBOL_GPL(security_inode_create); +/** + * security_inode_post_create_tmpfile() - Update inode security field after creation of tmpfile + * @idmap: idmap of the mount + * @dir: the inode of the base directory + * @file: file descriptor of the new tmpfile + * @mode: the mode of the new tmpfile + * + * Update inode security field after a tmpfile has been created. + */ +void security_inode_post_create_tmpfile(struct mnt_idmap *idmap, + struct inode *dir, + struct file *file, umode_t mode) +{ + if (unlikely(IS_PRIVATE(dir))) + return; + call_void_hook(inode_post_create_tmpfile, idmap, dir, file, mode); +} + /** * security_inode_link() - Check if creating a hard link is allowed * @old_dentry: existing file -- 2.34.1