rfjakob / gocryptfs

Encrypted overlay filesystem written in Go
https://nuetzlich.net/gocryptfs/
MIT License
3.51k stars 249 forks source link

How may root check whether a Gocryptfs mount point exists (when in use)? #849

Closed lechner closed 4 months ago

lechner commented 4 months ago

Hi,

This is probably a FUSE question, but I couldn't think of a better place:

I mount Gocryptfs volumes with the default FUSE options. The root user cannot look inside. My OS, however, insists on creating the mount point unless it exists. They use stat to check, which fails. Is that a bug in GNU Guile's stat, or should my OS check in a different way?

Thank you!

Kind regards Felix

rfjakob commented 4 months ago

They should check a different way.

Let's assume this:

$ ls -l
total 0
drwxr-xr-x. 2 jakob jakob 80 28. Mai 21:07 cipher
drwxr-xr-x. 2 jakob jakob 80 28. Mai 21:07 mnt
-rw-r--r--. 1 jakob jakob  0 28. Mai 21:12 somefile

Become root and we get:

# ls -l
ls: cannot access 'mnt': Permission denied
total 0
drwxr-xr-x. 2 jakob jakob 80 28. Mai 21:07 cipher
d?????????? ? ?     ?      ?             ? mnt
-rw-r--r--. 1 jakob jakob  0 28. Mai 21:12 somefile

Note that ls still knows that it's a directory as indicated by the d in front.

In other words, guix could read the containing directory.

2nd idea: Use "stat mnt/.":

# stat mnt/.
stat: cannot statx 'mnt/.': Permission denied

# stat somefile/.
stat: cannot statx 'somefile/.': Not a directory

# stat doesnotexist/.
stat: cannot statx 'doesnotexist/.': No such file or directory

If you get "Permission denied", then mnt is a directory.