-
Notifications
You must be signed in to change notification settings - Fork 257
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
Race condition when reading symlinks can expose unrelated parts of the file system in reverse mode #165
Comments
I have not prepared a patch for this yet, but apparently there is a |
I wonder how apache or nginx handle this |
I believe we can always use O_NOFOLLOW. The kernel resolves symlinks before we geht the path. In other words, we should never get a "benign" open on a symlink. |
I'm not sure if it is currently allowed, but please keep in mind that the cipherDir could also contain symlinks. We probably want to resolve them immediately after program startup if this is not done yet. |
Not sure what you mean. Symlinks look like random crap in reverse mode, and because the kernel resolves resolves them, you can never follow them:
|
FUSE log:
What the kernel does is (indexed by transaction number as above):
-> Return ENOENT to userspace |
Sorry if it wasn't clear what I mean. To be a bit more precise, I am concerned about the following code in fusefrontend_reverse/rpath.go:
The
However, when looking at the actual implementation ( https://golang.org/src/path/filepath/path.go I hope it is a bit more clear now. Some other remarks:
|
O_NOFOLLOW only affects the last component of the path:
|
Okay, that means that my concern should not be an issue. However, it also means that |
https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg04347.html discusses a similar problem:
|
Yes, O_NOFOLLOW is not sufficient. I will check what apache and nginx are doing - they face the same problem. |
I've just checked the Nginx source: It looks like they also split the path, and open each component separately with |
OpenNofollow = symlink-race-safe Open Prepares fixing #165
...using the new syscallcompat.OpenNofollow helper. This change secures Open() against symlink race attacks as described in #165
...using the new syscallcompat.OpenNofollow helper. This change secures Open() against symlink race attacks as described in #165
...by ignoring the path that was passed in. #165
...by using the new OpenNofollow helper. The benchmark shows a small but acceptable performance loss: $ ./benchmark-reverse.bash LS: 2.182 CAT: 18.221 Tracking ticket: #165
...by using the OpenNofollow helper & Fstatat. Also introduce a helper to convert from unix.Stat_t to syscall.Stat_t. Tracking ticket: #165
...by using Readlinkat. Tracking ticket: #165
Unfortunately, faccessat in Linux ignores AT_SYMLINK_NOFOLLOW, so this is not completely atomic. Given that the information you get from access is not very interesting, it seems good enough. #165
That should have been all of them. Can you check if your script now fails to trigger a race? |
Thanks for working on this! The original issue is definitely fixed. Not sure if it is a problem, but BTW: It looks like there are some opportunities to use the newly introduced |
About openBackingDir - yes the plan was to get rid of the duplicated code later, patches welcome! I'll take a look about at longname handling, pretty sure there's room for improvement. |
Besides |
Protects findLongnameParent against symlink races. Also add comments to several functions along the way. Reported at #165
Assume user A has access to a machine, and root has mounted an encrypted version of the user home directory with
-allow_other
. Further assume that the user knows the master key. By quickly exchanging directories with symlinks in the original data, it is possible trick GoCryptFS into exposing unwanted parts of the file system.Steps to reproduce:
ls <encrypted dir>
)/root
I used a small script to reproduce this issue, manual execution is probably too slow. Even without
-allow_other
this could be a security issue and could, for example, backup unwanted data instead of just the symbolic link.The text was updated successfully, but these errors were encountered: