NetBSD Problem Report #60281

From www@netbsd.org  Tue May 19 05:49:36 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "R13" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A95A11A9239
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 19 May 2026 05:49:36 +0000 (UTC)
Message-Id: <20260519054935.81A5C1A923A@mollari.NetBSD.org>
Date: Tue, 19 May 2026 05:49:35 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: crypto(4): bugs in reference counting and test
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60281
>Category:       kern
>Synopsis:       crypto(4): bugs in reference counting and test
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    riastradh
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 19 05:50:00 +0000 2026
>Closed-Date:    
>Last-Modified:  Sat Jun 27 16:34:28 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The CryptoBSDev Foundabug, Inc.
>Environment:
>Description:

	Several issues found on first pass, but I suspect there's a lot
	more I didn't see on this quick skim.

	1. Makes no sense to mutex_exit _and then_ acquire a reference;
	   the object in question may have been freed already between
	   the mutex_exit and the atomic_inc_uint:

    944 	mutex_enter(&fcr->lock);
    945 	TAILQ_FOREACH_SAFE(cse, &fcr->csessions, next, cnext)
    946 		if (cse->ses == ses) {
    947 			mutex_exit(&fcr->lock);
    948 			atomic_inc_uint(&cse->refcnt);
    949 			return cse;

https://nxr.NetBSD.org/xref/src/sys/opencrypto/cryptodev.c?r=1.128#944

	2. For reference count release, atomic_dec must be surrounded
	   by release/acquire barriers, or else the object might be
	   destroyed by one thread while another thread is still using
	   it:

   1027 	if (atomic_dec_uint_nv(&cse->refcnt) > 0)
   1028 		return;
   1029 	mutex_destroy(&cse->lock);
   1030 	crypto_freesession(cse->sid);
   1031 	if (cse->key)
   1032 		free(cse->key, M_XDATA);
   1033 	if (cse->mackey)
   1034 		free(cse->mackey, M_XDATA);
   1035 	pool_put(&csepl, cse);

https://nxr.NetBSD.org/xref/src/sys/opencrypto/cryptodev.c?r=1.128#1027

	   This must instead be:

		membar_release();
		if (atomic_dec_uint_nv(&cse->refcnt) > 0)
			return;
		membar_acquire();

	   For details, see, e.g.:

	   https://mail-index.NetBSD.org/source-changes/2023/02/23/msg143446.html

	3. Lock order between cryptodev_mtx, struct csession::lock, and
	   struct fcrypt::lock is not documented.

	4. The new test is fundamentally racy and will randomly
	   spuriously fail depending on who wins the race:

		- The t_encrypt thread runs forever issuing
		  ioctl(CIOCCRYPT) operations:

     79 static void *
     80 t_encrypt(void *v)
     81 {
...
     87 	for (;;) {
...
     96 		res = ioctl(a->fd, CIOCCRYPT, &co);
...
    103 	}
    104 }

https://nxr.NetBSD.org/xref/src/tests/crypto/opencrypto/h_thread.c?r=1.1#79

		- The main thread starts two t_encrypt threads and then
		  tries to close the session a second later with
		  ioctl(CIOCFSESSION), and fails the test if the ioctl
		  fails:

    126 	pthread_create(&t, NULL, t_encrypt, &a);
    127 	b = a;
    128 	b.msg = '+';
    129 	pthread_create(&t, NULL, t_encrypt, &b);
    130 	sleep(1);
    131 	res = ioctl(a.fd, CIOCFSESSION, &cs.ses);
    132 	if (res == -1) {
    133 		warn("CIOCFSESSION");
    134 		return EXIT_FAILURE;
    135 	}

https://nxr.NetBSD.org/xref/src/tests/crypto/opencrypto/h_thread.c?r=1.1#126

		- ioctl(CIOCFSESSION) fails with EBUSY if another
		  thread is concurrently using the session:

    963 			if (atomic_load_relaxed(&cse->refcnt) != 1)
    964 				return EBUSY;

https://nxr.NetBSD.org/xref/src/sys/opencrypto/cryptodev.c?r=1.128#963

	   Result: random spurious failures like this:

	   https://www.NetBSD.org/~martin/sparc64-atf/1023_atf.html#crypto_opencrypto_t_opencrypto_thread

>How-To-Repeat:

	code inspection

>Fix:

	Yes, please!

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Tue, 19 May 2026 15:55:04 +0000
Responsible-Changed-Why:
preparing patches


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: src/tests/crypto/opencrypto
Date: Tue, 19 May 2026 15:57:52 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue May 19 15:57:51 UTC 2026

 Modified Files:
 	src/tests/crypto/opencrypto: h_thread.c t_opencrypto.sh

 Log Message:
 crypto(4): Make test more reliable, and test more.

 1. New thread to concurrently create and destroy sessions.

    (There should really be multiple threads to concurrently compete
    with each other to create and destroy sessions, but this is
    already surfacing more crashes, as I expected.)

 2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
    CIOCCRYPT, as we are trying to test.

 3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
    it, as we are trying to test

 4. Dump core if the threads get stuck for too long.

 5. Provide stack traces from the test program or rump server if they
    dump core.

 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/tests/crypto/opencrypto/h_thread.c
 cvs rdiff -u -r1.12 -r1.13 src/tests/crypto/opencrypto/t_opencrypto.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: src/sys/opencrypto
Date: Tue, 19 May 2026 15:58:12 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue May 19 15:58:12 UTC 2026

 Modified Files:
 	src/sys/opencrypto: cryptodev.c

 Log Message:
 crypto(4): Take reference _before_ releasing the lock.

 Otherwise nothing ensures the object will still exist by the time we
 try to take the reference.

 Also guard against too many references, since this is only a 32-bit
 reference count.

 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.128 -r1.129 src/sys/opencrypto/cryptodev.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: src
Date: Tue, 19 May 2026 15:58:37 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue May 19 15:58:37 UTC 2026

 Modified Files:
 	src/sys/opencrypto: cryptodev.c cryptosoft.c
 	src/sys/rump/dev/lib/libopencrypto: OPENCRYPTO.ioconf
 	    opencrypto_component.c
 	src/tests/crypto/opencrypto: t_opencrypto.sh

 Log Message:
 crypto(4): Disentangle initialization and attachment goo.

 Lotta unnecessary boilerplate deleted here!

 Disable module unloading: can't be done safely.  Explain precisely
 why it can't be done safely.

 This also fixes annoying `crypto: unable to register devsw, error 17'
 messages in rump dmesg by having exactly one path to devsw_attach.

 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.130 -r1.131 src/sys/opencrypto/cryptodev.c
 cvs rdiff -u -r1.66 -r1.67 src/sys/opencrypto/cryptosoft.c
 cvs rdiff -u -r1.1 -r1.2 src/sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf
 cvs rdiff -u -r1.6 -r1.7 \
     src/sys/rump/dev/lib/libopencrypto/opencrypto_component.c
 cvs rdiff -u -r1.13 -r1.14 src/tests/crypto/opencrypto/t_opencrypto.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: src/sys/opencrypto
Date: Tue, 19 May 2026 15:59:01 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue May 19 15:59:01 UTC 2026

 Modified Files:
 	src/sys/opencrypto: cryptodev.c

 Log Message:
 crypto(4): Omit needless locking in fcrypt_dtor.

 We must have exclusive access to the object for this function to work
 at all, so if removing the locks appeared to cause issues, it would
 necessarily happen only because there is a bug somewhere else.

 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.131 -r1.132 src/sys/opencrypto/cryptodev.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 19 May 2026 16:10:22 +0000
State-Changed-Why:
fixed everything I found on the first pass in HEAD
needs pullup-11, pullup-10, pullup-9


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: src/sys/opencrypto
Date: Tue, 19 May 2026 19:00:01 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue May 19 19:00:01 UTC 2026

 Modified Files:
 	src/sys/opencrypto: cryptodev.c cryptodev_internal.h ocryptodev.c

 Log Message:
 crypto(4): Nix spurious mutex_exit; add missing bounds checks.

 Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
 `sizeof(struct whatever_foo_is)'.  Makes it easier for a reader to
 notice a discrepancy this way.

 Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
 the compat ocryptodev.c shims too.  I think this is waaaaaaaaaaaaay
 too high, by the way.  For example, it looks like qat(4) puts a limit
 of 16384 on the number of sessions.  Other devices like hifn(4) look
 like they're limited to numbers of sessions ranging from 2 to around
 256.

 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.132 -r1.133 src/sys/opencrypto/cryptodev.c
 cvs rdiff -u -r1.4 -r1.5 src/sys/opencrypto/cryptodev_internal.h
 cvs rdiff -u -r1.18 -r1.19 src/sys/opencrypto/ocryptodev.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Fri, 26 Jun 2026 01:47:11 +0000
State-Changed-Why:
pullup-10 #1278 https://releng.netbsd.org/cgi-bin/req-10.cgi?show=1278
pullup-11 #330 https://releng.netbsd.org/cgi-bin/req-11.cgi?show=330
lotta work for netbsd-9 -- there was a lot of cleanup back in 2021
through 2022 that never got pulled up and will take a while to track
down


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: [netbsd-11] src
Date: Sat, 27 Jun 2026 15:23:25 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Jun 27 15:23:24 UTC 2026

 Modified Files:
 	src/distrib/sets/lists/debug [netbsd-11]: mi
 	src/distrib/sets/lists/tests [netbsd-11]: mi
 	src/sys/opencrypto [netbsd-11]: cryptodev.c cryptodev_internal.h
 	    cryptosoft.c ocryptodev.c
 	src/sys/rump/dev/lib/libopencrypto [netbsd-11]: OPENCRYPTO.ioconf
 	    opencrypto_component.c
 	src/tests/crypto/opencrypto [netbsd-11]: Makefile t_opencrypto.sh
 Added Files:
 	src/tests/crypto/opencrypto [netbsd-11]: h_thread.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #330):

 	sys/opencrypto/cryptodev.c: revision 1.130
 	sys/opencrypto/cryptodev.c: revision 1.131
 	sys/opencrypto/cryptodev.c: revision 1.132
 	sys/opencrypto/cryptodev.c: revision 1.133
 	tests/crypto/opencrypto/Makefile: revision 1.6
 	sys/opencrypto/cryptosoft.c: revision 1.67
 	sys/opencrypto/ocryptodev.c: revision 1.19
 	tests/crypto/opencrypto/h_thread.c: revision 1.1
 	sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf: revision 1.2
 	tests/crypto/opencrypto/h_thread.c: revision 1.2
 	sys/rump/dev/lib/libopencrypto/opencrypto_component.c: revision 1.7
 	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.12
 	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.13
 	sys/opencrypto/cryptodev_internal.h: revision 1.5
 	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.14
 	sys/opencrypto/cryptodev.c: revision 1.129
 	distrib/sets/lists/debug/mi: revision 1.512
 	distrib/sets/lists/tests/mi: revision 1.1417

 Add a threaded test to test for races in cryptodev.
 new thread cryptodev test

 crypto(4): Make test more reliable, and test more.
 1. New thread to concurrently create and destroy sessions.
    (There should really be multiple threads to concurrently compete
    with each other to create and destroy sessions, but this is
    already surfacing more crashes, as I expected.)
 2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
    CIOCCRYPT, as we are trying to test.
 3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
    it, as we are trying to test
 4. Dump core if the threads get stuck for too long.
 5. Provide stack traces from the test program or rump server if they
    dump core.
 PR kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Take reference _before_ releasing the lock.

 Otherwise nothing ensures the object will still exist by the time we
 try to take the reference.

 Also guard against too many references, since this is only a 32-bit
 reference count.
 PR kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Fix missing membars on reference count release.

 If two threads A and B both hold references, we need to ensure that
 memory ops in thread A happen before memory free in thread B in:
 thread A                thread B                notes
 --------                --------                -----
 memory ops
 atomic_dec(&refcnt)                             goes from 2 to 1
                         atomic_dec(&refcnt)     goes from 1 to 0
                         memory free

 This requires a membar_release in thread A before the atomic_dec (or
 atomic_dec with memory_order_release), and a membar_acquire in thread
 B after the atomic_dec is found to have brought the reference count
 down to zero (or atomic_dec wiht memory_order_acquire).
 kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Disentangle initialization and attachment goo.
 Lotta unnecessary boilerplate deleted here!

 Disable module unloading: can't be done safely.  Explain precisely
 why it can't be done safely.

 This also fixes annoying `crypto: unable to register devsw, error 17'
 messages in rump dmesg by having exactly one path to devsw_attach.
 PR kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Omit needless locking in fcrypt_dtor.

 We must have exclusive access to the object for this function to work
 at all, so if removing the locks appeared to cause issues, it would
 necessarily happen only because there is a bug somewhere else.
 PR kern/60281: crypto(4): bugs in reference counting and test
 crypto(4): Nix spurious mutex_exit; add missing bounds checks.

 Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
 `sizeof(struct whatever_foo_is)'.  Makes it easier for a reader to
 notice a discrepancy this way.

 Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
 the compat ocryptodev.c shims too.  I think this is waaaaaaaaaaaaay
 too high, by the way.  For example, it looks like qat(4) puts a limit
 of 16384 on the number of sessions.  Other devices like hifn(4) look
 like they're limited to numbers of sessions ranging from 2 to around
 256.
 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.485.2.7 -r1.485.2.8 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.1387.2.7 -r1.1387.2.8 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.126.2.1 -r1.126.2.2 src/sys/opencrypto/cryptodev.c
 cvs rdiff -u -r1.3.48.1 -r1.3.48.2 src/sys/opencrypto/cryptodev_internal.h
 cvs rdiff -u -r1.65.2.1 -r1.65.2.2 src/sys/opencrypto/cryptosoft.c
 cvs rdiff -u -r1.17.12.1 -r1.17.12.2 src/sys/opencrypto/ocryptodev.c
 cvs rdiff -u -r1.1 -r1.1.60.1 \
     src/sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf
 cvs rdiff -u -r1.6 -r1.6.32.1 \
     src/sys/rump/dev/lib/libopencrypto/opencrypto_component.c
 cvs rdiff -u -r1.5 -r1.5.12.1 src/tests/crypto/opencrypto/Makefile
 cvs rdiff -u -r0 -r1.2.2.2 src/tests/crypto/opencrypto/h_thread.c
 cvs rdiff -u -r1.11 -r1.11.2.1 src/tests/crypto/opencrypto/t_opencrypto.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60281 CVS commit: [netbsd-10] src
Date: Sat, 27 Jun 2026 15:25:57 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sat Jun 27 15:25:57 UTC 2026

 Modified Files:
 	src/distrib/sets/lists/debug [netbsd-10]: mi
 	src/distrib/sets/lists/tests [netbsd-10]: mi
 	src/sys/opencrypto [netbsd-10]: cryptodev.c cryptodev_internal.h
 	    cryptosoft.c ocryptodev.c
 	src/sys/rump/dev/lib/libopencrypto [netbsd-10]: OPENCRYPTO.ioconf
 	    opencrypto_component.c
 	src/tests/crypto/opencrypto [netbsd-10]: Makefile t_opencrypto.sh
 Added Files:
 	src/tests/crypto/opencrypto [netbsd-10]: h_thread.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1278):

 	sys/opencrypto/cryptodev.c: revision 1.130
 	sys/opencrypto/cryptodev.c: revision 1.131
 	sys/opencrypto/cryptodev.c: revision 1.132
 	sys/opencrypto/cryptodev.c: revision 1.133
 	tests/crypto/opencrypto/Makefile: revision 1.6
 	sys/opencrypto/cryptosoft.c: revision 1.67
 	sys/opencrypto/ocryptodev.c: revision 1.19
 	tests/crypto/opencrypto/h_thread.c: revision 1.1
 	sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf: revision 1.2
 	tests/crypto/opencrypto/h_thread.c: revision 1.2
 	sys/rump/dev/lib/libopencrypto/opencrypto_component.c: revision 1.7
 	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.12
 	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.13
 	sys/opencrypto/cryptodev_internal.h: revision 1.5
 	tests/crypto/opencrypto/t_opencrypto.sh: revision 1.14
 	sys/opencrypto/cryptodev.c: revision 1.129
 	distrib/sets/lists/debug/mi: revision 1.512
 	distrib/sets/lists/tests/mi: revision 1.1417

 Add a threaded test to test for races in cryptodev.
 new thread cryptodev test

 crypto(4): Make test more reliable, and test more.
 1. New thread to concurrently create and destroy sessions.
    (There should really be multiple threads to concurrently compete
    with each other to create and destroy sessions, but this is
    already surfacing more crashes, as I expected.)
 2. Handle EBUSY in CIOCFSESSION in case there is a concurrent
    CIOCCRYPT, as we are trying to test.
 3. Handle CIOCCRYPT failure if a concurrent CIOCFSESSION beat us to
    it, as we are trying to test
 4. Dump core if the threads get stuck for too long.
 5. Provide stack traces from the test program or rump server if they
    dump core.
 PR kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Take reference _before_ releasing the lock.

 Otherwise nothing ensures the object will still exist by the time we
 try to take the reference.

 Also guard against too many references, since this is only a 32-bit
 reference count.
 PR kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Fix missing membars on reference count release.

 If two threads A and B both hold references, we need to ensure that
 memory ops in thread A happen before memory free in thread B in:
 thread A                thread B                notes
 --------                --------                -----
 memory ops
 atomic_dec(&refcnt)                             goes from 2 to 1
                         atomic_dec(&refcnt)     goes from 1 to 0
                         memory free

 This requires a membar_release in thread A before the atomic_dec (or
 atomic_dec with memory_order_release), and a membar_acquire in thread
 B after the atomic_dec is found to have brought the reference count
 down to zero (or atomic_dec wiht memory_order_acquire).
 kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Disentangle initialization and attachment goo.
 Lotta unnecessary boilerplate deleted here!

 Disable module unloading: can't be done safely.  Explain precisely
 why it can't be done safely.

 This also fixes annoying `crypto: unable to register devsw, error 17'
 messages in rump dmesg by having exactly one path to devsw_attach.
 PR kern/60281: crypto(4): bugs in reference counting and test

 crypto(4): Omit needless locking in fcrypt_dtor.

 We must have exclusive access to the object for this function to work
 at all, so if removing the locks appeared to cause issues, it would
 necessarily happen only because there is a bug somewhere else.
 PR kern/60281: crypto(4): bugs in reference counting and test
 crypto(4): Nix spurious mutex_exit; add missing bounds checks.

 Consistently use `foo = kmem_alloc(n * sizeof(*foo), ...)' instead of
 `sizeof(struct whatever_foo_is)'.  Makes it easier for a reader to
 notice a discrepancy this way.

 Move CRYPTODEV_OPS_MAX to cryptodev_internal.h so it can be used by
 the compat ocryptodev.c shims too.  I think this is waaaaaaaaaaaaay
 too high, by the way.  For example, it looks like qat(4) puts a limit
 of 16384 on the number of sessions.  Other devices like hifn(4) look
 like they're limited to numbers of sessions ranging from 2 to around
 256.
 PR kern/60281: crypto(4): bugs in reference counting and test


 To generate a diff of this commit:
 cvs rdiff -u -r1.394.2.15 -r1.394.2.16 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.1238.2.19 -r1.1238.2.20 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.125.4.1 -r1.125.4.2 src/sys/opencrypto/cryptodev.c
 cvs rdiff -u -r1.3.40.1 -r1.3.40.2 src/sys/opencrypto/cryptodev_internal.h
 cvs rdiff -u -r1.64.4.2 -r1.64.4.3 src/sys/opencrypto/cryptosoft.c
 cvs rdiff -u -r1.17.4.1 -r1.17.4.2 src/sys/opencrypto/ocryptodev.c
 cvs rdiff -u -r1.1 -r1.1.52.1 \
     src/sys/rump/dev/lib/libopencrypto/OPENCRYPTO.ioconf
 cvs rdiff -u -r1.6 -r1.6.24.1 \
     src/sys/rump/dev/lib/libopencrypto/opencrypto_component.c
 cvs rdiff -u -r1.5 -r1.5.8.1 src/tests/crypto/opencrypto/Makefile
 cvs rdiff -u -r0 -r1.2.4.2 src/tests/crypto/opencrypto/h_thread.c
 cvs rdiff -u -r1.9 -r1.9.8.1 src/tests/crypto/opencrypto/t_opencrypto.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 27 Jun 2026 16:34:28 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 11 and 10, needs a lot more work for 9


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.