Module Name:    src
Committed By:   pgoyette
Date:           Mon Oct 15 11:57:06 UTC 2018

Modified Files:
        src/sys/compat/common [pgoyette-compat]: compat_70_mod.c
            uipc_usrreq_70.c
        src/sys/compat/sys [pgoyette-compat]: socket.h
        src/sys/kern [pgoyette-compat]: compat_stub.c uipc_usrreq.c
        src/sys/sys [pgoyette-compat]: compat_stub.h

Log Message:
Convert the compat70_unp_addsockcred hook to the MP-safe mechanism.

XXX One more remaining: sysvipc50_sysctl


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.11 -r1.1.2.12 src/sys/compat/common/compat_70_mod.c
cvs rdiff -u -r1.1.20.2 -r1.1.20.3 src/sys/compat/common/uipc_usrreq_70.c
cvs rdiff -u -r1.15 -r1.15.2.1 src/sys/compat/sys/socket.h
cvs rdiff -u -r1.1.2.30 -r1.1.2.31 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.183.2.4 -r1.183.2.5 src/sys/kern/uipc_usrreq.c
cvs rdiff -u -r1.1.2.42 -r1.1.2.43 src/sys/sys/compat_stub.h

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

Modified files:

Index: src/sys/compat/common/compat_70_mod.c
diff -u src/sys/compat/common/compat_70_mod.c:1.1.2.11 src/sys/compat/common/compat_70_mod.c:1.1.2.12
--- src/sys/compat/common/compat_70_mod.c:1.1.2.11	Mon Oct 15 09:51:33 2018
+++ src/sys/compat/common/compat_70_mod.c	Mon Oct 15 11:57:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_70_mod.c,v 1.1.2.11 2018/10/15 09:51:33 pgoyette Exp $	*/
+/*	$NetBSD: compat_70_mod.c,v 1.1.2.12 2018/10/15 11:57:05 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_70_mod.c,v 1.1.2.11 2018/10/15 09:51:33 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_70_mod.c,v 1.1.2.12 2018/10/15 11:57:05 pgoyette Exp $");
 
 #include <sys/systm.h>
 #include <sys/module.h>
@@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: compat_70_mo
 #include <compat/common/compat_util.h>
 #include <compat/common/compat_mod.h>
 #include <compat/sys/sockio.h>
+#include <compat/sys/socket.h>
 
 #include <compat/net/route.h>
 #include <compat/net/route_70.h>
@@ -58,6 +59,7 @@ int compat_70_init(void)
 
 	compat70_ocreds_valid = true;
 	rtsock_70_init();
+	uipc_usrreq_70_init();
 
 	return 0;
 }
@@ -65,6 +67,7 @@ int compat_70_init(void)
 int compat_70_fini(void)
 {
 
+	uipc_usrreq_70_fini();
 	rtsock_70_fini();
 	compat70_ocreds_valid = false;
 

Index: src/sys/compat/common/uipc_usrreq_70.c
diff -u src/sys/compat/common/uipc_usrreq_70.c:1.1.20.2 src/sys/compat/common/uipc_usrreq_70.c:1.1.20.3
--- src/sys/compat/common/uipc_usrreq_70.c:1.1.20.2	Sat Sep 22 04:56:28 2018
+++ src/sys/compat/common/uipc_usrreq_70.c	Mon Oct 15 11:57:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_usrreq_70.c,v 1.1.20.2 2018/09/22 04:56:28 pgoyette Exp $	*/
+/*	$NetBSD: uipc_usrreq_70.c,v 1.1.20.3 2018/10/15 11:57:05 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq_70.c,v 1.1.20.2 2018/09/22 04:56:28 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq_70.c,v 1.1.20.3 2018/10/15 11:57:05 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -43,11 +43,12 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_usrreq_
 #include <sys/unpcb.h>
 #include <sys/mbuf.h>
 #include <sys/kauth.h>
+#include <sys/compat_stub.h>
 
 #include <compat/sys/socket.h>
 
-struct mbuf *
-compat_70_unp_addsockcred(struct lwp *l, struct mbuf *control)
+int
+compat_70_unp_addsockcred(struct mbuf **ret, struct lwp *l, struct mbuf *control)
 {
 	struct sockcred70 *sc;
 	struct mbuf *m;
@@ -55,8 +56,10 @@ compat_70_unp_addsockcred(struct lwp *l,
 
 	m = sbcreatecontrol1(&p, SOCKCRED70SIZE(kauth_cred_ngroups(l->l_cred)),
 		SCM_OCREDS, SOL_SOCKET, M_WAITOK);
-	if (m == NULL)
-		return control;
+	if (m == NULL) {
+		*ret = control;
+		return 0;
+	}
 
 	sc = p;
 	sc->sc_uid = kauth_cred_getuid(l->l_cred);
@@ -68,5 +71,23 @@ compat_70_unp_addsockcred(struct lwp *l,
 	for (int i = 0; i < sc->sc_ngroups; i++)
 		sc->sc_groups[i] = kauth_cred_group(l->l_cred, i);
 
-	return m_add(control, m);
+	*ret = m_add(control, m);
+	return 0;
+}
+
+MODULE_SET_HOOK(compat_70_unp_hook, "unp_70", compat_70_unp_addsockcred);
+MODULE_UNSET_HOOK(compat_70_unp_hook);
+
+void
+uipc_usrreq_70_init(void)
+{
+
+	compat_70_unp_hook_set();
+}
+
+void
+uipc_usrreq_70_fini(void)
+{
+
+	compat_70_unp_hook_unset();
 }

Index: src/sys/compat/sys/socket.h
diff -u src/sys/compat/sys/socket.h:1.15 src/sys/compat/sys/socket.h:1.15.2.1
--- src/sys/compat/sys/socket.h:1.15	Sat Jul 29 06:12:50 2017
+++ src/sys/compat/sys/socket.h	Mon Oct 15 11:57:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: socket.h,v 1.15 2017/07/29 06:12:50 maxv Exp $	*/
+/*	$NetBSD: socket.h,v 1.15.2.1 2018/10/15 11:57:05 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
@@ -105,7 +105,10 @@ u_long compat_cvtcmd(u_long cmd);
 int compat_ifioctl(struct socket *, u_long, u_long, void *, struct lwp *);
 int compat43_set_accrights(struct msghdr *, void *, int);
 
-struct mbuf * compat_70_unp_addsockcred(struct lwp *, struct mbuf *);
+int compat_70_unp_addsockcred(struct mbuf **, struct lwp *, struct mbuf *);
+
+void uipc_usrreq_70_init(void);
+void uipc_usrreq_70_fini(void);
 __END_DECLS
 #else
 int	__socket30(int, int, int);

Index: src/sys/kern/compat_stub.c
diff -u src/sys/kern/compat_stub.c:1.1.2.30 src/sys/kern/compat_stub.c:1.1.2.31
--- src/sys/kern/compat_stub.c:1.1.2.30	Mon Oct 15 10:44:27 2018
+++ src/sys/kern/compat_stub.c	Mon Oct 15 11:57:05 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.c,v 1.1.2.30 2018/10/15 10:44:27 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.c,v 1.1.2.31 2018/10/15 11:57:05 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -198,3 +198,8 @@ struct compat_60_ioctl_hook_t compat_60_
  */
 struct compat_10_openat_hook_t compat_10_openat_hook;
 
+/*
+ * Hook for compat_70_unp_addsockcred
+ */
+struct compat_70_unp_hook_t compat_70_unp_hook;
+

Index: src/sys/kern/uipc_usrreq.c
diff -u src/sys/kern/uipc_usrreq.c:1.183.2.4 src/sys/kern/uipc_usrreq.c:1.183.2.5
--- src/sys/kern/uipc_usrreq.c:1.183.2.4	Mon Oct 15 09:51:34 2018
+++ src/sys/kern/uipc_usrreq.c	Mon Oct 15 11:57:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_usrreq.c,v 1.183.2.4 2018/10/15 09:51:34 pgoyette Exp $	*/
+/*	$NetBSD: uipc_usrreq.c,v 1.183.2.5 2018/10/15 11:57:05 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.183.2.4 2018/10/15 09:51:34 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.183.2.5 2018/10/15 11:57:05 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -123,6 +123,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.
 #include <sys/uidinfo.h>
 #include <sys/kernel.h>
 #include <sys/kthread.h>
+#include <sys/compat_stub.h>
 
 #include <compat/sys/socket.h>
 
@@ -197,16 +198,15 @@ static int unp_defer;
 
 /* Compat interface */
 
-static struct mbuf *stub_compat_70_unp_addsockcred(lwp_t *, struct mbuf *);
-struct mbuf *(*vec_compat_70_unp_addsockcred)(struct lwp *, struct mbuf *) =
-    stub_compat_70_unp_addsockcred;
+int stub_compat_70_unp_addsockcred(struct mbuf **, lwp_t *, struct mbuf *);
 
