crypto: qat - ADF_STATUS_PF_RUNNING should be set after adf_dev_init
authorTong Zhang <ztong0001@gmail.com>
Fri, 19 Mar 2021 03:40:00 +0000 (23:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 May 2021 08:40:23 +0000 (10:40 +0200)
[ Upstream commit 8609f5cfdc872fc3a462efa6a3eca5cb1e2f6446 ]

ADF_STATUS_PF_RUNNING is (only) used and checked by adf_vf2pf_shutdown()
before calling adf_iov_putmsg()->mutex_lock(vf2pf_lock), however the
vf2pf_lock is initialized in adf_dev_init(), which can fail and when it
fail, the vf2pf_lock is either not initialized or destroyed, a subsequent
use of vf2pf_lock will cause issue.
To fix this issue, only set this flag if adf_dev_init() returns 0.

[    7.178404] BUG: KASAN: user-memory-access in __mutex_lock.isra.0+0x1ac/0x7c0
[    7.180345] Call Trace:
[    7.182576]  mutex_lock+0xc9/0xd0
[    7.183257]  adf_iov_putmsg+0x118/0x1a0 [intel_qat]
[    7.183541]  adf_vf2pf_shutdown+0x4d/0x7b [intel_qat]
[    7.183834]  adf_dev_shutdown+0x172/0x2b0 [intel_qat]
[    7.184127]  adf_probe+0x5e9/0x600 [qat_dh895xccvf]

Signed-off-by: Tong Zhang <ztong0001@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Fixes: 25c6ffb249f6 ("crypto: qat - check if PF is running")
Acked-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/qat/qat_c3xxxvf/adf_drv.c
drivers/crypto/qat/qat_c62xvf/adf_drv.c
drivers/crypto/qat/qat_dh895xccvf/adf_drv.c

index 0dd8d2dc2ec1b2c24c77289e7e16bed18cf0d828..26931325dfa26b66137e6fbce073f0712969ead6 100644 (file)
@@ -238,12 +238,12 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (ret)
                goto out_err_free_reg;
 
-       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
-
        ret = adf_dev_init(accel_dev);
        if (ret)
                goto out_err_dev_shutdown;
 
+       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
+
        ret = adf_dev_start(accel_dev);
        if (ret)
                goto out_err_dev_stop;
index cd9e63468b1898f56cb0ed499072be96664baba3..722a06aac9faac40a878a1267bc72b70ca4e83f7 100644 (file)
@@ -238,12 +238,12 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (ret)
                goto out_err_free_reg;
 
-       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
-
        ret = adf_dev_init(accel_dev);
        if (ret)
                goto out_err_dev_shutdown;
 
+       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
+
        ret = adf_dev_start(accel_dev);
        if (ret)
                goto out_err_dev_stop;
index 15de9cbed3bf87f0bf4cdcaa81f69c14118c9e9e..cc3f5171a5233bbf4ddd0f9cec7eb1226e9b1dcb 100644 (file)
@@ -238,12 +238,12 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (ret)
                goto out_err_free_reg;
 
-       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
-
        ret = adf_dev_init(accel_dev);
        if (ret)
                goto out_err_dev_shutdown;
 
+       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
+
        ret = adf_dev_start(accel_dev);
        if (ret)
                goto out_err_dev_stop;