From: Scott Mayhew <smayhew@redhat.com>
To: trondmy@kernel.org, anna@kernel.org
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH] NFSv4: xattr handlers should check for absent nfs filehandles
Date: Fri, 11 Apr 2025 16:16:12 -0400 [thread overview]
Message-ID: <20250411201612.2993634-1-smayhew@redhat.com> (raw)
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.
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
fs/nfs/nfs4proc.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 970f28dbf253..a01592930370 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -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;
--
2.48.1
next reply other threads:[~2025-04-11 20:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 20:16 Scott Mayhew [this message]
2025-04-14 21:07 ` [PATCH] NFSv4: xattr handlers should check for absent nfs filehandles Anna Schumaker
2025-04-15 19:56 ` Scott Mayhew
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250411201612.2993634-1-smayhew@redhat.com \
--to=smayhew@redhat.com \
--cc=anna@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox