Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4406237pxa; Mon, 10 Aug 2020 08:22:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXBX12IU/OLQop9GCX6ye1XyMQt39BiQbS8ryQh8VYMR1E4/KLYqKK6TcbJ6dBBxaywJda X-Received: by 2002:a17:906:551:: with SMTP id k17mr21504786eja.322.1597072931047; Mon, 10 Aug 2020 08:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597072931; cv=none; d=google.com; s=arc-20160816; b=TGrXPV6LsR+DOaE6fARxnOiBBtMepPAXpyyYv2kt/80ru7EnjuZYGuglH4SxpJEZc5 tYnpkFHGVbVrz74OYlgq+Ix/0j11xdGfiEZwoVZjlQ6fZR3mI+OcOqeeqZxnHz/b4Dty D9heL9a9Sx9aTq10SCLT5jTyBGSwSKoXxHsqDsqwIzetjhZ7yy4UbxJhQUe5f3u07Fj+ oEsTEXYjgKFm4JIe5UWiQ8Js3PGniGbYQMZCVbIOCnXjpTVUvAvhrPG37uvjoNtJkmu4 cXLnoDIGIYdfZPLuWuw18dA/q50w0/A4zV+L4WI3GQX8En27YCWRAeUgNeDZSC1EeIow 4RPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SYn/nvWCxOmWV5k20wkvGFRZo4AUlC5tCR0hXb2wkBw=; b=k+c76xVPIl5G98mvnIHT8eHQUYLHdaOygiWc5/LdtFe1jH8VwaJpuIH5T5DwUM6/f/ OtgwDz1Q9QOqlv8TfD01m57uPQ2I9udpmCAlAR6O9oe7rTLMb+9IVr6W5zCEHFM63wBe 1rI6Rdt4hRjmM2v1UrJ6+nFGDIO0YBI8HXTCUVDWY5A5QwMX6ftvoKhHxt7gmbLSayoP 1PkhSzrmFjN6IPB+jIJVBnhQ6W6cZF8WpyU/gAL9PG7M0+96NDcdku/ZFjRi15Va2CG/ 8Xsx1dYQSK2WHXjq3FKWXlVC0H9L1yns6X+Vm7LPGs5TTlcmBqm24uu19LnmjZnaNkz0 4XUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dfuOJL4S; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si10530584edw.303.2020.08.10.08.21.48; Mon, 10 Aug 2020 08:22:11 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dfuOJL4S; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727987AbgHJPU3 (ORCPT + 99 others); Mon, 10 Aug 2020 11:20:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:50850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727977AbgHJPU0 (ORCPT ); Mon, 10 Aug 2020 11:20:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6F272075F; Mon, 10 Aug 2020 15:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597072825; bh=ced6ACKeiVQz70N1jpmr7sSe/5mq+5lAuhok2wNXuMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dfuOJL4SOaNObguckMIK3MbjlVOmXxvxOOEhHDBTXgjINlvf9oqkkNGB963PpEt2L MEjvPCmYy2VQACkcwmHGD3KO/4OUEQ6Nw1CXemPCPWFg9oGlWdDB2Y90JMDvjYmioH H0CeoyGyYQXciTCCOZRW/yP8WcJmSxrAp8Tc64Zw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, linux-fsdevel@vger.kernel.org, Al Viro , Frank van der Linden , Chuck Lever Subject: [PATCH 5.8 31/38] xattr: break delegations in {set,remove}xattr Date: Mon, 10 Aug 2020 17:19:21 +0200 Message-Id: <20200810151805.446918954@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151803.920113428@linuxfoundation.org> References: <20200810151803.920113428@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank van der Linden commit 08b5d5014a27e717826999ad20e394a8811aae92 upstream. set/removexattr on an exported filesystem should break NFS delegations. This is true in general, but also for the upcoming support for RFC 8726 (NFSv4 extended attribute support). Make sure that they do. Additionally, they need to grow a _locked variant, since callers might call this with i_rwsem held (like the NFS server code). Cc: stable@vger.kernel.org # v4.9+ Cc: linux-fsdevel@vger.kernel.org Cc: Al Viro Signed-off-by: Frank van der Linden Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/xattr.c | 84 +++++++++++++++++++++++++++++++++++++++++++++----- include/linux/xattr.h | 2 + 2 files changed, 79 insertions(+), 7 deletions(-) --- a/fs/xattr.c +++ b/fs/xattr.c @@ -204,10 +204,22 @@ int __vfs_setxattr_noperm(struct dentry return error; } - +/** + * __vfs_setxattr_locked: set an extended attribute while holding the inode + * lock + * + * @dentry - object to perform setxattr on + * @name - xattr name to set + * @value - value to set @name to + * @size - size of @value + * @flags - flags to pass into filesystem operations + * @delegated_inode - on return, will contain an inode pointer that + * a delegation was broken on, NULL if none. + */ int -vfs_setxattr(struct dentry *dentry, const char *name, const void *value, - size_t size, int flags) +__vfs_setxattr_locked(struct dentry *dentry, const char *name, + const void *value, size_t size, int flags, + struct inode **delegated_inode) { struct inode *inode = dentry->d_inode; int error; @@ -216,15 +228,40 @@ vfs_setxattr(struct dentry *dentry, cons if (error) return error; - inode_lock(inode); error = security_inode_setxattr(dentry, name, value, size, flags); if (error) goto out; + error = try_break_deleg(inode, delegated_inode); + if (error) + goto out; + error = __vfs_setxattr_noperm(dentry, name, value, size, flags); out: + return error; +} +EXPORT_SYMBOL_GPL(__vfs_setxattr_locked); + +int +vfs_setxattr(struct dentry *dentry, const char *name, const void *value, + size_t size, int flags) +{ + struct inode *inode = dentry->d_inode; + struct inode *delegated_inode = NULL; + int error; + +retry_deleg: + inode_lock(inode); + error = __vfs_setxattr_locked(dentry, name, value, size, flags, + &delegated_inode); inode_unlock(inode); + + if (delegated_inode) { + error = break_deleg_wait(&delegated_inode); + if (!error) + goto retry_deleg; + } return error; } EXPORT_SYMBOL_GPL(vfs_setxattr); @@ -378,8 +415,18 @@ __vfs_removexattr(struct dentry *dentry, } EXPORT_SYMBOL(__vfs_removexattr); +/** + * __vfs_removexattr_locked: set an extended attribute while holding the inode + * lock + * + * @dentry - object to perform setxattr on + * @name - name of xattr to remove + * @delegated_inode - on return, will contain an inode pointer that + * a delegation was broken on, NULL if none. + */ int -vfs_removexattr(struct dentry *dentry, const char *name) +__vfs_removexattr_locked(struct dentry *dentry, const char *name, + struct inode **delegated_inode) { struct inode *inode = dentry->d_inode; int error; @@ -388,11 +435,14 @@ vfs_removexattr(struct dentry *dentry, c if (error) return error; - inode_lock(inode); error = security_inode_removexattr(dentry, name); if (error) goto out; + error = try_break_deleg(inode, delegated_inode); + if (error) + goto out; + error = __vfs_removexattr(dentry, name); if (!error) { @@ -401,12 +451,32 @@ vfs_removexattr(struct dentry *dentry, c } out: + return error; +} +EXPORT_SYMBOL_GPL(__vfs_removexattr_locked); + +int +vfs_removexattr(struct dentry *dentry, const char *name) +{ + struct inode *inode = dentry->d_inode; + struct inode *delegated_inode = NULL; + int error; + +retry_deleg: + inode_lock(inode); + error = __vfs_removexattr_locked(dentry, name, &delegated_inode); inode_unlock(inode); + + if (delegated_inode) { + error = break_deleg_wait(&delegated_inode); + if (!error) + goto retry_deleg; + } + return error; } EXPORT_SYMBOL_GPL(vfs_removexattr); - /* * Extended attribute SET operations */ --- a/include/linux/xattr.h +++ b/include/linux/xattr.h @@ -52,8 +52,10 @@ ssize_t vfs_getxattr(struct dentry *, co ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size); int __vfs_setxattr(struct dentry *, struct inode *, const char *, const void *, size_t, int); int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int); +int __vfs_setxattr_locked(struct dentry *, const char *, const void *, size_t, int, struct inode **); int vfs_setxattr(struct dentry *, const char *, const void *, size_t, int); int __vfs_removexattr(struct dentry *, const char *); +int __vfs_removexattr_locked(struct dentry *, const char *, struct inode **); int vfs_removexattr(struct dentry *, const char *); ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);