Skip to contentSkip to conversation

NFSv4: xattr handlers should check for absent nfs filehandles

PATCH Superseded Scott Mayhew 2 participants 3 messages Apr 11, 2025 – Apr 15, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSv4: xattr handlers should check for absent nfs filehandles

The nfs inodes for referral anchors that have not yet been followed have their filehandles zeroed out.

Attempting to call getxattr() on one of these will cause the nfs client to send a GETATTR to the nfs server with the preceding PUTFH sans filehandle. The server will reply NFS4ERR_NOFILEHANDLE, leading to -EIO being returned to the application.

For example:

$ strace -e trace=getxattr getfattr -n system.nfs4_acl /mnt/t/ref
getxattr("/mnt/t/ref", "system.nfs4_acl", NULL, 0) = -1 EIO (Input/output error)
/mnt/t/ref: system.nfs4_acl: Input/output error
+++ exited with 1 +++

Have the xattr handlers return -ENODATA instead.

---
 fs/nfs/nfs4proc.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
fs/nfs/nfs4proc.c +71 -0
index 970f28dbf253..a01592930370 100644
@@ -7933,6 +7933,11 @@ static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler,
 				   const char *key, const void *buf,
 				   size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_ACL);
 }
 
@@ -7940,11 +7945,21 @@ static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler,
 				   struct dentry *unused, struct inode *inode,
 				   const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_ACL);
 }
 
 static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_ACL);
 }
 
@@ -7957,6 +7972,11 @@ static int nfs4_xattr_set_nfs4_dacl(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_DACL);
 }
 
@@ -7964,11 +7984,21 @@ static int nfs4_xattr_get_nfs4_dacl(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_DACL);
 }
 
 static bool nfs4_xattr_list_nfs4_dacl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_DACL);
 }
 
@@ -7980,6 +8010,11 @@ static int nfs4_xattr_set_nfs4_sacl(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_SACL);
 }
 
@@ -7987,11 +8022,21 @@ static int nfs4_xattr_get_nfs4_sacl(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_SACL);
 }
 
 static bool nfs4_xattr_list_nfs4_sacl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_SACL);
 }
 
@@ -8005,6 +8050,11 @@ static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler,
 				     const char *key, const void *buf,
 				     size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (security_ismaclabel(key))
 		return nfs4_set_security_label(inode, buf, buflen);
 
@@ -8015,6 +8065,11 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 				     struct dentry *unused, struct inode *inode,
 				     const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (security_ismaclabel(key))
 		return nfs4_get_security_label(inode, buf, buflen);
 	return -EOPNOTSUPP;
@@ -8023,8 +8078,12 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 static ssize_t
 nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	int len = 0;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
 		len = security_inode_listsecurity(inode, list, list_len);
 		if (len >= 0 && list_len && len > list_len)
@@ -8056,9 +8115,13 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u32 mask;
 	int ret;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return -EOPNOTSUPP;
 
@@ -8093,9 +8156,13 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u32 mask;
 	ssize_t ret;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return -EOPNOTSUPP;
 
@@ -8120,6 +8187,7 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
 static ssize_t
 nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u64 cookie;
 	bool eof;
 	ssize_t ret, size;
@@ -8127,6 +8195,9 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
 	size_t buflen;
 	u32 mask;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return 0;
 
Signature · 1 line
2.48.1
#1 lore raw

Hi Scott,

Quoted 8 lines · Scott Mayhew

The nfs inodes for referral anchors that have not yet been followed have their filehandles zeroed out.

Attempting to call getxattr() on one of these will cause the nfs client to send a GETATTR to the nfs server with the preceding PUTFH sans filehandle. The server will reply NFS4ERR_NOFILEHANDLE, leading to -EIO being returned to the application.

Quoted 8 lines

For example:

$ strace -e trace=getxattr getfattr -n system.nfs4_acl /mnt/t/ref
getxattr("/mnt/t/ref", "system.nfs4_acl", NULL, 0) = -1 EIO (Input/output error)
/mnt/t/ref: system.nfs4_acl: Input/output error
+++ exited with 1 +++

Have the xattr handlers return -ENODATA instead.

This looks like a lot of repeated code. I was wondering if there is a way to do this with a helper function that returns -ENODATA? Or could it be checked inside nfs4_proc_set_acl() / nfs4_proc_get_acl() / nfs4_server_supports_acls() to cut down on duplication?

Quoted 30 lines
---
 fs/nfs/nfs4proc.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
fs/nfs/nfs4proc.c +9 -0
index 970f28dbf253..a01592930370 100644
@@ -7933,6 +7933,11 @@ static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler,
 				   const char *key, const void *buf,
 				   size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_ACL);
 }
 
@@ -7940,11 +7945,21 @@ static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler,
 				   struct dentry *unused, struct inode *inode,
 				   const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

fs/nfs/nfs4proc.c static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, · line 7961

Quoted 10 lines
fs/nfs/nfs4proc.c +5 -0
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_ACL);
 }
 
 static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

Note that the return value of this function is a boolean, and not an integer, so callers probably won't care about a specific return value.

Quoted 24 lines
fs/nfs/nfs4proc.c +10 -0
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_ACL);
 }
 
@@ -7957,6 +7972,11 @@ static int nfs4_xattr_set_nfs4_dacl(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_DACL);
 }
 
@@ -7964,11 +7984,21 @@ static int nfs4_xattr_get_nfs4_dacl(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

fs/nfs/nfs4proc.c static int nfs4_xattr_get_nfs4_dacl(const struct xattr_handler *handler, · line 8000

Quoted 10 lines
fs/nfs/nfs4proc.c +5 -0
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_DACL);
 }
 
 static bool nfs4_xattr_list_nfs4_dacl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

Here's another boolean return type.

Quoted 24 lines
fs/nfs/nfs4proc.c +10 -0
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_DACL);
 }
 
@@ -7980,6 +8010,11 @@ static int nfs4_xattr_set_nfs4_sacl(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_SACL);
 }
 
@@ -7987,11 +8022,21 @@ static int nfs4_xattr_get_nfs4_sacl(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

fs/nfs/nfs4proc.c static int nfs4_xattr_get_nfs4_sacl(const struct xattr_handler *handler, · line 8038

Quoted 10 lines
fs/nfs/nfs4proc.c +5 -0
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_SACL);
 }
 
 static bool nfs4_xattr_list_nfs4_sacl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

Boolean return type.

Thanks,
Anna

Quoted 87 lines
fs/nfs/nfs4proc.c +27 -0
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_SACL);
 }
 
@@ -8005,6 +8050,11 @@ static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler,
 				     const char *key, const void *buf,
 				     size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (security_ismaclabel(key))
 		return nfs4_set_security_label(inode, buf, buflen);
 
@@ -8015,6 +8065,11 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 				     struct dentry *unused, struct inode *inode,
 				     const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (security_ismaclabel(key))
 		return nfs4_get_security_label(inode, buf, buflen);
 	return -EOPNOTSUPP;
@@ -8023,8 +8078,12 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 static ssize_t
 nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	int len = 0;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
 		len = security_inode_listsecurity(inode, list, list_len);
 		if (len >= 0 && list_len && len > list_len)
@@ -8056,9 +8115,13 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u32 mask;
 	int ret;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return -EOPNOTSUPP;
 
@@ -8093,9 +8156,13 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u32 mask;
 	ssize_t ret;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return -EOPNOTSUPP;
 
@@ -8120,6 +8187,7 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
 static ssize_t
 nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u64 cookie;
 	bool eof;
 	ssize_t ret, size;
@@ -8127,6 +8195,9 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
 	size_t buflen;
 	u32 mask;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return 0;
 
#2 lore raw
Quoted 18 lines · Anna Schumaker

Hi Scott,

Quoted 15 lines · Scott Mayhew

The nfs inodes for referral anchors that have not yet been followed have their filehandles zeroed out.

Attempting to call getxattr() on one of these will cause the nfs client to send a GETATTR to the nfs server with the preceding PUTFH sans filehandle. The server will reply NFS4ERR_NOFILEHANDLE, leading to -EIO being returned to the application.

For example:

$ strace -e trace=getxattr getfattr -n system.nfs4_acl /mnt/t/ref
getxattr("/mnt/t/ref", "system.nfs4_acl", NULL, 0) = -1 EIO (Input/output error)
/mnt/t/ref: system.nfs4_acl: Input/output error
+++ exited with 1 +++
Quoted 6 lines
Quoted 1 line

Have the xattr handlers return -ENODATA instead.

This looks like a lot of repeated code. I was wondering if there is a way to do this with a helper function that returns -ENODATA? Or could it be checked inside nfs4_proc_set_acl() / nfs4_proc_get_acl() / nfs4_server_supports_acls() to cut down on duplication?

