]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: qat - extend scope of lock in adf_cfg_add_key_value_param()
authorNivas Varadharajan Mugunthakumar <nivasx.varadharajan.mugunthakumar@intel.com>
Tue, 25 Jun 2024 14:38:50 +0000 (15:38 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 6 Jul 2024 00:20:00 +0000 (10:20 +1000)
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()")
Signed-off-by: Nivas Varadharajan Mugunthakumar <nivasx.varadharajan.mugunthakumar@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/intel/qat/qat_common/adf_cfg.c

index 8836f015c39c41e0fbdb9c2db230c1aa8b9952c9..2cf102ad4ca82d7408ccac99b7a00fb8b6dc83b2 100644 (file)
@@ -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;
 }