[regression] getdents() does not list entries created after opening the directory

From: Linux regression tracking (Thorsten Leemhuis)
Date: Tue Oct 01 2024 - 07:29:31 EST


Hi, Thorsten here, the Linux kernel's regression tracker.

yangerkun, I noticed a report about a regression in bugzilla.kernel.org
that appears to be caused by the following change of yours:

64a7ce76fb901b ("libfs: fix infinite directory reads for offset dir")
[merged via: "Merge tag 'vfs-6.11-rc4.fixes' of
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs"; v6.11-rc4]

As many (most?) kernel developers don't keep an eye on the bug tracker,
I decided to write this mail. To quote from
https://bugzilla.kernel.org/show_bug.cgi?id=219285:

> below program illustrates the problem. Expected output should include line "entry: after", actual output does not:
> ```
> entry: .
> entry: ..
> entry: before
> ```
> Program:
>
> ```c
> #include <unistd.h>
> #include <dirent.h>
> #include <stdlib.h>
> #include <sys/stat.h>
> #include <stdio.h>
> #include <fcntl.h>
>
> int main() {
> system("rm -rf /tmp/dirent-problems-test-dir");
> if (mkdir("/tmp/dirent-problems-test-dir", 0755)) {
> abort();
> }
>
> int fd = creat("/tmp/dirent-problems-test-dir/before", 0644);
> if (fd < 0) {
> abort();
> }
> close(fd);
>
> DIR* dir = opendir("/tmp/dirent-problems-test-dir");
>
> fd = creat("/tmp/dirent-problems-test-dir/after", 0644);
> if (fd < 0) {
> abort();
> }
> close(fd);
>
> struct dirent* entry;
> while ((entry = readdir(dir))) {
> printf("entry: %s\n", entry->d_name);
> }
>
> closedir(dir);
> return 0;
> }
> ```
>
> Affected kernel version: 6.10.10.
> Filesystem: ext4.
> Distribution: Arch Linux.

> On Linux 6.6.51 it works as expected.

> Regression first appeared in 6.10.7, 6.10.6 was good. I will further
> bisect tomorrow.

> 6.11 is still affected.

See the ticket for more details. Reporter ist CCed. I made no judgement
if the code provided is sane, I'm just assumed forwarding the issue was
a good idea.

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat)
--
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
If I did something stupid, please tell me, as explained on that page.

P.S.: let me use this mail to also add the report to the list of tracked
regressions to ensure it's doesn't fall through the cracks:

#regzbot introduced: 64a7ce76fb901bf9f9c36cf5d681328fc0fd4b5a
#regzbot title: libfs: getdents() does not list entries created after
opening the directory
#regzbot from: Krzysztof Małysa <varqox@xxxxxxxxx>
#regzbot duplicate: https://bugzilla.kernel.org/show_bug.cgi?id=219285
#regzbot ignore-activity