Skip to contentSkip to conversation

crypto: qat - extend scope of lock in adf_cfg_add_key_value_param()

PATCH In review Giovanni Cabiddu 2 participants 2 messages Jun 25, 2024 – Jul 6, 2024

Subsystems (2)
lore
Share & tools
lore

Giovanni Cabiddu

author maintainer
#0 lore raw

PATCH 1/1 crypto: qat - extend scope of lock in adf_cfg_add_key_value_param()

From: Nivas Varadharajan Mugunthakumar <[email protected]>

The function adf_cfg_add_key_value_param() attempts to access and modify the key value store of the driver without locking.

Extend the scope of cfg->lock to avoid a potential race condition.

Fixes 92bf269fbfe9 ("crypto: qat - change behaviour of adf_cfg_add_key_value_param()")
---
 drivers/crypto/intel/qat/qat_common/adf_cfg.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_cfg.c +4 -2
index 8836f015c39c..2cf102ad4ca8 100644
@@ -290,17 +290,19 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
 	 * 3. if the key exists with the same value, then return without doing
 	 *    anything (the newly created key_val is freed).
 	 */
+	down_write(&cfg->lock);
 	if (!adf_cfg_key_val_get(accel_dev, section_name, key, temp_val)) {
 		if (strncmp(temp_val, key_val->val, sizeof(temp_val))) {
 			adf_cfg_keyval_remove(key, section);
 		} else {
 			kfree(key_val);
-			return 0;
+			goto out;
 		}
 	}
 
-	down_write(&cfg->lock);
 	adf_cfg_keyval_add(key_val, section);
+
+out:
 	up_write(&cfg->lock);
 	return 0;
 }
Signature · 1 line
2.44.0
maintainer
#1 lore raw
Quoted 5 lines · Giovanni Cabiddu

From: Nivas Varadharajan Mugunthakumar <[email protected]>

The function adf_cfg_add_key_value_param() attempts to access and modify the key value store of the driver without locking.

Quoted 8 lines

Extend the scope of cfg->lock to avoid a potential race condition.

Fixes 92bf269fbfe9 ("crypto: qat - change behaviour of adf_cfg_add_key_value_param()")
---
 drivers/crypto/intel/qat/qat_common/adf_cfg.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt