llvm / llvm/llvm-project

[libc] Add support for SYS_fchmodat2 in fchmodat

Open
#223,953 1 comment 0 reactions 0 assignees View on GitHub
libc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Description

In #223165 (resolving #223072), `fchmodat` was updated to reject non-zero flags with `ENOTSUP` and pass 3 arguments to `SYS_fchmodat`, as the traditional Linux `SYS_fchmodat` system call does not accept a `flags` argument.

Linux kernel 6.6 introduced `SYS_fchmodat2` (system call 452 on most architectures), which accepts a 4th `flags` argument (`int fchmodat2(int dirfd, const char *pathname, mode_t mode, unsigned int flags)`). This enables support for flags like `AT_SYMLINK_NOFOLLOW` and `AT_EMPTY_PATH`.

As discussed in https://github.com/llvm/llvm-project/pull/223165#issuecomment-5694545879, we should add support for `SYS_fchmodat2` in `llvm-libc`:
- Update the Linux syscall wrapper for `fchmodat` to support passing flags via `SYS_fchmodat2` when available.
- When `SYS_fchmodat2` is not defined (e.g. `#ifndef SYS_fchmodat2`), fallback to `SYS_fchmodat`, verifying that `flags == 0` and returning `ENOTSUP` if non-zero.
- Optionally handle runtime fallback to `SYS_fchmodat` if `SYS_fchmodat2` returns `ENOSYS` when running against older kernels.

Contributor guide

Open the contributing guide

Research direction

Start with the Linux syscall wrapper for fchmodat and inspect how it currently calls SYS_fchmodat. Verify the SYS_fchmodat2 path passes flags when available, while the fallback rejects non-zero flags with ENOTSUP; optionally confirm runtime ENOSYS fallback behavior on older kernels.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.