I'll move the check down into nfs4_proc_set_acl() / nfs4_proc_get_acl().

Quoted 35 lines
Quoted 35 lines
---
 fs/nfs/nfs4proc.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
fs/nfs/nfs4proc.c +10 -0
index 970f28dbf253..a01592930370 100644
@@ -7933,6 +7933,11 @@ static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler,
 				   const char *key, const void *buf,
 				   size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_ACL);
 }
 
@@ -7940,11 +7945,21 @@ static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler,
 				   struct dentry *unused, struct inode *inode,
 				   const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_ACL);
 }
 
Quoted 9 lines

fs/nfs/nfs4proc.c static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, · line 7961

Quoted 6 lines
fs/nfs/nfs4proc.c +4 -0
 static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

Note that the return value of this function is a boolean, and not an integer, so callers probably won't care about a specific return value.

Doh! I blame the fact that I was fighting a severe head and chest cold last week. After a fresh look, I don't think we need to change the list handlers at all - those get called by the listxattr inode operation, which nfs_referral_inode_operations does not have.

-Scott

Quoted 166 lines
Quoted 25 lines
fs/nfs/nfs4proc.c +10 -0
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_ACL);
 }
 
@@ -7957,6 +7972,11 @@ static int nfs4_xattr_set_nfs4_dacl(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_DACL);
 }
 
@@ -7964,11 +7984,21 @@ static int nfs4_xattr_get_nfs4_dacl(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

fs/nfs/nfs4proc.c static int nfs4_xattr_get_nfs4_dacl(const struct xattr_handler *handler, · line 8000

Quoted 10 lines
fs/nfs/nfs4proc.c +5 -0
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_DACL);
 }
 
 static bool nfs4_xattr_list_nfs4_dacl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

Here's another boolean return type.

Quoted 24 lines
fs/nfs/nfs4proc.c +10 -0
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_DACL);
 }
 
@@ -7980,6 +8010,11 @@ static int nfs4_xattr_set_nfs4_sacl(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	return nfs4_proc_set_acl(inode, buf, buflen, NFS4ACL_SACL);
 }
 
@@ -7987,11 +8022,21 @@ static int nfs4_xattr_get_nfs4_sacl(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

fs/nfs/nfs4proc.c static int nfs4_xattr_get_nfs4_sacl(const struct xattr_handler *handler, · line 8038

Quoted 10 lines
fs/nfs/nfs4proc.c +5 -0
+
 	return nfs4_proc_get_acl(inode, buf, buflen, NFS4ACL_SACL);
 }
 
 static bool nfs4_xattr_list_nfs4_sacl(struct dentry *dentry)
 {
+	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;

Boolean return type.

Thanks,
Anna

Quoted 87 lines
fs/nfs/nfs4proc.c +27 -0
+
 	return nfs4_server_supports_acls(NFS_SB(dentry->d_sb), NFS4ACL_SACL);
 }
 
@@ -8005,6 +8050,11 @@ static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler,
 				     const char *key, const void *buf,
 				     size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (security_ismaclabel(key))
 		return nfs4_set_security_label(inode, buf, buflen);
 
@@ -8015,6 +8065,11 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 				     struct dentry *unused, struct inode *inode,
 				     const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
+
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (security_ismaclabel(key))
 		return nfs4_get_security_label(inode, buf, buflen);
 	return -EOPNOTSUPP;
@@ -8023,8 +8078,12 @@ static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
 static ssize_t
 nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	int len = 0;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) {
 		len = security_inode_listsecurity(inode, list, list_len);
 		if (len >= 0 && list_len && len > list_len)
@@ -8056,9 +8115,13 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
 				    const char *key, const void *buf,
 				    size_t buflen, int flags)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u32 mask;
 	int ret;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return -EOPNOTSUPP;
 
@@ -8093,9 +8156,13 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
 				    struct dentry *unused, struct inode *inode,
 				    const char *key, void *buf, size_t buflen)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u32 mask;
 	ssize_t ret;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return -EOPNOTSUPP;
 
@@ -8120,6 +8187,7 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
 static ssize_t
 nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
 {
+	struct nfs_fh *fh = NFS_FH(inode);
 	u64 cookie;
 	bool eof;
 	ssize_t ret, size;
@@ -8127,6 +8195,9 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
 	size_t buflen;
 	u32 mask;
 
+	if (unlikely(fh->size == 0))
+		return -ENODATA;
+
 	if (!nfs_server_capable(inode, NFS_CAP_XATTR))
 		return 0;