OSDN Git Service

fscrypt: use READ_ONCE() to access ->i_crypt_info
authorEric Biggers <ebiggers@google.com>
Thu, 11 Apr 2019 21:32:15 +0000 (14:32 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 12 Jul 2019 23:47:39 +0000 (16:47 -0700)
commit70e22217e51820eda1256af3f1c7dda46e416157
tree57282a41418f3fac54ecc94a5cd58193f7ee969b
parentc5710a3ce6be4c534af204e7973f7da25a1ef3a0
fscrypt: use READ_ONCE() to access ->i_crypt_info

->i_crypt_info starts out NULL and may later be locklessly set to a
non-NULL value by the cmpxchg() in fscrypt_get_encryption_info().

But ->i_crypt_info is used directly, which technically is incorrect.
It's a data race, and it doesn't include the data dependency barrier
needed to safely dereference the pointer on at least one architecture.

Fix this by using READ_ONCE() instead.  Note: we don't need to use
smp_load_acquire(), since dereferencing the pointer only requires a data
dependency barrier, which is already included in READ_ONCE().  We also
don't need READ_ONCE() in places where ->i_crypt_info is unconditionally
dereferenced, since it must have already been checked.

Also downgrade the cmpxchg() to cmpxchg_release(), since RELEASE
semantics are sufficient on the write side.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/crypto/crypto.c
fs/crypto/fname.c
fs/crypto/keyinfo.c
fs/crypto/policy.c
include/linux/fscrypt.h