-struct mbuf *stub_compat_70_unp_addsockcred(struct lwp *lwp,
+int stub_compat_70_unp_addsockcred(struct mbuf** ret, struct lwp *lwp,
     struct mbuf *control)
 {
 
 	/* just return our initial argument */
-	return control;
+	*ret = control;
+	return 0;
 }
 
 bool *compat70_ocreds_valid = false;
@@ -331,6 +331,12 @@ unp_free(struct unpcb *unp)
 	kmem_free(unp, sizeof(*unp));
 }
 
+MODULE_CALL_HOOK_DECL(compat_70_unp_hook, f,
+    (struct mbuf **, struct lwp *, struct mbuf *));
+MODULE_CALL_HOOK(compat_70_unp_hook, f,
+    (struct mbuf **ret, struct lwp *lwp, struct mbuf *control),
+    (ret, lwp, control), stub_compat_70_unp_addsockcred(ret, lwp, control));
+
 static int
 unp_output(struct mbuf *m, struct mbuf *control, struct unpcb *unp)
 {
@@ -351,7 +357,7 @@ unp_output(struct mbuf *m, struct mbuf *
 	if (unp->unp_conn->unp_flags & UNP_WANTCRED)
 		control = unp_addsockcred(curlwp, control);
 	if (unp->unp_conn->unp_flags & UNP_OWANTCRED)
-		control = (*vec_compat_70_unp_addsockcred)(curlwp, control);
+		compat_70_unp_hook_f_call(&control, curlwp, control);
 	if (sbappendaddr(&so2->so_rcv, (const struct sockaddr *)sun, m,
 	    control) == 0) {
 		unp_dispose(control);
@@ -530,7 +536,7 @@ unp_send(struct socket *so, struct mbuf 
 			 * SOCK_STREAM and SOCK_SEQPACKET.
 			 */
 			unp->unp_conn->unp_flags &= ~UNP_OWANTCRED;
-			control = (*vec_compat_70_unp_addsockcred)(l, control);
+			compat_70_unp_hook_f_call(&control, curlwp, control);
 		}
 		/*
 		 * Send to paired receive port, and then reduce

Index: src/sys/sys/compat_stub.h
diff -u src/sys/sys/compat_stub.h:1.1.2.42 src/sys/sys/compat_stub.h:1.1.2.43
--- src/sys/sys/compat_stub.h:1.1.2.42	Mon Oct 15 10:44:28 2018
+++ src/sys/sys/compat_stub.h	Mon Oct 15 11:57:05 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.42 2018/10/15 10:44:28 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.h,v 1.1.2.43 2018/10/15 11:57:05 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -251,4 +251,10 @@ MODULE_HOOK2(compat_60_ioctl_hook, (dev_
 struct pathbuf;
 MODULE_HOOK(compat_10_openat_hook, (struct pathbuf **));
 
+/*
+ * Hook for compat_70_unp_addsockcred
+ */
+struct mbuf;
+MODULE_HOOK(compat_70_unp_hook, (struct mbuf **, struct lwp *, struct mbuf *));
+
 #endif	/* _SYS_COMPAT_STUB_H */

Reply via email to