Module Name:    src
Committed By:   knakahara
Date:           Wed May 10 09:45:51 UTC 2017

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

Log Message:
fix: crypto_drivers[hid].cc_process() could be called even if it was null.

If a crypto driver is unregistered before calling cyrptointr(),
the crypto_drivers[hid].cc_process is null in spite of the hid
is less than crypto_drivers_num.

reffered to FreeBSD code.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.62 src/sys/opencrypto/crypto.c:1.63
--- src/sys/opencrypto/crypto.c:1.62	Wed May 10 03:26:33 2017
+++ src/sys/opencrypto/crypto.c	Wed May 10 09:45:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.62 2017/05/10 03:26:33 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.63 2017/05/10 09:45:51 knakahara 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.62 2017/05/10 03:26:33 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.63 2017/05/10 09:45:51 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -970,12 +970,10 @@ crypto_invoke(struct cryptop *crp, int h
 
 	hid = CRYPTO_SESID2HID(crp->crp_sid);
 
-	if (hid < crypto_drivers_num) {
+	if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP) == 0) {
 		int (*process)(void *, struct cryptop *, int);
 		void *arg;
 
-		if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP)
-			crypto_freesession(crp->crp_sid);
 		process = crypto_drivers[hid].cc_process;
 		arg = crypto_drivers[hid].cc_arg;
 
@@ -992,6 +990,8 @@ crypto_invoke(struct cryptop *crp, int h
 		 * Driver has unregistered; migrate the session and return
 		 * an error to the caller so they'll resubmit the op.
 		 */
+		crypto_freesession(crp->crp_sid);
+
 		for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
 			crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
 

Reply via email to