]> git.apps.os.sepia.ceph.com Git - fscrypt.git/commit
keyring: fix permission denied accessing user keyring (#177)
authorebiggers <ebiggers@google.com>
Mon, 16 Dec 2019 03:10:41 +0000 (19:10 -0800)
committerJoseph Richey <joerichey@google.com>
Mon, 16 Dec 2019 03:10:41 +0000 (19:10 -0800)
commit55f71606b71f43bd64b7b4394a631f1e05e36f79
treeada151a1cf689e5e0e865929dcf58d30918ba376
parent6821d90d7c449b63d602c272d5ffa19243a7c517
keyring: fix permission denied accessing user keyring (#177)

When userKeyringIDLookup() looks up a user keyring, it links it into the
process keyring to ensure that the process retains the "possessor
privileges" over the user keyring, then caches the user keyring's ID.

Unfortunately, this use of the process keyring randomly fails because Go
creates threads before even init() and main() are run, and then can run
code on them later.  Since the kernel doesn't create the process keyring
until userspace requests it and the process keyring is actually a
per-thread property that's only inherited by new threads, different
threads in a Go process may see different process keyrings.

Fix this by removing the user keyring cache, switching from the process
keyring to the thread keyring, and using LockOSThread() to pin the
goroutine to an OS thread while needed to perform a keyring operation.

Resolves https://github.com/google/fscrypt/issues/176
security/keyring.go