tytso / e2fsprogs

Ext2/3/4 file system utilities
http://ext4.wiki.kernel.org
383 stars 224 forks source link

fuse2fs: respect requested mode in mkdir #170

Closed steven676 closed 7 months ago

steven676 commented 1 year ago

fuse2fs always clears the group and other mode bits when creating a directory, regardless of the requested mode:

steven@bookworm:~$ fuse2fs-old/bin/fuse2fs fs.img mnt
fs.img: Writing to the journal is not supported.
steven@bookworm:~$ cd mnt/
steven@bookworm:~/mnt$ ls -l
ls: lost+found: Permission denied
total 12
drwx------ 2 root root 12288 Nov 23 15:26 lost+found
steven@bookworm:~/mnt$ umask
0022
steven@bookworm:~/mnt$ mkdir foo
steven@bookworm:~/mnt$ umask 000
steven@bookworm:~/mnt$ mkdir bar
steven@bookworm:~/mnt$ umask 041
steven@bookworm:~/mnt$ mkdir baz
steven@bookworm:~/mnt$ ls -l
ls: lost+found: Permission denied
total 15
drwxr-xr-x 2 steven steven  1024 Nov 23 15:27 bar
drwx--xr-- 2 steven steven  1024 Nov 23 15:27 baz
drwxr-xr-x 2 steven steven  1024 Nov 23 15:27 foo
drwx------ 2 root   root   12288 Nov 23 15:26 lost+found

Amongst other things, this can cause permissions to change when writing to a directory on a fuse-overlayfs backed by fuse2fs; if the write causes the directory to be copied up, the new directory in the upper layer will have the group and other write permission bits cleared regardless of the permissions in the lower layer.

With this patch, permissions when creating a new directory are as expected:

steven@bookworm:~$ fuse2fs-new/bin/fuse2fs fs.img mnt
fs.img: Writing to the journal is not supported.
steven@bookworm:~$ cd mnt
steven@bookworm:~/mnt$ ls -l
ls: lost+found: Permission denied
total 12
drwx------ 2 root root 12288 Nov 23 15:31 lost+found
steven@bookworm:~/mnt$ umask
0022
steven@bookworm:~/mnt$ mkdir foo
steven@bookworm:~/mnt$ umask 000
steven@bookworm:~/mnt$ mkdir bar
steven@bookworm:~/mnt$ umask 041
steven@bookworm:~/mnt$ mkdir baz
steven@bookworm:~/mnt$ ls -l
ls: lost+found: Permission denied
total 15
drwxrwxrwx 2 steven steven  1024 Nov 23 15:32 bar
drwx-wxrw- 2 steven steven  1024 Nov 23 15:32 baz
drwxr-xr-x 2 steven steven  1024 Nov 23 15:32 foo
drwx------ 2 root   root   12288 Nov 23 15:31 lost+found