summaryrefslogtreecommitdiff
path: root/sys/opencrypto
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2022-05-22 11:34:29 +0000
committerriastradh <riastradh@NetBSD.org>2022-05-22 11:34:29 +0000
commit2709f08b11c6c1f04a977809abe19a8fd238f5dc (patch)
tree7272c7336a566e6b74b52d53b96da113dfee9ad0 /sys/opencrypto
parent29ad72533a5f6987c033b519a70ac3890f90c647 (diff)
crypto(4): Refuse crypto operations with nothing in them earlier.
This way we avoid passing 0 to crypto_getreq -- makes it easier to reason about everything downstream.
Diffstat (limited to 'sys/opencrypto')
-rw-r--r--sys/opencrypto/cryptodev.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c
index e00ba38cceb..48552c82497 100644
--- a/sys/opencrypto/cryptodev.c
+++ b/sys/opencrypto/cryptodev.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.c,v 1.117 2022/05/22 11:30:41 riastradh Exp $ */
+/* $NetBSD: cryptodev.c,v 1.118 2022/05/22 11:34:29 riastradh Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */
/* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.117 2022/05/22 11:30:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.118 2022/05/22 11:34:29 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -471,6 +471,9 @@ cryptodev_op(struct csession *cse, struct crypt_op *cop, struct lwp *l)
return EINVAL;
}
+ if (cse->tcomp == NULL && cse->txform == NULL && cse->thash == NULL)
+ return EINVAL;
+
DPRINTF("cryptodev_op[%u]: iov_len %d\n",
CRYPTO_SESID2LID(cse->sid), iov_len);
if ((cse->tcomp) && cop->dst_len) {
@@ -1131,6 +1134,13 @@ cryptodev_mop(struct fcrypt *fcr,
}
}
+ if (cse->txform == NULL &&
+ cse->thash == NULL &&
+ cse->tcomp == NULL) {
+ cnop[req].status = EINVAL;
+ goto bail;
+ }
+
/* sanitize */
if (cnop[req].len <= 0) {
cnop[req].status = ENOMEM;