Source-Changes-HG archive

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

[src/trunk]: src/sys/opencrypto opencrypto: Assert num>0 in crypto_getreq, nu...



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

description:
opencrypto: Assert num>0 in crypto_getreq, num=1 in crypto_kgetreq.

- For crypto_getreq this makes downstream reasoning easier: on
  success, crp_desc is guaranteed to be nonnull.

- For crypto_kgetreq, this was already assumed, just silently
  ignored and not checked by anything.

diffstat:

 share/man/man9/opencrypto.9 |   8 +++++---
 sys/opencrypto/crypto.c     |  10 +++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diffs (72 lines):

diff -r 6963fba2e9e0 -r ed6774475f63 share/man/man9/opencrypto.9
--- a/share/man/man9/opencrypto.9       Sun May 22 11:31:33 2022 +0000
+++ b/share/man/man9/opencrypto.9       Sun May 22 11:34:17 2022 +0000
@@ -1,5 +1,5 @@
 .\"    $OpenBSD: crypto.9,v 1.25 2003/07/11 13:47:41 jmc Exp $
-.\"    $NetBSD: opencrypto.9,v 1.17 2017/07/03 21:28:48 wiz Exp $
+.\"    $NetBSD: opencrypto.9,v 1.18 2022/05/22 11:34:17 riastradh Exp $
 .\"
 .\" The author of this man page is Angelos D. Keromytis (angelos%cis.upenn.edu@localhost)
 .\"
@@ -417,7 +417,8 @@
 .Fa cryptop
 structure with a linked list of as many
 .Fa cryptodesc
-structures as were specified in the argument passed to it.
+structures as were specified in the argument passed to it, which must
+be at least 1.
 .Pp
 .Fn crypto_freereq
 deallocates a structure
@@ -462,7 +463,8 @@
 .Fa cryptkop
 structure.
 The first argument means the same as
-.Fn crypto_getreq .
+.Fn crypto_getreq ,
+except it is currently limited to be exactly 1.
 The second argument means flags passed to
 .Fn pool_get .
 .Pp
diff -r 6963fba2e9e0 -r ed6774475f63 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Sun May 22 11:31:33 2022 +0000
+++ b/sys/opencrypto/crypto.c   Sun May 22 11:34:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypto.c,v 1.121 2022/05/22 11:30:05 riastradh Exp $ */
+/*     $NetBSD: crypto.c,v 1.122 2022/05/22 11:34:17 riastradh Exp $ */
 /*     $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $   */
 /*     $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */
 
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.121 2022/05/22 11:30:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.122 2022/05/22 11:34:17 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -1641,6 +1641,8 @@
        struct cryptop *crp;
        struct crypto_crp_ret_qs *qs;
 
+       KASSERT(num > 0);
+
        /*
         * When crp_ret_q is full, we restrict here to avoid crp_ret_q overflow
         * by error callback.
@@ -1701,11 +1703,13 @@
  * Currently, support one descriptor only.
  */
 struct cryptkop *
-crypto_kgetreq(int num __unused, int prflags)
+crypto_kgetreq(int num __diagused, int prflags)
 {
        struct cryptkop *krp;
        struct crypto_crp_ret_qs *qs;
 
+       KASSERTMSG(num == 1, "num=%d not supported", num);
+
        /*
         * When crp_ret_kq is full, we restrict here to avoid crp_ret_kq
         * overflow by error callback.



Home | Main Index | Thread Index | Old Index