wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.64k stars 321 forks source link

libfaketime does not fake `statx()` call #417

Closed mdietzer-fn closed 1 year ago

mdietzer-fn commented 1 year ago

As the title says, currently libfaketime does not intercept the statx syscall ( https://man7.org/linux/man-pages/man2/statx.2.html )

This syscall is used on modern Debian (bullseye) in its built-in programs at the last (such as ls and stat). Example:

root@host:/src# /usr/bin/faketime -f '1991-01-18 13:56:21 -0800' stat Makefile
  File: Makefile
  Size: 1006        Blocks: 8          IO Block: 4096   regular file
Device: 92h/146d    Inode: 391         Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-01-19 19:35:52.011207576 +0000
Modify: 2023-01-19 19:35:51.730121913 +0000
Change: 2023-01-19 19:35:51.730121913 +0000

I have verified this is an issue with both the packaged faketime as well as latest git

drok commented 1 year ago

I believe this behaviour breaks the FAKETIME_FOLLOW_FILE feature:

On Ubuntu 16.04, stat() is a weak symbol pointing to statx(). This means that https://github.com/wolfcw/libfaketime/blob/6fc4ae74f43bd906be74515778c35b2658672958/src/libfaketime.c#L2588 fails to find the "real" stat()

The consequence is that, when trying to read the timestamp of the follow file, the CHECK_MISSING_REAL(stat) thinks there is no stat available, and fails to read the file's timestamp.

More generally, on platforms where some faked symbols are weak symbols, libfaketime is unable to find the "real" syscall, and fails.

In my environment I have implemented the following hack to allow me to proceed with the tests I'm working on, but is by no means a good solution: 1ddc2ff2356fa5db3f124f316264661a27530359

I propose changing the issue title to "libfaketime does not support weak symbols" and reclassifying this issue as a bug.