* File permissions are not persisted after creating hard link if system crashes
@ 2026-03-03 16:41 Vyacheslav Kovalevsky
2026-03-03 19:08 ` Filipe Manana
0 siblings, 1 reply; 2+ messages in thread
From: Vyacheslav Kovalevsky @ 2026-03-03 16:41 UTC (permalink / raw)
To: clm, dsterba; +Cc: linux-btrfs, linux-kernel
Detailed description
====================
Hello, there seems to be an issue with btrfs crash behavior:
1. Create and sync a new file.
2. Open the file and change permissions.
3. Sync the file.
4. Create new hard link to file.
5. Sync the root directory.
After crash the file will have old (original) permissions, though the
changes were synced.
System info
===========
Linux version 7.0-rc2, also tested on 6.19.2
How to reproduce
================
```
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
int status;
int file_fd0;
int file_fd1;
int root_fd;
status = creat("file1", S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
printf("CREAT: %d\n", status);
file_fd0 = status;
status = close(file_fd0);
printf("CLOSE: %d\n", status);
sync();
status = open("file1", O_RDONLY);
printf("OPEN: %d\n", status);
file_fd1 = status;
status = fchmod(file_fd1, S_IRWXU | S_IRWXG | S_IRWXO);
printf("FCHMOD: %d\n", status);
status = fsync(file_fd1);
printf("FSYNC: %d\n", status);
status = link("file1", "file2");
printf("LINK: %d\n", status);
status = open(".", O_RDONLY);
printf("OPEN: %d\n", status);
root_fd = status;
status = fsync(root_fd);
printf("FSYNC: %d\n", status);
}
// after crash file `file1` / `file2` has old permissions (0751 instead
of 0777)
```
Steps:
1. Create and mount new btrfs file system in default configuration.
2. Change directory to root of the file system and run the compiled test.
3. Cause hard system crash (e.g. QEMU `system_reset` command).
4. Remount file system after crash.
5. Observe that file permissions were not persisted.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: File permissions are not persisted after creating hard link if system crashes
2026-03-03 16:41 File permissions are not persisted after creating hard link if system crashes Vyacheslav Kovalevsky
@ 2026-03-03 19:08 ` Filipe Manana
0 siblings, 0 replies; 2+ messages in thread
From: Filipe Manana @ 2026-03-03 19:08 UTC (permalink / raw)
To: Vyacheslav Kovalevsky; +Cc: clm, dsterba, linux-btrfs, linux-kernel
On Tue, Mar 3, 2026 at 4:47 PM Vyacheslav Kovalevsky
<slava.kovalevskiy.2014@gmail.com> wrote:
>
> Detailed description
> ====================
>
> Hello, there seems to be an issue with btrfs crash behavior:
>
> 1. Create and sync a new file.
> 2. Open the file and change permissions.
> 3. Sync the file.
> 4. Create new hard link to file.
> 5. Sync the root directory.
>
> After crash the file will have old (original) permissions, though the
> changes were synced.
For this test to pass you'll need the patch I sent for another report
you made before:
https://lore.kernel.org/linux-btrfs/af8c15fa-4e41-4bb2-885c-0bc4e97532a6@gmail.com/
The patch is: https://lore.kernel.org/linux-btrfs/1c66bd7efe749cd3b421fc3dff5ef646dda8c7aa.1771350720.git.fdmanana@suse.com/
It's not in any released kernel yet (not even in Linus' master
branch), only in the for-next github branch:
https://github.com/btrfs/linux/commits/for-next/
Whenever you have new things to report, try to see if every patch I
pointed you to in previous reports is applied in the kernel you are
testing.
Thanks.
>
>
> System info
> ===========
>
> Linux version 7.0-rc2, also tested on 6.19.2
>
>
> How to reproduce
> ================
>
> ```
> #include <errno.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <string.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <unistd.h>
>
> int main() {
> int status;
> int file_fd0;
> int file_fd1;
> int root_fd;
>
> status = creat("file1", S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
> printf("CREAT: %d\n", status);
> file_fd0 = status;
>
> status = close(file_fd0);
> printf("CLOSE: %d\n", status);
>
> sync();
>
> status = open("file1", O_RDONLY);
> printf("OPEN: %d\n", status);
> file_fd1 = status;
>
> status = fchmod(file_fd1, S_IRWXU | S_IRWXG | S_IRWXO);
> printf("FCHMOD: %d\n", status);
>
> status = fsync(file_fd1);
> printf("FSYNC: %d\n", status);
>
> status = link("file1", "file2");
> printf("LINK: %d\n", status);
>
> status = open(".", O_RDONLY);
> printf("OPEN: %d\n", status);
> root_fd = status;
>
> status = fsync(root_fd);
> printf("FSYNC: %d\n", status);
> }
> // after crash file `file1` / `file2` has old permissions (0751 instead
> of 0777)
> ```
>
> Steps:
>
> 1. Create and mount new btrfs file system in default configuration.
> 2. Change directory to root of the file system and run the compiled test.
> 3. Cause hard system crash (e.g. QEMU `system_reset` command).
> 4. Remount file system after crash.
> 5. Observe that file permissions were not persisted.
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-03 19:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03 16:41 File permissions are not persisted after creating hard link if system crashes Vyacheslav Kovalevsky
2026-03-03 19:08 ` Filipe Manana
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox