Skip to contentSkip to conversation

fscrypt: add memory barrier when loading essiv_hash_tfm

PATCH In review Eric Biggers 1 participant 2 messages Mar 18, 2019 – Apr 11, 2019

Subsystems (2)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 fscrypt: add memory barrier when loading essiv_hash_tfm

From: Eric Biggers <[email protected]>

Load 'essiv_hash_tfm' using smp_load_acquire() to guarantee that the struct crypto_shash is seen as fully initialized before being used.

---
 fs/crypto/keyinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/crypto/keyinfo.c +1 -1
index ba74dafa18a3..d1f0f8369d51 100644
@@ -379,7 +379,7 @@ fscrypt_get_master_key(const struct fscrypt_info *ci, struct fscrypt_mode *mode,
 
 static int derive_essiv_salt(const u8 *key, int keysize, u8 *salt)
 {
-	struct crypto_shash *tfm = READ_ONCE(essiv_hash_tfm);
+	struct crypto_shash *tfm = smp_load_acquire(&essiv_hash_tfm);
 
 	/* init hash transform on demand */
 	if (unlikely(!tfm)) {
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
author maintainer
#1 lore raw
Quoted 26 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Load 'essiv_hash_tfm' using smp_load_acquire() to guarantee that the struct crypto_shash is seen as fully initialized before being used.

---
 fs/crypto/keyinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/crypto/keyinfo.c +1 -1
index ba74dafa18a3..d1f0f8369d51 100644
@@ -379,7 +379,7 @@ fscrypt_get_master_key(const struct fscrypt_info *ci, struct fscrypt_mode *mode,
 
 static int derive_essiv_salt(const u8 *key, int keysize, u8 *salt)
 {
-	struct crypto_shash *tfm = READ_ONCE(essiv_hash_tfm);
+	struct crypto_shash *tfm = smp_load_acquire(&essiv_hash_tfm);
 
 	/* init hash transform on demand */
 	if (unlikely(!tfm)) {
Signature · 1 line
2.21.0.225.g810b269d1ac-goog

Actually I think we only need a data dependency barrier here, so this patch isn't needed. See discussion of similar case at
https://marc.info/?l=linux-fsdevel&m=155487269904655&w=2

- Eric