Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3239fdb authored by Eric Biggers's avatar Eric Biggers Committed by Ritesh Harjani
Browse files

fscrypt: lock mutex before checking for bounce page pool



commit a0b3bc855374c50b5ea85273553485af48caf2f7 upstream.

fscrypt_initialize(), which allocates the global bounce page pool when
an encrypted file is first accessed, uses "double-checked locking" to
try to avoid locking fscrypt_init_mutex.  However, it doesn't use any
memory barriers, so it's theoretically possible for a thread to observe
a bounce page pool which has not been fully initialized.  This is a
classic issue with "double-checked locking".

While "only a theoretical issue" in the latest kernel, in pre-4.8
kernels the pointer that was checked was not even the last to be
initialized, so it was easily possible for a issue (NULL pointer
dereference) to happen.  This was changed only incidentally by the large
refactor to use fs/crypto/.

Solve both problems in a trivial way that can easily be backported: just
always take the mutex.  It's theoretically less efficient, but it
shouldn't be noticeable in practice as the mutex is only acquired very
briefly once per encrypted file.

Later I'd like to make this use a helper macro like DO_ONCE().  However,
DO_ONCE() runs in atomic context, so we'd need to add a new macro that
allows blocking.

Change-Id: I82ada76e8b3d737478a0d74fda6620cb8ee6f505
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Git-repo: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git


Git-Commit: 91bd72dd
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
[riteshh@codeaurora.org : resolved merge conflict ]
Signed-off-by: default avatarRitesh Harjani <riteshh@codeaurora.org>
parent 0dd9616f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment