Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4414396pxa; Mon, 10 Aug 2020 08:32:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOze0FCspPKkMKNZEcqEgHI/Szld9XE1CUphsogO8gSbE1/IiQnGv/tI+WNTCLiE8Vnodu X-Received: by 2002:aa7:cb19:: with SMTP id s25mr20700464edt.340.1597073553920; Mon, 10 Aug 2020 08:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073553; cv=none; d=google.com; s=arc-20160816; b=gbydIQvh1tVofiGPjyoRqaglRAqLvoYGVm+m3AoiAedH54rfZGUvlPIsRuWNa4A/X7 hhHFR3gexXAlTNx+9Fob6S7T4zR8rkFzIvpc1TyI0KWyh5QcVaCM1pW0+CXhrCY2CBn7 VF/O7qDWSAwlE8I1K8AjWpDA4Jmb+lNJ5vDGU3xsfr4QtcnT03wmYfMgJfcf/ZZo4pDd lyom9HsfNmMyptaZV1JmqRbLpQ7fBpIWfar/TXbbSM9SsktJAiX0ex2wUOtstHGGppOz OMQ30rdV4c55gD2g33hAmTJQDMHCLQUlR5T2FlMdmF5z3FoRamu+XD4AcutRa5h9HCNN Zhug== 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=J5jq0wIa9g/nYpUxx/XFAyGVnKKnHQscffg9VETlaL4=; b=kCYNp5gxziHFcedVSet43SEFp5B9SqswCe54P9FyMK2y1y+j1oilZema77I/l0m9lo /gvNh27S5G2hd8wjFRWV8m2p+1o3t5IbLgJzAfNvgdcVZu7IEEhnKqXCgXr28B3pGorJ KXQuAagzcqFrZ4OYss2MW7645Xpymcgn/z6Sl0pXy/ajL7mc+KVOIT0qvk5S5GDUG0/w +sduS/KsK8E87X9ENpegr8E+d0xY/on5Lak0CGokB0xvPqotKKp682k2yP0Mff75KxiK DRu9NpwLrPGEF1Z7/6YWhkH9RzEuRQWuLt4XZP8xNCy2+W9riuThHy1dB7SiyyNufWOD F/gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VSUvT82k; 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 x25si10998829edr.231.2020.08.10.08.32.10; Mon, 10 Aug 2020 08:32:33 -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=VSUvT82k; 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 S1729214AbgHJPbn (ORCPT + 99 others); Mon, 10 Aug 2020 11:31:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:38790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729205AbgHJPb1 (ORCPT ); Mon, 10 Aug 2020 11:31:27 -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 69F45207FF; Mon, 10 Aug 2020 15:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073486; bh=VmtNeDwcA6stexLMf4wzZ7iMfns6+tPogp0ojJ3LmcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSUvT82kNAh1gs+D1ExWItsuMtv7AOHGMxQojqJshRUqTzM4KdBtf59IAKTSHHPI1 xsiJp6QmsW28Zhusf0tpUnn6p1h+EPKSCs6rTlFIG/HPZ0SDbGDWjnYnTva1X0LEZY Z/BRiKWYrF22F5xabr4ziaR+ptfWuVHPIaMJL24I= 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 4.19 31/48] xattr: break delegations in {set,remove}xattr Date: Mon, 10 Aug 2020 17:21:53 +0200 Message-Id: <20200810151805.747153401@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151804.199494191@linuxfoundation.org> References: <20200810151804.199494191@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 @@ -203,10 +203,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; @@ -215,15 +227,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); @@ -377,8 +414,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; @@ -387,11 +434,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) { @@ -400,12 +450,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 @@ -51,8 +51,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);