Skip to contentSkip to conversation

fscrypt: avoid data race on fscrypt_mode::logged_impl_name

PATCH Superseded Eric Biggers 1 participant 1 message Oct 9, 2019 fscrypt: file system level encryption support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 fscrypt: avoid data race on fscrypt_mode::logged_impl_name

From: Eric Biggers <[email protected]>

The access to logged_impl_name is technically a data race, which tools like KCSAN could complain about in the future. See:
https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE

Fix by using xchg(), which also ensures that only one thread does the logging.

---
 fs/crypto/keysetup.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/crypto/keysetup.c +2 -4
index 8eb5a0e762ec6..df3e1c8653884 100644
@@ -81,15 +81,13 @@ struct crypto_skcipher *fscrypt_allocate_skcipher(struct fscrypt_mode *mode,
 			    mode->cipher_str, PTR_ERR(tfm));
 		return tfm;
 	}
-	if (unlikely(!mode->logged_impl_name)) {
+	if (!xchg(&mode->logged_impl_name, true)) {
 		/*
 		 * fscrypt performance can vary greatly depending on which
 		 * crypto algorithm implementation is used.  Help people debug
 		 * performance problems by logging the ->cra_driver_name the
-		 * first time a mode is used.  Note that multiple threads can
-		 * race here, but it doesn't really matter.
+		 * first time a mode is used.
 		 */
-		mode->logged_impl_name = true;
 		pr_info("fscrypt: %s using implementation \"%s\"\n",
 			mode->friendly_name,
 			crypto_skcipher_alg(tfm)->base.cra_driver_name);
Signature · 1 line
2.23.0.581.g78d2f28ef7-goog