diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2021-10-13 13:08:59 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2021-10-13 13:08:59 +0000 |
commit | d1e024176c87a67967f6f420011d4067fe2a0944 (patch) | |
tree | 12fff95b1415486a2c56a399c96ba260a8f96e18 /sys/crypto | |
parent | c91ef0f523c6bacfcf722eb21933240ac641b84d (diff) |
The kernel crypto framework sometimes returned an error, sometimes
the callback was called, and sometimes both. So the caller of that
API could not release resources correctly.
A bunch of errors can or should not happen, replace them with an
assert. Remove redundant checks. crypto_invoke() should not return
the error, but pass it via callback.
Some old hardware drivers keep part of their inconsistency as I
cannot test them.
OK mpi@
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/crypto.c | 18 | ||||
-rw-r--r-- | sys/crypto/cryptodev.h | 4 | ||||
-rw-r--r-- | sys/crypto/cryptosoft.c | 8 |
3 files changed, 13 insertions, 17 deletions
diff --git a/sys/crypto/crypto.c b/sys/crypto/crypto.c index bff6dd4a97c..a278f305ea3 100644 --- a/sys/crypto/crypto.c +++ b/sys/crypto/crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crypto.c,v 1.85 2021/07/26 21:27:56 bluhm Exp $ */ +/* $OpenBSD: crypto.c,v 1.86 2021/10/13 13:08:58 bluhm Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) * @@ -404,7 +404,7 @@ crypto_dispatch(struct cryptop *crp) if (crp->crp_flags & CRYPTO_F_NOQUEUE) { if (lock) KERNEL_LOCK(); - error = crypto_invoke(crp); + crypto_invoke(crp); if (lock) KERNEL_UNLOCK(); } else { @@ -421,7 +421,7 @@ crypto_dispatch(struct cryptop *crp) /* * Dispatch a crypto request to the appropriate crypto devices. */ -int +void crypto_invoke(struct cryptop *crp) { u_int64_t nid; @@ -430,17 +430,15 @@ crypto_invoke(struct cryptop *crp) int s, i; /* Sanity checks. */ - if (crp == NULL || crp->crp_callback == NULL) - return EINVAL; + KASSERT(crp != NULL); + KASSERT(crp->crp_callback != NULL); KERNEL_ASSERT_LOCKED(); s = splvm(); if (crp->crp_ndesc < 1 || crypto_drivers == NULL) { crp->crp_etype = EINVAL; - crypto_done(crp); - splx(s); - return 0; + goto done; } hid = (crp->crp_sid >> 32) & 0xffffffff; @@ -470,7 +468,7 @@ crypto_invoke(struct cryptop *crp) } splx(s); - return 0; + return; migrate: /* Migrate session. */ @@ -482,9 +480,9 @@ crypto_invoke(struct cryptop *crp) crp->crp_sid = nid; crp->crp_etype = EAGAIN; + done: crypto_done(crp); splx(s); - return 0; } /* diff --git a/sys/crypto/cryptodev.h b/sys/crypto/cryptodev.h index 10bb1a6f625..699074db83f 100644 --- a/sys/crypto/cryptodev.h +++ b/sys/crypto/cryptodev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptodev.h,v 1.74 2021/07/26 21:27:56 bluhm Exp $ */ +/* $OpenBSD: cryptodev.h,v 1.75 2021/10/13 13:08:58 bluhm Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -224,7 +224,7 @@ int crypto_register(u_int32_t, int *, int (*)(struct cryptop *)); int crypto_unregister(u_int32_t, int); int32_t crypto_get_driverid(u_int8_t); -int crypto_invoke(struct cryptop *); +void crypto_invoke(struct cryptop *); void crypto_done(struct cryptop *); void cuio_copydata(struct uio *, int, int, caddr_t); diff --git a/sys/crypto/cryptosoft.c b/sys/crypto/cryptosoft.c index 6fef68ac276..3fc7e3ca8f0 100644 --- a/sys/crypto/cryptosoft.c +++ b/sys/crypto/cryptosoft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptosoft.c,v 1.88 2021/07/09 15:29:55 bluhm Exp $ */ +/* $OpenBSD: cryptosoft.c,v 1.89 2021/10/13 13:08:58 bluhm Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -1035,11 +1035,9 @@ swcr_process(struct cryptop *crp) int type; int i; - /* Sanity check */ - if (crp == NULL) - return EINVAL; + KASSERT(crp->crp_ndesc >= 1); - if (crp->crp_ndesc < 1 || crp->crp_buf == NULL) { + if (crp->crp_buf == NULL) { crp->crp_etype = EINVAL; goto done; } |