Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1805201rdh; Tue, 26 Sep 2023 04:18:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFx6chuyggpH6jJFefbfg6A4r/ATulthnY/XDuZY7QzR24yEwlj0ZHFFsEwZPfcXcgzi0aQ X-Received: by 2002:a54:450b:0:b0:3a7:7988:9916 with SMTP id l11-20020a54450b000000b003a779889916mr10822326oil.59.1695727082367; Tue, 26 Sep 2023 04:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695727082; cv=none; d=google.com; s=arc-20160816; b=aX7ZW6B4vkgvMbSqln5g/9xmQ9THVEFEHVGoLh2+tlmuZM9LRcURLtOsMyZIUYuE7/ HzEGTb3YvjAV80YpeCHCE+2BntWhqD7vfchy4hkOSM0LTMhCRTEDiBU4EhNFhv5uLsbt Awg44hQUzuMnRhOrytPXufDBo+i9pJ1JFDFM8BCItXC3tqPfOlCKsrl778Ntxrs1Yrfk eN8s/muiiPI6JBvhIiXzsKaQT6RGYPpktTnsLIuevYc0dp638Eww4mUXxYaXY67szcCU w8jBWUPCm+xeY00fjJ7Z8+TTXZpasNLrygOVy9+wvNPd8yTrPlMZM6nNO0avqHTTyNOT FuWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=nY0OD5qndhKTn3rax0XzoCSt2M26Mc6mEiH7WR22i4A=; fh=k32FWR+OEbSGPhlKvyeJu1pW9b0VDX/rgvS8LbsdBHU=; b=0wmTbFJHDY25tMMRo6V1Ap+sx4Ewq7AM7CsjirpX8XmkdfTHEL6bdk6jTzDT7te9gn jKKnB2zk/9yKXnpQauQ36ztiJV8/C/MkHUCaQcvN/8sRJFxl9uwx1c6GxlIGsc7cPHtp Z5yL1wu+jhiIU3jZi5/YnC54L5fVdK5ntoOobz4Qx5KeC+L2F9oHf75juGa1a5uP5xam QzQsE2DISHAVrbu2zoeI+F+Sn5MpB9aI1Hs3bGFkXKfPCjBDwbIW0tiR0oMewzDUAIwT wV5ojzCabJqRI80x/kolnRltE3NVH6kMOJJG9wP2FRUR2FeILOvu3JY2vpgRBdN8+dZY ocLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id l191-20020a6391c8000000b0055c8d58cee9si12527227pge.714.2023.09.26.04.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:18:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B883B8303A33; Tue, 26 Sep 2023 04:15:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbjIZLPK convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Sep 2023 07:15:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbjIZLPJ (ORCPT ); Tue, 26 Sep 2023 07:15:09 -0400 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E72EDE5; Tue, 26 Sep 2023 04:15:01 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4RvxbH6zKSz9v7cV; Tue, 26 Sep 2023 18:59:55 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwDHH5ELvRJlT9ARAQ--.20978S2; Tue, 26 Sep 2023 12:14:32 +0100 (CET) Message-ID: <66249824469de1edefd42b42f72cab17ea331d09.camel@huaweicloud.com> Subject: Re: [PATCH v3 12/25] security: Introduce inode_post_setattr hook 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 Date: Tue, 26 Sep 2023 13:14:17 +0200 In-Reply-To: <20230904133415.1799503-13-roberto.sassu@huaweicloud.com> References: <20230904133415.1799503-1-roberto.sassu@huaweicloud.com> <20230904133415.1799503-13-roberto.sassu@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-CM-TRANSID: LxC2BwDHH5ELvRJlT9ARAQ--.20978S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCryrXF4ftryxWF4furW7Arb_yoWrCrWrpF Wrt3WrCw4rGFW7Wrn5Ja17uanaga45WrW7XrWvgw1jyFn7tr17tF13K34UCr13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HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 26 Sep 2023 04:15:09 -0700 (PDT) On Mon, 2023-09-04 at 15:34 +0200, Roberto Sassu wrote: > From: Roberto Sassu > > In preparation for moving IMA and EVM to the LSM infrastructure, introduce > the inode_post_setattr hook. > > It is useful for EVM to recalculate the HMAC on modified file attributes > and other file metadata, after it verified the HMAC of current file > metadata with the inode_setattr hook. > > LSMs should use the new hook instead of inode_setattr, when they need to > know that the operation was done successfully (not known in inode_setattr). > The new hook cannot return an error and cannot cause the operation to be > reverted. > > Signed-off-by: Roberto Sassu > --- > fs/attr.c | 1 + Hi Christian, Al could you please review and ack patches 12-19, which touch the VFS? Thanks a lot! Roberto > include/linux/lsm_hook_defs.h | 2 ++ > include/linux/security.h | 7 +++++++ > security/security.c | 16 ++++++++++++++++ > 4 files changed, 26 insertions(+) > > diff --git a/fs/attr.c b/fs/attr.c > index 431f667726c7..3c309eb456c6 100644 > --- a/fs/attr.c > +++ b/fs/attr.c > @@ -486,6 +486,7 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry, > > if (!error) { > fsnotify_change(dentry, ia_valid); > + security_inode_post_setattr(idmap, dentry, ia_valid); > ima_inode_post_setattr(idmap, dentry, ia_valid); > evm_inode_post_setattr(idmap, dentry, ia_valid); > } > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index fdf075a6b1bb..995d30336cfa 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -136,6 +136,8 @@ LSM_HOOK(int, 0, inode_follow_link, struct dentry *dentry, struct inode *inode, > LSM_HOOK(int, 0, inode_permission, struct inode *inode, int mask) > LSM_HOOK(int, 0, inode_setattr, struct mnt_idmap *idmap, struct dentry *dentry, > struct iattr *attr) > +LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, struct mnt_idmap *idmap, > + struct dentry *dentry, int ia_valid) > LSM_HOOK(int, 0, inode_getattr, const struct path *path) > LSM_HOOK(int, 0, inode_setxattr, struct mnt_idmap *idmap, > struct dentry *dentry, const char *name, const void *value, > diff --git a/include/linux/security.h b/include/linux/security.h > index dcb3604ffab8..820899db5276 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -355,6 +355,8 @@ int security_inode_follow_link(struct dentry *dentry, struct inode *inode, > int security_inode_permission(struct inode *inode, int mask); > int security_inode_setattr(struct mnt_idmap *idmap, > struct dentry *dentry, struct iattr *attr); > +void security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry, > + int ia_valid); > int security_inode_getattr(const struct path *path); > int security_inode_setxattr(struct mnt_idmap *idmap, > struct dentry *dentry, const char *name, > @@ -856,6 +858,11 @@ static inline int security_inode_setattr(struct mnt_idmap *idmap, > return 0; > } > > +static inline void > +security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry, > + int ia_valid) > +{ } > + > static inline int security_inode_getattr(const struct path *path) > { > return 0; > diff --git a/security/security.c b/security/security.c > index 2b24d01cf181..764a6f28b3b9 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -2124,6 +2124,22 @@ int security_inode_setattr(struct mnt_idmap *idmap, > } > EXPORT_SYMBOL_GPL(security_inode_setattr); > > +/** > + * security_inode_post_setattr() - Update the inode after a setattr operation > + * @idmap: idmap of the mount > + * @dentry: file > + * @ia_valid: file attributes set > + * > + * Update inode security field after successful setting file attributes. > + */ > +void security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry, > + int ia_valid) > +{ > + if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) > + return; > + call_void_hook(inode_post_setattr, idmap, dentry, ia_valid); > +} > + > /** > * security_inode_getattr() - Check if getting file attributes is allowed > * @path: file