[13/23] linux: Add fchroot

Message ID 20261103143252.3957485-14-adhemerval.zanella@linaro.org (mailing list archive)
State Superseded
Headers
Series Linux 7.2/7.3 updates and new system call wrappers |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 fail Patch failed to apply

Commit Message

Adhemerval Zanella Netto Nov. 3, 2026, 2:32 p.m. UTC
  The fchroot system call (commit
79d27fd718545db4731691e0a77e51d27dc1a41e, Linux 7.3) changes the root
directory of the calling process to the directory referred to by a
file descriptor.  The fd argument can also be FD_FAILFS_ROOT, in which
case all subsequent absolute file name lookups fail, unprivileged
processes can do this if no_new_privs is set and the file system
information is not shared with other threads (so it fails with EINVAL
in a multithreaded process created with pthread_create).

The wrapper follows the kernel signature:

  int fchroot (int fd, unsigned int flags);

Checked on x86_64-linux-gnu.
---
 NEWS                                          |   3 +
 sysdeps/unix/sysv/linux/Makefile              |   1 +
 sysdeps/unix/sysv/linux/Versions              |   1 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |   1 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/arc/libc.abilist      |   1 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/bits/unistd_ext.h     |   6 +
 sysdeps/unix/sysv/linux/csky/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |   1 +
 .../sysv/linux/loongarch/ilp32/libc.abilist   |   1 +
 .../sysv/linux/loongarch/lp64/libc.abilist    |   1 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |   1 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |   1 +
 .../sysv/linux/microblaze/be/libc.abilist     |   1 +
 .../sysv/linux/microblaze/le/libc.abilist     |   1 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |   1 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |   1 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |   1 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/or1k/libc.abilist     |   1 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |   1 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |   1 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |   1 +
 .../linux/powerpc/powerpc64/le/libc.abilist   |   1 +
 .../unix/sysv/linux/riscv/rv32/libc.abilist   |   1 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |   1 +
 sysdeps/unix/sysv/linux/s390/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |   1 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |   1 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |   1 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |   1 +
 sysdeps/unix/sysv/linux/syscalls.list         |   1 +
 sysdeps/unix/sysv/linux/tst-fchroot.c         | 114 ++++++++++++++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |   1 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |   1 +
 38 files changed, 158 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/tst-fchroot.c
  

Comments

Florian Weimer Nov. 5, 2026, 12:26 p.m. UTC | #1
* Adhemerval Zanella:

> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
> index a541b378d03..6597435ace7 100644
> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>  #endif
>  
> +/* Change the root directory of the calling process to the directory
> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
> +   in which case all subsequent absolute file name lookups fail.  FLAGS
> +   must be zero.  */
> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
> +
>  #endif /* __USE_GNU  */

CRIU defines _GNU_SOURCE, and it has:

criu/files.c:#include <unistd.h>

criu/files.c:static int fchroot(int fd)
criu/files.c-{
criu/files.c-   /*
criu/files.c-    * There's no such thing in syscalls. We can emulate
criu/files.c-    * it using fchdir()
criu/files.c-    */
criu/files.c-
criu/files.c-   if (fchdir(fd) < 0) {
criu/files.c-           pr_perror("Can't chdir to proc");
criu/files.c-           return -1;
criu/files.c-   }
criu/files.c-
criu/files.c-   pr_debug("Going to chroot into /proc/self/fd/%d\n", fd);
criu/files.c-   return chroot(".");
criu/files.c-}

So it breaks the build.  I think that's true for

I wonder if we should start defining macros like

#define _LIBC_HAS_FUNCTION_fchroot

in some header file as part of a general push for more system call
wrappers.

Thanks,
Florian
  
