Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/opencrypto crypto(4): Refuse crypto operations with noth...



details:   https://anonhg.NetBSD.org/src/rev/e76a0b0029b4
branches:  trunk
changeset: 366318:e76a0b0029b4
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun May 22 11:34:29 2022 +0000

description:
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:

 sys/opencrypto/cryptodev.c |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (42 lines):

diff -r ed6774475f63 -r e76a0b0029b4 sys/opencrypto/cryptodev.c
--- a/sys/opencrypto/cryptodev.c        Sun May 22 11:34:17 2022 +0000
+++ b/sys/opencrypto/cryptodev.c        Sun May 22 11:34:29 2022 +0000
@@ -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 @@
                        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 @@
                        }
                }
 
+               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;



Home | Main Index | Thread Index | Old Index