Commit 43a867a2 authored by Ralph Wuerthner's avatar Ralph Wuerthner Committed by Martin Schwidefsky

[S390] zcrypt: fix possible race when unloading zcrypt driver modules

Move try_module_get() call into spin protected block to prevent zcrypt
driver module unload while submitting a request to driver.
Signed-off-by: default avatarRalph Wuerthner <rwuerthn@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent cf352ce0
...@@ -298,14 +298,14 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex) ...@@ -298,14 +298,14 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
get_device(&zdev->ap_dev->device); get_device(&zdev->ap_dev->device);
zdev->request_count++; zdev->request_count++;
__zcrypt_decrease_preference(zdev); __zcrypt_decrease_preference(zdev);
spin_unlock_bh(&zcrypt_device_lock);
if (try_module_get(zdev->ap_dev->drv->driver.owner)) { if (try_module_get(zdev->ap_dev->drv->driver.owner)) {
spin_unlock_bh(&zcrypt_device_lock);
rc = zdev->ops->rsa_modexpo(zdev, mex); rc = zdev->ops->rsa_modexpo(zdev, mex);
spin_lock_bh(&zcrypt_device_lock);
module_put(zdev->ap_dev->drv->driver.owner); module_put(zdev->ap_dev->drv->driver.owner);
} }
else else
rc = -EAGAIN; rc = -EAGAIN;
spin_lock_bh(&zcrypt_device_lock);
zdev->request_count--; zdev->request_count--;
__zcrypt_increase_preference(zdev); __zcrypt_increase_preference(zdev);
put_device(&zdev->ap_dev->device); put_device(&zdev->ap_dev->device);
...@@ -373,14 +373,14 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt) ...@@ -373,14 +373,14 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
get_device(&zdev->ap_dev->device); get_device(&zdev->ap_dev->device);
zdev->request_count++; zdev->request_count++;
__zcrypt_decrease_preference(zdev); __zcrypt_decrease_preference(zdev);
spin_unlock_bh(&zcrypt_device_lock);
if (try_module_get(zdev->ap_dev->drv->driver.owner)) { if (try_module_get(zdev->ap_dev->drv->driver.owner)) {
spin_unlock_bh(&zcrypt_device_lock);
rc = zdev->ops->rsa_modexpo_crt(zdev, crt); rc = zdev->ops->rsa_modexpo_crt(zdev, crt);
spin_lock_bh(&zcrypt_device_lock);
module_put(zdev->ap_dev->drv->driver.owner); module_put(zdev->ap_dev->drv->driver.owner);
} }
else else
rc = -EAGAIN; rc = -EAGAIN;
spin_lock_bh(&zcrypt_device_lock);
zdev->request_count--; zdev->request_count--;
__zcrypt_increase_preference(zdev); __zcrypt_increase_preference(zdev);
put_device(&zdev->ap_dev->device); put_device(&zdev->ap_dev->device);
...@@ -408,14 +408,14 @@ static long zcrypt_send_cprb(struct ica_xcRB *xcRB) ...@@ -408,14 +408,14 @@ static long zcrypt_send_cprb(struct ica_xcRB *xcRB)
get_device(&zdev->ap_dev->device); get_device(&zdev->ap_dev->device);
zdev->request_count++; zdev->request_count++;
__zcrypt_decrease_preference(zdev); __zcrypt_decrease_preference(zdev);
spin_unlock_bh(&zcrypt_device_lock);
if (try_module_get(zdev->ap_dev->drv->driver.owner)) { if (try_module_get(zdev->ap_dev->drv->driver.owner)) {
spin_unlock_bh(&zcrypt_device_lock);
rc = zdev->ops->send_cprb(zdev, xcRB); rc = zdev->ops->send_cprb(zdev, xcRB);
spin_lock_bh(&zcrypt_device_lock);
module_put(zdev->ap_dev->drv->driver.owner); module_put(zdev->ap_dev->drv->driver.owner);
} }
else else
rc = -EAGAIN; rc = -EAGAIN;
spin_lock_bh(&zcrypt_device_lock);
zdev->request_count--; zdev->request_count--;
__zcrypt_increase_preference(zdev); __zcrypt_increase_preference(zdev);
put_device(&zdev->ap_dev->device); put_device(&zdev->ap_dev->device);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment