Bug 507873 - fchmodat fchmodat2 should handle AT_FDCWD and absolute paths
Summary: fchmodat fchmodat2 should handle AT_FDCWD and absolute paths
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: 3.25 GIT
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: mcermak
URL:
Keywords:
Depends on:
Blocks: 506971
  Show dependency treegraph
 
Reported: 2025-08-04 23:35 UTC by Mark Wielaard
Modified: 2025-08-06 17:10 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
proposed patch (2.79 KB, patch)
2025-08-05 13:27 UTC, mcermak
Details
proposed patch (3.37 KB, patch)
2025-08-05 15:37 UTC, mcermak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2025-08-04 23:35:11 UTC
There are two syscalls fchmodat and fchmodat2 but only one glibc wrapper:
int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);

The PRE wrappers in coregrind/m_syswrap/syswrap-linux.c simply do:

   if ( !ML_(fd_allowed)(SARG1, "fchmodat", tid, False) )
     SET_STATUS_Failure( VKI_EBADF );

   if ( !ML_(fd_allowed)(SARG1, "fchmodat2", tid, False) )
     SET_STATUS_Failure( VKI_EBADF );

This doesn't handle AT_FDCWD or absolute paths (then fd should be ignored).

fchmodat01.c:47: TFAIL: fchmodat(-100, fchmodatdir/fchmodatfile, 0600, 0) failed: EBADF (9)
fchmodat02.c:55: TFAIL: fchmodat() with invalid flag expected EINVAL: EBADF (9)

Note that the fchmodat2 testcases don't seem to check for AT_FDCWD or absolute paths.

This also seems to cause a lot of arm64 LTP failures
Comment 1 mcermak 2025-08-05 13:27:27 UTC
Created attachment 183804 [details]
proposed patch
Comment 2 mcermak 2025-08-05 15:37:41 UTC
Created attachment 183809 [details]
proposed patch
Comment 3 Mark Wielaard 2025-08-06 17:10:19 UTC
(In reply to mcermak from comment #2)
> Created attachment 183809 [details]
> proposed patch

Looks good. Pushed as:

commit 90d4ed67ff52b859bf1f2d8cbea8816ca705d6f6
Author: Martin Cermak <mcermak@redhat.com>
Date:   Tue Aug 5 17:36:29 2025 +0200

    Make fchmodat and fchmodat2 syscall wrappers accept AT_FDCWD
    
    The fchmodat and fchmodat2 syscall wrappers should accept special
    value AT_FDCWD as a valid file descriptor.
    
    https://bugs.kde.org/show_bug.cgi?id=507873