Adhemerval Zanella Netto Nov. 5, 2026, 2:02 p.m. UTC | #2
On 05/11/26 09:26, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> index a541b378d03..6597435ace7 100644
>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>  #endif
>>  
>> +/* Change the root directory of the calling process to the directory
>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>> +   must be zero.  */
>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>> +
>>  #endif /* __USE_GNU  */
> 
> CRIU defines _GNU_SOURCE, and it has:
> 
> criu/files.c:#include <unistd.h>
> 
> criu/files.c:static int fchroot(int fd)
> criu/files.c-{
> criu/files.c-   /*
> criu/files.c-    * There's no such thing in syscalls. We can emulate
> criu/files.c-    * it using fchdir()
> criu/files.c-    */
> criu/files.c-
> criu/files.c-   if (fchdir(fd) < 0) {
> criu/files.c-           pr_perror("Can't chdir to proc");
> criu/files.c-           return -1;
> criu/files.c-   }
> criu/files.c-
> criu/files.c-   pr_debug("Going to chroot into /proc/self/fd/%d\n", fd);
> criu/files.c-   return chroot(".");
> criu/files.c-}
> 
> So it breaks the build.  I think that's true for

I think you ended the sentence here.

> 
> I wonder if we should start defining macros like
> 
> #define _LIBC_HAS_FUNCTION_fchroot
> 
> in some header file as part of a general push for more system call
> wrappers.

Please no, this adds another set of defines we will need to keep tracking
of.

For the CRIU, it would require to add a configure check. I don't think it
should be a blocked for this wrapper.

> Thanks,
> Florian
  
Andreas Schwab Nov. 5, 2026, 2:31 p.m. UTC | #3
On Nov 05 2026, Florian Weimer wrote:

> * Adhemerval Zanella:
>
>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> index a541b378d03..6597435ace7 100644
>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>  #endif
>>  
>> +/* Change the root directory of the calling process to the directory
>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>> +   must be zero.  */
>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>> +
>>  #endif /* __USE_GNU  */
>
> CRIU defines _GNU_SOURCE, and it has:
>
> criu/files.c:#include <unistd.h>
>
> criu/files.c:static int fchroot(int fd)

BSD also has fchroot without the flags.  Should the one above be called
fchroot2, or should the flags be dropped for now?
  
Adhemerval Zanella Netto Nov. 5, 2026, 4:28 p.m. UTC | #4
On 05/11/26 11:31, Andreas Schwab wrote:
> On Nov 05 2026, Florian Weimer wrote:
> 
>> * Adhemerval Zanella:
>>
>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>> index a541b378d03..6597435ace7 100644
>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>  #endif
>>>  
>>> +/* Change the root directory of the calling process to the directory
>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>> +   must be zero.  */
>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>> +
>>>  #endif /* __USE_GNU  */
>>
>> CRIU defines _GNU_SOURCE, and it has:
>>
>> criu/files.c:#include <unistd.h>
>>
>> criu/files.c:static int fchroot(int fd)
> 
> BSD also has fchroot without the flags.  Should the one above be called
> fchroot2, or should the flags be dropped for now?
> 

This is annoying, but doable. We can add both fchroot as SYS_fchroot with
flags set to 0 and fchroot2 with Linux signature. I don't have a strong
opinion.
  
Florian Weimer Nov. 5, 2026, 4:42 p.m. UTC | #5
* Andreas Schwab:

> On Nov 05 2026, Florian Weimer wrote:
>
>> * Adhemerval Zanella:
>>
>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>> index a541b378d03..6597435ace7 100644
>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>  #endif
>>>  
>>> +/* Change the root directory of the calling process to the directory
>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>> +   must be zero.  */
>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>> +
>>>  #endif /* __USE_GNU  */
>>
>> CRIU defines _GNU_SOURCE, and it has:
>>
>> criu/files.c:#include <unistd.h>
>>
>> criu/files.c:static int fchroot(int fd)
>
> BSD also has fchroot without the flags.

So does Hurd.

> Should the one above be called fchroot2, or should the flags be
> dropped for now?

It won't fix the fchroot build failure.  It's surprisingly rare, though:

<https://codesearch.debian.net/search?q=%28%5E%7Cint%5Cs*%29fchroot%5Cs*%5C%28&literal=0>

I just got lucky, I didn't find it through Debian Code Search, just by
consulting the CRIU source code.

I don't think we should aim for compatibility with Hurd/BSD if Linux has
something else.  On the other hand, if POSIX standardizes fchroot in the
one-argument form, we'll have a problem.

Thanks,
Florian
  
Florian Weimer Nov. 5, 2026, 4:44 p.m. UTC | #6
* Adhemerval Zanella Netto:

