From 90687215a42b2e074f3b5a85cf344ca998fa34ac Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Fri, 24 Nov 2017 00:44:06 +0100 Subject: fusefrontend_reverse: Do not mix up cache information for different directories Fixes https://github.com/rfjakob/gocryptfs/issues/168 Steps to reproduce the problem: * Create a regular reverse mount point * Create files with the same very long name in multiple directories - so far everything works as expected, and it will appear with a different name each time, for example, gocryptfs.longname.A in directory A and gocryptfs.longname.B in directory B * Try to access a path with A/gocryptfs.longname.B or B/gocryptfs.longname.A - this should fail, but it actually works. The problem is that the longname cache only uses the path as key and not the dir or divIV. Assume an attacker can directly interact with a reverse mount and knows the relation longname path -> unencoded path in one directory, it allows to test if the same unencoded filename appears in any other directory. --- internal/fusefrontend_reverse/reverse_longnames.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'internal/fusefrontend_reverse/reverse_longnames.go') diff --git a/internal/fusefrontend_reverse/reverse_longnames.go b/internal/fusefrontend_reverse/reverse_longnames.go index 212d493..6a561d8 100644 --- a/internal/fusefrontend_reverse/reverse_longnames.go +++ b/internal/fusefrontend_reverse/reverse_longnames.go @@ -51,7 +51,7 @@ func initLongnameCache() { // findLongnameParent converts "gocryptfs.longname.XYZ" to the plaintext name func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname string) (plaintextName string, err error) { longnameCacheLock.Lock() - hit := longnameParentCache[longname] + hit := longnameParentCache[dir + "/" + longname] longnameCacheLock.Unlock() if hit != "" { return hit, nil @@ -79,7 +79,7 @@ func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname stri log.Panic("logic error or wrong shortNameMax constant?") } hName := rfs.nameTransform.HashLongName(cName) - longnameParentCache[hName] = plaintextName + longnameParentCache[dir + "/" + hName] = plaintextName if longname == hName { hit = plaintextName } -- cgit v1.2.3