Fix a couple of bugs for asym crypto introduced in r359374.

- Check for null pointers in the crypto_drivers[] array when checking
  for empty slots in crypto_select_kdriver().

- Handle the case where crypto_kdone() is invoked on a request where
  krq_cap is NULL due to not finding a matching driver.

Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D26811
This commit is contained in:
John Baldwin 2020-10-19 20:04:03 +00:00
parent 4fa4bd6312
commit e7f6b6cf69
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=366852

View File

@ -1540,7 +1540,7 @@ crypto_select_kdriver(const struct cryptkop *krp, int flags)
* match), then skip.
*/
cap = crypto_drivers[hid];
if (cap->cc_dev == NULL ||
if (cap == NULL ||
(cap->cc_flags & match) == 0)
continue;
@ -1880,15 +1880,18 @@ crypto_kdone(struct cryptkop *krp)
if (krp->krp_status != 0)
CRYPTOSTAT_INC(cs_kerrs);
CRYPTO_DRIVER_LOCK();
cap = krp->krp_cap;
KASSERT(cap->cc_koperations > 0, ("cc_koperations == 0"));
cap->cc_koperations--;
if (cap->cc_koperations == 0 && cap->cc_flags & CRYPTOCAP_F_CLEANUP)
wakeup(cap);
CRYPTO_DRIVER_UNLOCK();
krp->krp_cap = NULL;
cap_rele(cap);
if (cap != NULL) {
CRYPTO_DRIVER_LOCK();
KASSERT(cap->cc_koperations > 0, ("cc_koperations == 0"));
cap->cc_koperations--;
if (cap->cc_koperations == 0 &&
cap->cc_flags & CRYPTOCAP_F_CLEANUP)
wakeup(cap);
CRYPTO_DRIVER_UNLOCK();
krp->krp_cap = NULL;
cap_rele(cap);
}
ret_worker = CRYPTO_RETW(0);