>> I wonder if we should start defining macros like
>> 
>> #define _LIBC_HAS_FUNCTION_fchroot
>> 
>> in some header file as part of a general push for more system call
>> wrappers.
>
> Please no, this adds another set of defines we will need to keep tracking
> of.

If it's just a plain #define, I think we could generate that from the
DSO itself.

If we need to identify the header for the declaration or the argument
count, it's less straightforward to auto-generate, but still possible.

Thanks,
Florian
  
Adhemerval Zanella Netto Nov. 5, 2026, 4:59 p.m. UTC | #7
On 05/11/26 13:42, Florian Weimer wrote:
> * Andreas Schwab:
> 
>> On Nov 05 2026, Florian Weimer wrote:
>>
>>> * Adhemerval Zanella:
>>>
>>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>> index a541b378d03..6597435ace7 100644
>>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>>  #endif
>>>>  
>>>> +/* Change the root directory of the calling process to the directory
>>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>>> +   must be zero.  */
>>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>>> +
>>>>  #endif /* __USE_GNU  */
>>>
>>> CRIU defines _GNU_SOURCE, and it has:
>>>
>>> criu/files.c:#include <unistd.h>
>>>
>>> criu/files.c:static int fchroot(int fd)
>>
>> BSD also has fchroot without the flags.
> 
> So does Hurd.
> 
>> Should the one above be called fchroot2, or should the flags be
>> dropped for now?
> 
> It won't fix the fchroot build failure.  It's surprisingly rare, though:

What do you mean by it won't fix the build failure? We can provide both,
although it still be confusing that on Linux you have 2 functions.

> 
> <https://codesearch.debian.net/search?q=%28%5E%7Cint%5Cs*%29fchroot%5Cs*%5C%28&literal=0>
> 
> I just got lucky, I didn't find it through Debian Code Search, just by
> consulting the CRIU source code.
> 
> I don't think we should aim for compatibility with Hurd/BSD if Linux has
> something else.  On the other hand, if POSIX standardizes fchroot in the
> one-argument form, we'll have a problem.
> 
> Thanks,
> Florian
  
Florian Weimer Nov. 5, 2026, 5:02 p.m. UTC | #8
* Adhemerval Zanella Netto:

> On 05/11/26 13:42, Florian Weimer wrote:
>> * Andreas Schwab:
>> 
>>> On Nov 05 2026, Florian Weimer wrote:
>>>
>>>> * Adhemerval Zanella:
>>>>
>>>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>> index a541b378d03..6597435ace7 100644
>>>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>>>  #endif
>>>>>  
>>>>> +/* Change the root directory of the calling process to the directory
>>>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>>>> +   must be zero.  */
>>>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>>>> +
>>>>>  #endif /* __USE_GNU  */
>>>>
>>>> CRIU defines _GNU_SOURCE, and it has:
>>>>
>>>> criu/files.c:#include <unistd.h>
>>>>
>>>> criu/files.c:static int fchroot(int fd)
>>>
>>> BSD also has fchroot without the flags.
>> 
>> So does Hurd.
>> 
>>> Should the one above be called fchroot2, or should the flags be
>>> dropped for now?
>> 
>> It won't fix the fchroot build failure.  It's surprisingly rare, though:
>
> What do you mean by it won't fix the build failure? We can provide both,
> although it still be confusing that on Linux you have 2 functions.

With the single-argument version, it's still a static definition folling
an extern declaration, which is a compiler error.

Thanks,
Florian
  
Collin Funk Nov. 5, 2026, 5:26 p.m. UTC | #9
Florian Weimer <fweimer@redhat.com> writes:

> * Andreas Schwab:
>
>> On Nov 05 2026, Florian Weimer wrote:
>>
>>> * Adhemerval Zanella:
>>>
>>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>> index a541b378d03..6597435ace7 100644
>>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>>  #endif
>>>>  
>>>> +/* Change the root directory of the calling process to the directory
>>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>>> +   must be zero.  */
>>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>>> +
>>>>  #endif /* __USE_GNU  */
>>>
>>> CRIU defines _GNU_SOURCE, and it has:
>>>
>>> criu/files.c:#include <unistd.h>
>>>
>>> criu/files.c:static int fchroot(int fd)
>>
>> BSD also has fchroot without the flags.
>
> So does Hurd.

And Solaris [1].

I have been wanting this for the 'chroot' command from GNU coreutils for
a while. If my memory serves me correctly, it is only available on
NetBSD and not the other BSDs. For that reason, I didn't bother making
use of it. I was not aware it was supported on Hurd, and only found out
about Solaris recently.

>> Should the one above be called fchroot2, or should the flags be
>> dropped for now?
>
> It won't fix the fchroot build failure.  It's surprisingly rare, though:
>
> <https://codesearch.debian.net/search?q=%28%5E%7Cint%5Cs*%29fchroot%5Cs*%5C%28&literal=0>
>
> I just got lucky, I didn't find it through Debian Code Search, just by
> consulting the CRIU source code.
>
> I don't think we should aim for compatibility with Hurd/BSD if Linux has
> something else.  On the other hand, if POSIX standardizes fchroot in the
> one-argument form, we'll have a problem.

Yes. I was pleasantly suprised to see the system call added in Linux
7.3. But I find it a bit annoying that a different function signature
than everyone else...

Collin

[1] https://docs.oracle.com/cd/E86824_01/html/E54765/fchroot-2.html
  
Adhemerval Zanella Netto Nov. 5, 2026, 6:44 p.m. UTC | #10
On 05/11/26 14:02, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
>> On 05/11/26 13:42, Florian Weimer wrote:
>>> * Andreas Schwab:
>>>
>>>> On Nov 05 2026, Florian Weimer wrote:
>>>>
>>>>> * Adhemerval Zanella:
>>>>>
>>>>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>>> index a541b378d03..6597435ace7 100644
>>>>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>>>>  #endif
>>>>>>  
>>>>>> +/* Change the root directory of the calling process to the directory
>>>>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>>>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>>>>> +   must be zero.  */
>>>>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>>>>> +
>>>>>>  #endif /* __USE_GNU  */
>>>>>
>>>>> CRIU defines _GNU_SOURCE, and it has:
>>>>>
>>>>> criu/files.c:#include <unistd.h>
>>>>>
>>>>> criu/files.c:static int fchroot(int fd)
>>>>
>>>> BSD also has fchroot without the flags.
>>>
>>> So does Hurd.
>>>
>>>> Should the one above be called fchroot2, or should the flags be
>>>> dropped for now?
>>>
>>> It won't fix the fchroot build failure.  It's surprisingly rare, though:
>>
>> What do you mean by it won't fix the build failure? We can provide both,
>> although it still be confusing that on Linux you have 2 functions.
> 
> With the single-argument version, it's still a static definition folling
> an extern declaration, which is a compiler error.
Right, but on this case the usual expected way is a configure check if
the system library already provides it.  Having this as a blocker will
make *any* new syscall wrappers really hard to justify.
  
Adhemerval Zanella Netto Nov. 5, 2026, 6:46 p.m. UTC | #11
On 05/11/26 14:26, Collin Funk wrote:
> Florian Weimer <fweimer@redhat.com> writes:
> 
>> * Andreas Schwab:
>>
>>> On Nov 05 2026, Florian Weimer wrote:
>>>
>>>> * Adhemerval Zanella:
>>>>
>>>>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>> index a541b378d03..6597435ace7 100644
>>>>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>>>>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>>>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>>>>  #endif
>>>>>  
>>>>> +/* Change the root directory of the calling process to the directory
>>>>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>>>>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>>>>> +   must be zero.  */
>>>>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>>>>> +
>>>>>  #endif /* __USE_GNU  */
>>>>
>>>> CRIU defines _GNU_SOURCE, and it has:
>>>>
>>>> criu/files.c:#include <unistd.h>
>>>>
>>>> criu/files.c:static int fchroot(int fd)
>>>
>>> BSD also has fchroot without the flags.
>>
>> So does Hurd.
> 
> And Solaris [1].
> 
> I have been wanting this for the 'chroot' command from GNU coreutils for
> a while. If my memory serves me correctly, it is only available on
> NetBSD and not the other BSDs. For that reason, I didn't bother making
> use of it. I was not aware it was supported on Hurd, and only found out
> about Solaris recently.

It was added on FreeBSD 15 as well [1].

[1] https://man.freebsd.org/cgi/man.cgi?query=fchroot&apropos=0&sektion=0&manpath=FreeBSD+15.1-RELEASE+and+Ports.quarterly&format=html

> 
>>> Should the one above be called fchroot2, or should the flags be
>>> dropped for now?
>>
>> It won't fix the fchroot build failure.  It's surprisingly rare, though:
>>
>> <https://codesearch.debian.net/search?q=%28%5E%7Cint%5Cs*%29fchroot%5Cs*%5C%28&literal=0>
>>
>> I just got lucky, I didn't find it through Debian Code Search, just by
>> consulting the CRIU source code.
>>
>> I don't think we should aim for compatibility with Hurd/BSD if Linux has
>> something else.  On the other hand, if POSIX standardizes fchroot in the
>> one-argument form, we'll have a problem.
> 
> Yes. I was pleasantly suprised to see the system call added in Linux
> 7.3. But I find it a bit annoying that a different function signature
> than everyone else...
> 

I think we can keep using the BSD/Solaris/Hurd prototype and add a fchroot2
with flags. Seems the lest disruptive way imho.

> Collin
> 
> [1] https://docs.oracle.com/cd/E86824_01/html/E54765/fchroot-2.html
  
Andreas Schwab Nov. 5, 2026, 9:04 p.m. UTC | #12
On Nov 05 2026, Florian Weimer wrote:

> On the other hand, if POSIX standardizes fchroot

That is unlikely, they removed chroot in the 2001 edition.
  
Florian Weimer Nov. 6, 2026, 2:14 p.m. UTC | #13
* Andreas Schwab:

> On Nov 05 2026, Florian Weimer wrote:
>
>> On the other hand, if POSIX standardizes fchroot
>
> That is unlikely, they removed chroot in the 2001 edition.

Oh.  Then I would say we should go with the two-argument Linux version.

Thanks,
Florian
  
Adhemerval Zanella Netto Nov. 6, 2026, 2:52 p.m. UTC | #14
On 06/11/26 11:14, Florian Weimer wrote:
> * Andreas Schwab:
> 
>> On Nov 05 2026, Florian Weimer wrote:
>>
>>> On the other hand, if POSIX standardizes fchroot
>>
>> That is unlikely, they removed chroot in the 2001 edition.
> 
> Oh.  Then I would say we should go with the two-argument Linux version.
With the current fchroot name or do you prefer a fchroot2 ?
  
Florian Weimer Nov. 6, 2026, 2:55 p.m. UTC | #15
* Adhemerval Zanella Netto:

> On 06/11/26 11:14, Florian Weimer wrote:
>> * Andreas Schwab:
>> 
>>> On Nov 05 2026, Florian Weimer wrote:
>>>
>>>> On the other hand, if POSIX standardizes fchroot
>>>
>>> That is unlikely, they removed chroot in the 2001 edition.
>> 
>> Oh.  Then I would say we should go with the two-argument Linux version.

> With the current fchroot name or do you prefer a fchroot2 ?

I prefer fchroot, matching the system call name.

Thanks,
Florian
  

Patch

diff --git a/NEWS b/NEWS
index a414adf3cc5..cf11fe1387a 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,9 @@  Major new features:
   <sys/membarrier.h> header.  It issues memory barriers on a set of
   threads.
 
+* On Linux, the fchroot function has been added.  It changes the root
+  directory to the directory referred to by a file descriptor.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 7d20aa5e324..933ccd2cc8b 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -204,6 +204,7 @@  tests += \
   tst-epoll \
   tst-epoll-ioctls \
   tst-fanotify \
