Module Name:    src
Committed By:   christos
Date:           Wed Jan 26 19:52:16 UTC 2011

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

Log Message:
PR/44470: Dr. Wolfgang Stukenbrock: opencrypto kernel implementation may pass
outdated argument to worker


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 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.36 src/sys/opencrypto/crypto.c:1.37
--- src/sys/opencrypto/crypto.c:1.36	Wed Aug 11 07:49:09 2010
+++ src/sys/opencrypto/crypto.c	Wed Jan 26 14:52:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.36 2010/08/11 11:49:09 pgoyette Exp $ */
+/*	$NetBSD: crypto.c,v 1.37 2011/01/26 19:52:16 christos 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.36 2010/08/11 11:49:09 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.37 2011/01/26 19:52:16 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -76,7 +76,7 @@
 /* below are kludges for residual code wrtitten to FreeBSD interfaces */
   #define SWI_CRYPTO 17
   #define register_swi(lvl, fn)  \
-  softint_establish(SOFTINT_NET, (void (*)(void*))fn, NULL)
+  softint_establish(SOFTINT_NET, (void (*)(void *))fn, NULL)
   #define unregister_swi(lvl, fn)  softint_disestablish(softintr_cookie)
   #define setsoftcrypto(x) softint_schedule(x)
 
@@ -89,7 +89,7 @@
  */
 static	struct cryptocap *crypto_drivers;
 static	int crypto_drivers_num;
-static	void* softintr_cookie;
+static	void *softintr_cookie;
 
 /*
  * There are two queues for crypto requests; one for symmetric (e.g.
@@ -266,7 +266,7 @@
 
 	softintr_cookie = register_swi(SWI_CRYPTO, cryptointr);
 	error = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
-	    (void (*)(void*))cryptoret, NULL, &cryptothread, "cryptoret");
+	    (void (*)(void *))cryptoret, NULL, &cryptothread, "cryptoret");
 	if (error) {
 		printf("crypto_init: cannot start cryptoret thread; error %d",
 			error);
@@ -488,7 +488,7 @@
  */
 int
 crypto_kregister(u_int32_t driverid, int kalg, u_int32_t flags,
-    int (*kprocess)(void*, struct cryptkop *, int),
+    int (*kprocess)(void *, struct cryptkop *, int),
     void *karg)
 {
 	struct cryptocap *cap;
@@ -534,9 +534,9 @@
 int
 crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
     u_int32_t flags,
-    int (*newses)(void*, u_int32_t*, struct cryptoini*),
-    int (*freeses)(void*, u_int64_t),
-    int (*process)(void*, struct cryptop *, int),
+    int (*newses)(void *, u_int32_t*, struct cryptoini*),
+    int (*freeses)(void *, u_int64_t),
+    int (*process)(void *, struct cryptop *, int),
     void *arg)
 {
 	struct cryptocap *cap;
@@ -839,6 +839,7 @@
 		return EINVAL;
 	}
 
+	mutex_spin_enter(&crypto_mtx);
 	for (hid = 0; hid < crypto_drivers_num; hid++) {
 		if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
 		    crypto_devallowsoft == 0)
@@ -851,10 +852,16 @@
 		break;
 	}
 	if (hid < crypto_drivers_num) {
+		int (*process)(void *, struct cryptkop *, int);
+		void *arg;
+
+		process = crypto_drivers[hid].cc_kprocess;
+		arg = crypto_drivers[hid].cc_karg;
+		mutex_spin_exit(&crypto_mtx);
 		krp->krp_hid = hid;
-		error = crypto_drivers[hid].cc_kprocess(
-				crypto_drivers[hid].cc_karg, krp, hint);
+		error = (*process)(arg, krp, hint);
 	} else {
+		mutex_spin_exit(&crypto_mtx);
 		error = ENODEV;
 	}
 
@@ -896,7 +903,6 @@
 crypto_invoke(struct cryptop *crp, int hint)
 {
 	u_int32_t hid;
-	int (*process)(void*, struct cryptop *, int);
 
 #ifdef CRYPTO_TIMING
 	if (crypto_timing)
@@ -915,17 +921,24 @@
 	}
 
 	hid = CRYPTO_SESID2HID(crp->crp_sid);
+
+	mutex_spin_enter(&crypto_mtx);
 	if (hid < crypto_drivers_num) {
-		mutex_spin_enter(&crypto_mtx);
+		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;
 		mutex_spin_exit(&crypto_mtx);
-	} else {
-		process = NULL;
-	}
 
-	if (process == NULL) {
+		/*
+		 * Invoke the driver to process the request.
+		 */
+		DPRINTF(("calling process for %p\n", crp));
+		return (*process)(arg, crp, hint);
+	} else {
 		struct cryptodesc *crd;
 		u_int64_t nid = 0;
 
@@ -933,7 +946,6 @@
 		 * Driver has unregistered; migrate the session and return
 		 * an error to the caller so they'll resubmit the op.
 		 */
-		mutex_spin_enter(&crypto_mtx);
 		for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
 			crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
 
@@ -945,12 +957,6 @@
 
 		crypto_done(crp);
 		return 0;
-	} else {
-		/*
-		 * Invoke the driver to process the request.
-		 */
-		DPRINTF(("calling process for %p\n", crp));
-		return (*process)(crypto_drivers[hid].cc_arg, crp, hint);
 	}
 }
 

Reply via email to