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.
This commit is contained in:
riastradh 2022-05-22 11:34:17 +00:00
parent a1a80f9135
commit a56f0ba8bd
2 changed files with 12 additions and 6 deletions

View File

@ -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)
.\"
@ -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

View File

@ -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.