+  tst-fchroot \
   tst-fdopendir-o_path \
   tst-getauxval \
   tst-gettid \
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 61696fad7fc..7062d96902c 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -344,6 +344,7 @@  libc {
     openat2;
   }
   GLIBC_2.45 {
+    fchroot;
     membarrier;
   }
   GLIBC_PRIVATE {
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index 4d09997cce3..a644d272922 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2775,6 +2775,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 8bd9a672d4b..f473976a182 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -3122,6 +3122,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist
index da45cbf90e8..c0689263513 100644
--- a/sysdeps/unix/sysv/linux/arc/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arc/libc.abilist
@@ -2536,6 +2536,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist
index 7e34bc91516..3a84f9ea96a 100644
--- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist
@@ -2828,6 +2828,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist
index f6cf2c520bc..318d6d4f7e6 100644
--- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist
@@ -2825,6 +2825,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
index a541b378d03..6597435ace7 100644
--- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
+++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
@@ -47,4 +47,10 @@  extern __pid_t gettid (void) __THROW;
 # define CLOSE_RANGE_CLOEXEC (1U << 2)
 #endif
 
+/* Change the root directory of the calling process to the directory
+   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
+   in which case all subsequent absolute file name lookups fail.  FLAGS
+   must be zero.  */
+extern int fchroot (int __fd, unsigned int __flags) __THROW;
+
 #endif /* __USE_GNU  */
diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist
index 49e831b815f..7f15dcd3e39 100644
--- a/sysdeps/unix/sysv/linux/csky/libc.abilist
+++ b/sysdeps/unix/sysv/linux/csky/libc.abilist
@@ -2812,6 +2812,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 27669e04a3c..64f4c1cb3c9 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -2849,6 +2849,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 307494d3ba8..22da20fd9f7 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -3032,6 +3032,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist
index d1807e45e1b..0dfb84b561a 100644
--- a/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/loongarch/ilp32/libc.abilist
@@ -2287,6 +2287,7 @@  GLIBC_2.44 wprintf F
 GLIBC_2.44 write F
 GLIBC_2.44 writev F
 GLIBC_2.44 wscanf F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
index f81e37f3cc6..c9c808dd9fe 100644
--- a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist
@@ -2296,6 +2296,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index a1315c2dd48..b89aa74577b 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -2808,6 +2808,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index 5b62f2b181e..094f94e31c8 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -2975,6 +2975,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
index 44f42d6de64..51ea5272cc9 100644
--- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
@@ -2861,6 +2861,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
index d2bcf51ac02..a3ff87070cb 100644
--- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
@@ -2858,6 +2858,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index cfb821bb24e..4aaa5e69891 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -2938,6 +2938,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index b097351cbdc..51308b1ca36 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -2936,6 +2936,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 492c23108e5..5807025a499 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -2944,6 +2944,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index 92537db667e..d904de5d547 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -2846,6 +2846,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist
index 1a24723bb9a..758fbd44afe 100644
--- a/sysdeps/unix/sysv/linux/or1k/libc.abilist
+++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist
@@ -2286,6 +2286,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index ab7f9ae5e70..47e33b3e912 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -3165,6 +3165,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index fadc9c42b30..836397c97d2 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -3210,6 +3210,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
index cf24061bfdb..a97a51ea267 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
@@ -2919,6 +2919,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
index c4975eb3552..7cee2945247 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
@@ -2995,6 +2995,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
index f18093a6236..7f0b8935eb0 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist
@@ -2539,6 +2539,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index 15c7b728f6a..5b17e99686f 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2739,6 +2739,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/s390/libc.abilist b/sysdeps/unix/sysv/linux/s390/libc.abilist
index ad14f4cc0a8..58af3b58aed 100644
--- a/sysdeps/unix/sysv/linux/s390/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/libc.abilist
@@ -2956,6 +2956,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist
index 3f2d470ad0d..3a22aaf088d 100644
--- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist
@@ -2855,6 +2855,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist
index e69c1d4ff48..86b587c163c 100644
--- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist
@@ -2852,6 +2852,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 42bef5fefa5..a92c3bfe01c 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -3186,6 +3186,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index 73490c21bf7..d16ec5a885a 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -2822,6 +2822,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 77b1c72513d..195c3c8d09b 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -10,6 +10,7 @@  epoll_create1	EXTRA	epoll_create1	i:i	epoll_create1
 epoll_ctl	EXTRA	epoll_ctl	i:iiip	epoll_ctl
 eventfd		EXTRA	eventfd2	i:ii	eventfd
 execve		-	execve		i:spp	__execve	execve
+fchroot		EXTRA	fchroot		i:iU	fchroot
 flock		-	flock		i:ii	__flock		flock
 fsconfig	EXTRA	fsconfig	i:iUsNi	fsconfig
 fsmount		EXTRA	fsmount		i:iUU	fsmount
diff --git a/sysdeps/unix/sysv/linux/tst-fchroot.c b/sysdeps/unix/sysv/linux/tst-fchroot.c
new file mode 100644
index 00000000000..93444d7c9a9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-fchroot.c
@@ -0,0 +1,114 @@ 
+/* Basic tests for Linux fchroot.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+#include <support/check.h>
+#include <support/namespace.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+
+#define MARKER "fchroot-marker"
+
+static char *temp_dir;
+static char *marker_path;
+
+static void
+do_prepare (int argc, char *argv[])
+{
+  temp_dir = support_create_temp_directory ("tst-fchroot.");
+  marker_path = xasprintf ("%s/%s", temp_dir, MARKER);
+  add_temp_file (marker_path);
+  xclose (xopen (marker_path, O_WRONLY | O_CREAT | O_EXCL, 0600));
+}
+#define PREPARE do_prepare
+
+/* Move the root to failfs.  Unprivileged processes can do this if
+   no_new_privs is set.  */
+static void
+change_root_failfs (void *closure)
+{
+  TEST_COMPARE (prctl (PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0), 0);
+  if (fchroot (FD_FAILFS_ROOT, 0) != 0)
+    {
+      /* An unprivileged process which is already in a chroot cannot escape
+	 it this way.  */
+      TEST_COMPARE (errno, EPERM);
+      puts ("info: cannot change the root to failfs");
+      return;
+    }
+
+  /* Absolute file name lookups now fail.  */
+  TEST_COMPARE (open ("/", O_RDONLY | O_DIRECTORY), -1);
+  TEST_COMPARE (errno, EOPNOTSUPP);
+}
+
+/* Change the root to TEMP_DIR, which requires CAP_SYS_CHROOT.  */
+static void
+change_root (void *closure)
+{
+  int dfd = xopen (temp_dir, O_RDONLY | O_DIRECTORY, 0);
+  TEST_COMPARE (fchroot (dfd, 0), 0);
+  xclose (dfd);
+
+  /* The marker file is now at the root.  */
+  TEST_COMPARE (access ("/" MARKER, F_OK), 0);
+}
+
+static int
+do_test (void)
+{
+  int dfd = xopen (temp_dir, O_RDONLY | O_DIRECTORY, 0);
+
+  /* FLAGS must be zero.  */
+  TEST_COMPARE (fchroot (dfd, 1), -1);
+  if (errno == ENOSYS)
+    FAIL_UNSUPPORTED ("fchroot is not supported by the kernel");
+  TEST_COMPARE (errno, EINVAL);
+
+  TEST_COMPARE (fchroot (-1, 0), -1);
+  TEST_COMPARE (errno, EBADF);
+
+  {
+    int fd = xopen (marker_path, O_RDONLY, 0);
+    TEST_COMPARE (fchroot (fd, 0), -1);
+    TEST_COMPARE (errno, ENOTDIR);
+    xclose (fd);
+  }
+
+  support_isolate_in_subprocess (change_root_failfs, NULL);
+
+  support_become_root ();
+  if (support_can_chroot ())
+    support_isolate_in_subprocess (change_root, NULL);
+  else
+    {
+      TEST_COMPARE (fchroot (dfd, 0), -1);
+      TEST_COMPARE (errno, EPERM);
+      puts ("info: cannot change the root to a directory");
+    }
+
+  xclose (dfd);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 0ca23d8d22a..38ff1a7e879 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -2771,6 +2771,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 6add9657b39..85846f59941 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2790,6 +2790,7 @@  GLIBC_2.43 memset_explicit F
 GLIBC_2.43 mseal F
 GLIBC_2.43 openat2 F
 GLIBC_2.43 umaxabs F
+GLIBC_2.45 fchroot F
 GLIBC_2.45 membarrier F
 GLIBC_2.45 posix_spawn_file_actions_addchdir F
 GLIBC_2.45 posix_spawn_file_actions_addfchdir F