Module Name: src Committed By: riastradh Date: Sun May 22 11:34:17 UTC 2022
Modified Files: src/share/man/man9: opencrypto.9 src/sys/opencrypto: crypto.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/share/man/man9/opencrypto.9 cvs rdiff -u -r1.121 -r1.122 src/sys/opencrypto/crypto.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man9/opencrypto.9 diff -u src/share/man/man9/opencrypto.9:1.17 src/share/man/man9/opencrypto.9:1.18 --- src/share/man/man9/opencrypto.9:1.17 Mon Jul 3 21:28:48 2017 +++ src/share/man/man9/opencrypto.9 Sun May 22 11:34:17 2022 @@ -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 (ange...@cis.upenn.edu) .\" @@ -417,7 +417,8 @@ allocates a .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 @@ allocates a .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 Index: src/sys/opencrypto/crypto.c diff -u src/sys/opencrypto/crypto.c:1.121 src/sys/opencrypto/crypto.c:1.122 --- src/sys/opencrypto/crypto.c:1.121 Sun May 22 11:30:05 2022 +++ src/sys/opencrypto/crypto.c Sun May 22 11:34:17 2022 @@ -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 @@ crypto_getreq(int num) 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 @@ crypto_kfreereq(struct cryptkop *krp) * 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.