[PATCH 2/3] pidfs: return -ENODATA from pidfs_xattr_get() when no xattrs exist

Christian Brauner
2026-04-20T13:32:48Z

When no xattrs have ever been set on a pidfd (attr->xattrs is NULL),
pidfs_xattr_get() returns 0. The VFS interprets a return value of 0 as
"xattr exists with a zero-length value", causing getxattr() to report
success for non-existent xattrs.

Return -ENODATA instead which is consistent with what simple_xattr_get()
returns when an xattr is not found.

Fixes: 5c1e4b9db95c ("pidfs: support xattrs on pidfds")
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/pidfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index 11eb53f3e50a..2ab8fd2646f0 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -1023,7 +1023,7 @@ static int pidfs_xattr_get(const struct xattr_handler *handler,

xattrs = READ_ONCE(attr->xattrs);
if (!xattrs)
- return 0;
+ return -ENODATA;

name = xattr_full_name(handler, suffix);
return simple_xattr_get(xattrs, name, value, size);

--
2.47.3