-
Notifications
You must be signed in to change notification settings - Fork 1.3k
mount: user
option is sometimes ignored when used with X-mount.mkdir
#3575
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
Comments
I have tested that the mount() function's arguments remain consistent across two consecutive command executions. # prepare
echo@debian ~/u/build> sudo chown root:root mount; sudo chmod u+s mount
echo@debian ~/u/build> rm /home/echo/FOO_FS -rf
# firstly
echo@debian ~/u/build> ./mount /home/echo/FOO_FS
mount(2) [source=/dev/nvme0n2, target=/home/echo/FOO_FS, type=btrfs, flags=0x0000000e, options=<none>]
mount: /home/echo/FOO_FS: must be superuser to use mount.
dmesg(1) may have more information after failed mount system call.
# second
echo@debian ~/u/build> ./mount /home/echo/FOO_FS
mount(2) [source=/dev/nvme0n2, target=/home/echo/FOO_FS, type=btrfs, flags=0x0000000e, options=<none>] Perhaps it is the behavior of a system call |
I wanted to try
(I don't really have any clue why it was necessary to log in as root and fake my user in this way, but running I've attached two traces that I hope might be helpful: The contents of the traces are a little hard for me to follow, but it looks like the key difference is at line 126 of So the problem seems a little more subtle than I thought at first, which is to say I have no idea what would cause a failure to read the Here's some more info on my system:
And, as is apparent from the traces, the filesystem I'm trying to mount is a LUKS partition in this case, though I wouldn't expect that to be important in this case. mount_fail_trace_from_root.txt |
Call if (mnt_context_is_restricted(cxt) && sanitize_paths(cxt) != 0)
suid_drop(cxt); |
should I move |
The The problem is that sanitize_paths() is called at the beginning (for security reasons), 8000 and before mount/libmount, it reads fstab, so it has no clue about the mount options. IF we move the check after the mkdir hook, then there will be a huge area for possible security issues. It would be better to document in man page that user-mount need the target directory and mkdir is not allowed. |
I feel like it's not entirely clear to me how much of a security hole allowing Or maybe the real problem would be allowing To me it seems like moving the logic of |
The original motivation for sanitize_paths() is to avoid situations where a non-root user uses mount(8) to verify the existence of any file or directory in the system, trigger anything (automount, inotify, etc.), or exploit any libmount bug. For example, in a very old version without sanitize_paths(), mount(8) returned different error messages if the path existed and was not configured in fstab. Thus, using "mount /root/foo" to detect if a file was present was possible. I think it would be safer to keep sanitize_paths() at the beginning of all mount processes, but perhaps we can make the function smarter. For example, we can accept incomplete paths if all existing elements of the path are accessible to the current user and the last directory is writable. The hook_mkdir.c should be extended to consider non-root users. |
With the following line in
/etc/fstab
:I sometimes get the following error:
Specifically, if the target directory doesn't already exist, the first time I call
mount
, it creates the target directory, and then exits, complaining about permissions as above. If I callmount
a second time, without deleting the directory that it made the first time, it mounts the filesystem without any problem. I also checked if changing the order of the two options makes a difference, butX-mount.mkdir=0700,user
has the same behavior.(For completeness):
I think the expected behavior would be that with
user
option present,mount
should not raise errors due to not being the superuser, and that withX-mount.mkdir
option present,mount
should create the target directory if needed.In case it's relevant, the full line in my
fstab
is usuallywhich has the same behavior as the shorter line. (I tested both the shorter version, and this longer version).
The text was updated successfully, but these errors were encountered: