Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2392221rdb; Mon, 20 Nov 2023 09:33:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyWnvSyGh/0RtrBqGMFi/XZYwCSfmn47Zb4XTXyICvReblT+l8gr2+94pvsF4kNOzIDn91 X-Received: by 2002:a17:902:b782:b0:1ce:6589:d1c0 with SMTP id e2-20020a170902b78200b001ce6589d1c0mr8797285pls.46.1700501580177; Mon, 20 Nov 2023 09:33:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700501580; cv=none; d=google.com; s=arc-20160816; b=VgXAB1keof68rePr9GJsLYRl4f7kgHhnsIykCEQYIRWlE9i7YXnmBQTWXcZfgf827q XbzJG2cChsQjlTNEFtCp+UEB9RrrhApllbGC7q1ifmcsY5N47un7RNL5A4aDuGHplE/d 6lj+eDl7/Fg5CpWhzym+n7HgL6UvKj5FOU11VC7llrknxConFjUBjVtQ1Z+R6H2Dspnb 2La9xJ36JtdjnxIwrFDEWiS4PXEYz+UciWG1PqVvvVTQxcG6hMHsYP3X9cNS2q4ImLg8 KavUZbiqduW/0yhWKF+gSozzH+XVU5BKIjZxc86xyr1d6JIniice4uf/DQn7z2eudEMG cR2w== 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=/n56n6VSj+6kzkNFHCVa5j5Dx51fbtWe1iqlXGuphzo=; fh=rktxqm33MMuC7ZhjsHbktB7IJ3whJdYMLoIrEoJl4gU=; b=F2g2sCZoiKLP4wnRrj8Qn7GEes0RG6bZWBb58rnJuLdlSv/Py8vyDnLb5zjJGNtyoT cl749TiriqhIoxGq/ipmJRdKg+PzQqlN2TFPj0BQZWN0jmKEmV3REYcKxECH5hKdtMC8 +33vbbHRqugLY7IEUAiQKDfJExlY8olPU1FVMBJBwaeL/9dVwOgR2ueT8FZBDnTImt0A KaGOPbW7Dj2PJrj2+O4Fn6ldypcRiB/iPGrfmC+bIwtFFj5Jh0MTP47C7lYoQq/22Zxg 8xYIRQ2j6/sItFfXEwVaCDDfEAJ48bVv2w3iwipJf36iXGTG1KtUYM2IsxEz9lLaAhHQ GKpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o12-20020a170902bccc00b001cc1eab0fe4si8004321pls.298.2023.11.20.09.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 09:33:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7C11F8032C51; Mon, 20 Nov 2023 09:32:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233627AbjKTRcb convert rfc822-to-8bit (ORCPT + 99 others); Mon, 20 Nov 2023 12:32:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233710AbjKTRc2 (ORCPT ); Mon, 20 Nov 2023 12:32:28 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99DDABA; Mon, 20 Nov 2023 09:32:24 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4SYvKW1Jf5z9xvrJ; Tue, 21 Nov 2023 01:15:43 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwDHxV_8l1tllXsHAQ--.3416S2; Mon, 20 Nov 2023 18:31:55 +0100 (CET) Message-ID: <1999ed6f77100d9d2adc613c9748f15ab8fcf432.camel@huaweicloud.com> Subject: Re: [PATCH v5 11/23] security: Introduce inode_post_removexattr hook From: Roberto Sassu To: Casey Schaufler , 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, 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, Roberto Sassu , Stefan Berger Date: Mon, 20 Nov 2023 18:31:37 +0100 In-Reply-To: <85c5dda2-5a2f-4c73-82ae-8a333b69b4a7@schaufler-ca.com> References: <20231107134012.682009-1-roberto.sassu@huaweicloud.com> <20231107134012.682009-12-roberto.sassu@huaweicloud.com> <85c5dda2-5a2f-4c73-82ae-8a333b69b4a7@schaufler-ca.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: GxC2BwDHxV_8l1tllXsHAQ--.3416S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCryfur1DZr4xWrW7XF48Crg_yoWrKFyfpF s8K3Z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.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 09:32:50 -0800 (PST) On Tue, 2023-11-07 at 09:33 -0800, Casey Schaufler wrote: > On 11/7/2023 5:40 AM, Roberto Sassu wrote: > > From: Roberto Sassu > > > > In preparation for moving IMA and EVM to the LSM infrastructure, introduce > > the inode_post_removexattr hook. > > > > At inode_removexattr hook, EVM verifies the file's existing HMAC value. At > > inode_post_removexattr, EVM re-calculates the file's HMAC with the passed > > xattr removed and other file metadata. > > > > Other LSMs could similarly take some action after successful xattr removal. > > > > The new hook cannot return an error and cannot cause the operation to be > > reverted. > > > > Signed-off-by: Roberto Sassu > > Reviewed-by: Stefan Berger > > Reviewed-by: Mimi Zohar > > --- > > fs/xattr.c | 9 +++++---- > > include/linux/lsm_hook_defs.h | 2 ++ > > include/linux/security.h | 5 +++++ > > security/security.c | 14 ++++++++++++++ > > 4 files changed, 26 insertions(+), 4 deletions(-) > > > > diff --git a/fs/xattr.c b/fs/xattr.c > > index 09d927603433..84a4aa566c02 100644 > > --- a/fs/xattr.c > > +++ b/fs/xattr.c > > @@ -552,11 +552,12 @@ __vfs_removexattr_locked(struct mnt_idmap *idmap, > > goto out; > > > > error = __vfs_removexattr(idmap, dentry, name); > > + if (error) > > + goto out; > > Shouldn't this be simply "return error" rather than a goto to nothing > but "return error"? I got a review from Andrew Morton. His argument seems convincing, that having less return places makes the code easier to handle. Thanks Roberto > > - if (!error) { > > - fsnotify_xattr(dentry); > > - evm_inode_post_removexattr(dentry, name); > > - } > > + fsnotify_xattr(dentry); > > + security_inode_post_removexattr(dentry, name); > > + evm_inode_post_removexattr(dentry, name); > > > > out: > > return error; > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > > index 67410e085205..88452e45025c 100644 > > --- a/include/linux/lsm_hook_defs.h > > +++ b/include/linux/lsm_hook_defs.h > > @@ -149,6 +149,8 @@ LSM_HOOK(int, 0, inode_getxattr, struct dentry *dentry, const char *name) > > LSM_HOOK(int, 0, inode_listxattr, struct dentry *dentry) > > LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, > > struct dentry *dentry, const char *name) > > +LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, > > + const char *name) > > LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, > > struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) > > LSM_HOOK(int, 0, inode_get_acl, struct mnt_idmap *idmap, > > diff --git a/include/linux/security.h b/include/linux/security.h > > index 664df46b22a9..922ea7709bae 100644 > > --- a/include/linux/security.h > > +++ b/include/linux/security.h > > @@ -380,6 +380,7 @@ int security_inode_getxattr(struct dentry *dentry, const char *name); > > int security_inode_listxattr(struct dentry *dentry); > > int security_inode_removexattr(struct mnt_idmap *idmap, > > struct dentry *dentry, const char *name); > > +void security_inode_post_removexattr(struct dentry *dentry, const char *name); > > int security_inode_need_killpriv(struct dentry *dentry); > > int security_inode_killpriv(struct mnt_idmap *idmap, struct dentry *dentry); > > int security_inode_getsecurity(struct mnt_idmap *idmap, > > @@ -940,6 +941,10 @@ static inline int security_inode_removexattr(struct mnt_idmap *idmap, > > return cap_inode_removexattr(idmap, dentry, name); > > } > > > > +static inline void security_inode_post_removexattr(struct dentry *dentry, > > + const char *name) > > +{ } > > + > > static inline int security_inode_need_killpriv(struct dentry *dentry) > > { > > return cap_inode_need_killpriv(dentry); > > diff --git a/security/security.c b/security/security.c > > index ce3bc7642e18..8aa6e9f316dd 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -2452,6 +2452,20 @@ int security_inode_removexattr(struct mnt_idmap *idmap, > > return evm_inode_removexattr(idmap, dentry, name); > > } > > > > +/** > > + * security_inode_post_removexattr() - Update the inode after a removexattr op > > + * @dentry: file > > + * @name: xattr name > > + * > > + * Update the inode after a successful removexattr operation. > > + */ > > +void security_inode_post_removexattr(struct dentry *dentry, const char *name) > > +{ > > + if (unlikely(IS_PRIVATE(d_backing_inode(dentry)))) > > + return; > > + call_void_hook(inode_post_removexattr, dentry, name); > > +} > > + > > /** > > * security_inode_need_killpriv() - Check if security_inode_killpriv() required > > * @dentry: associated dentry