aboutsummaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-10-29 06:30:19 -0400
committerMister Oyster <oysterized@gmail.com>2017-12-19 20:35:51 +0100
commit53e80e11dacd5a901790ae7ea1f0d164773f707e (patch)
tree65ce65d9ae441488291c9475d7fe91f92e88846a /fs
parentd6d7be0cd6c659844dffd98eb0a423b98d1d4c72 (diff)
UPSTREAM: fscrypt: lock mutex before checking for bounce page pool
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 bug 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 crash (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. Cc: stable@vger.kernel.org # v4.1+ Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> (cherry-picked from commit a0b3bc855374c50b5ea85273553485af48caf2f7 and fixed up for android-3.18) Change-Id: I18c7231af7de2319883934d2e36ea54e1eb44466 Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/crypto/crypto.c7
-rw-r--r--fs/ext4/crypto_key.c8
2 files changed, 5 insertions, 10 deletions
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index 5182c8e07..303e88123 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -410,11 +410,8 @@ int fscrypt_initialize(unsigned int cop_flags)
{
int i, res = -ENOMEM;
- /*
- * No need to allocate a bounce page pool if there already is one or
- * this FS won't use it.
- */
- if (cop_flags & FS_CFLG_OWN_PAGES || fscrypt_bounce_page_pool)
+ /* No need to allocate a bounce page pool if this FS won't use it. */
+ if (cop_flags & FS_CFLG_OWN_PAGES)
return 0;
mutex_lock(&fscrypt_init_mutex);
diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
index 84dccd223..bc36571b0 100644
--- a/fs/ext4/crypto_key.c
+++ b/fs/ext4/crypto_key.c
@@ -128,11 +128,9 @@ int _ext4_get_encryption_info(struct inode *inode)
char mode;
int res;
- if (!ext4_read_workqueue) {
- res = ext4_init_crypto();
- if (res)
- return res;
- }
+ res = ext4_init_crypto();
+ if (res)
+ return res;
retry:
crypt_info = ACCESS_ONCE(ei->i_crypt_info);