Re: [PATCH 0/4] xattr: fix AT_FDCWD handling
From: Andreas Gruenbacher
Date: Mon Nov 30 2026 - 13:06:02 EST
On Mon, 30 Nov 2026 at 16:52, Christian Brauner <brauner@xxxxxxxxxx> wrote:
> Two bugs in the AT_FDCWD handling of the xattr system calls while
> reviewing Andreas' patch that lets *xattrat() accept O_PATH file
> descriptors (cf. [1]) surfaced. Both predate that patch:
>
> * fsetxattr() and fgetxattr() operate on the current working directory
> when passed AT_FDCWD instead of failing with EBADF. They're
> implemented on top of the *xattrat() helpers and since commit
> f520bed25d17 ("fs/xattr: Fix handling of AT_FDCWD in setxattrat(2) and
> getxattrat(2)") those resolve AT_FDCWD with an empty path to the
> current working directory. That's a regression since v6.15.
>
> * listxattrat() and removexattrat() fail with EBADF when called with
> AT_FDCWD, an empty path and AT_EMPTY_PATH while setxattrat() and
> getxattrat() operate on the current working directory. They never got
> the same fix.
>
> The f*xattr() system calls now resolve the file descriptor themselves
> like fchmod() and fchown() do instead of going through the *xattrat()
> helpers. That fixes the first bug and leaves the helpers to the path
> based system calls. With this Andreas' patch doesn't need the
> fd_maybe_raw class anymore as the helpers can simply use CLASS(fd_raw).
> I've reworked it accordingly and it's the last patch in this series.
>
> The new selftest covers both bugs.
Thanks, this is all looking good.
Andreas
> [1]: https://lore.kernel.org/20260722151023.1308069-1-agruenba@xxxxxxxxxx
>
> Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
> ---
> Andreas Gruenbacher (1):
> xattrat: accept empty O_PATH file descriptors
>
> Christian Brauner (3):
> xattr: don't route f*xattr() through the *xattrat() helpers
> xattr: let listxattrat() and removexattrat() handle AT_FDCWD
> selftests/xattr: add AT_FDCWD tests
>
> fs/xattr.c | 73 +++++-
> .../testing/selftests/filesystems/xattr/.gitignore | 1 +
> tools/testing/selftests/filesystems/xattr/Makefile | 3 +-
> .../selftests/filesystems/xattr/xattr_fdcwd_test.c | 265 +++++++++++++++++++++
> 4 files changed, 330 insertions(+), 12 deletions(-)
> ---
> base-commit: 4a3b05a191ed84099d4ffaff7d29f73f08d27408
> change-id: 20261130-work-xattr-at_fdcwd-misc-7b6ba7c0bc79
>