Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data is lost if file with open descriptor is renamed before writing #78

Open
Slava0135 opened this issue Mar 13, 2025 · 0 comments
Open

Comments

@Slava0135
Copy link

Hello, we are doing research on file system testing, our fuzzer DIFFuzzer found this bug on commit 2cc2af5030f8bf831cd8355bc4780a34acbf6faa (tag: v2.7.10)

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

int main() {
  char buffer[100] = {0};
  int fd_0 = creat("1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  rename("1", "2");
  write(fd_0, "0123456789", 10);
  close(fd_0);
  int fd_1 = open("2", O_RDWR);
  int nread = read(fd_1, buffer, 10);
  printf("%d(%s)\n", nread, strerror(errno));
  printf("%s\n", buffer);
}

// ::Expected::
// 10(Success)
// 0123456789

// ::Actual::
// 0(Success)
//

If file is renamed when there is an open file descriptor, and any data is written, it will not be saved to disk.

Instead of using read at the end you can also just cat 2 in shell.

System info:

Ubuntu 22.04.5 LTS
Kernel 5.15.178
gcc 11.4.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant