From: guenther Date: Fri, 25 Feb 2022 23:51:03 +0000 (+0000) Subject: Reported-by: syzbot+1b5b209ce506db4d411d@syzkaller.appspotmail.com X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=532245610f13e832eae31acb86682b643d78417a;p=openbsd Reported-by: syzbot+1b5b209ce506db4d411d@syzkaller.appspotmail.com Revert the pr_usrreqs move: syzkaller found a NULL pointer deref and I won't be available to monitor for followup issues for a bit --- diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index e6cae385d4b..cc0ccb55ca1 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_socket.c,v 1.48 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: sys_socket.c,v 1.49 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */ /* @@ -139,11 +139,9 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) } if (IOCGROUP(cmd) == 'r') return (EOPNOTSUPP); - if (so->so_proto->pr_usrreqs->pru_control == NULL) - return (EOPNOTSUPP); KERNEL_LOCK(); - error = ((*so->so_proto->pr_usrreqs->pru_control)(so, cmd, - data, NULL)); + error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, + (struct mbuf *)cmd, (struct mbuf *)data, NULL, p)); KERNEL_UNLOCK(); break; } diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c index c0d9d6f989e..1d19002cc1c 100644 --- a/sys/kern/uipc_proto.c +++ b/sys/kern/uipc_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_proto.c,v 1.21 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: uipc_proto.c,v 1.22 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */ /*- @@ -51,7 +51,8 @@ const struct protosw unixsw[] = { .pr_protocol = PF_UNIX, .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, .pr_usrreq = uipc_usrreq, - .pr_usrreqs = &uipc_usrreqs, + .pr_attach = uipc_attach, + .pr_detach = uipc_detach, }, { .pr_type = SOCK_SEQPACKET, @@ -59,7 +60,8 @@ const struct protosw unixsw[] = { .pr_protocol = PF_UNIX, .pr_flags = PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, .pr_usrreq = uipc_usrreq, - .pr_usrreqs = &uipc_usrreqs, + .pr_attach = uipc_attach, + .pr_detach = uipc_detach, }, { .pr_type = SOCK_DGRAM, @@ -67,7 +69,8 @@ const struct protosw unixsw[] = { .pr_protocol = PF_UNIX, .pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS, .pr_usrreq = uipc_usrreq, - .pr_usrreqs = &uipc_usrreqs, + .pr_attach = uipc_attach, + .pr_detach = uipc_detach, } }; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 084f9c44edc..0d721fbed00 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.274 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.275 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -169,7 +169,7 @@ socreate(int dom, struct socket **aso, int type, int proto) prp = pffindproto(dom, proto, type); else prp = pffindtype(dom, type); - if (prp == NULL || prp->pr_usrreqs->pru_attach == NULL) + if (prp == NULL || prp->pr_attach == NULL) return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); @@ -192,7 +192,7 @@ socreate(int dom, struct socket **aso, int type, int proto) so->so_rcv.sb_timeo_nsecs = INFSLP; s = solock(so); - error = (*prp->pr_usrreqs->pru_attach)(so, proto); + error = (*prp->pr_attach)(so, proto); if (error) { so->so_state |= SS_NOFDREF; /* sofree() calls sounlock(). */ @@ -347,8 +347,8 @@ soclose(struct socket *so, int flags) drop: if (so->so_pcb) { int error2; - KASSERT(so->so_proto->pr_usrreqs->pru_detach != NULL); - error2 = (*so->so_proto->pr_usrreqs->pru_detach)(so); + KASSERT(so->so_proto->pr_detach); + error2 = (*so->so_proto->pr_detach)(so); if (error == 0) error = error2; } diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index df506fd5ada..befc826548d 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.119 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.120 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -150,7 +150,7 @@ sonewconn(struct socket *head, int connstatus) /* * XXXSMP as long as `so' and `head' share the same lock, we - * can call soreserve() and pru_attach() below w/o explicitly + * can call soreserve() and pr_attach() below w/o explicitly * locking `so'. */ soassertlocked(head); @@ -194,7 +194,7 @@ sonewconn(struct socket *head, int connstatus) sigio_copy(&so->so_sigio, &head->so_sigio); soqinsque(head, so, soqueue); - if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0)) { + if ((*so->so_proto->pr_attach)(so, 0)) { (void) soqremque(so, soqueue); sigio_free(&so->so_sigio); klist_free(&so->so_rcv.sb_sel.si_note); diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index a25bda5a765..a4538f2c805 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.162 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.163 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -150,6 +150,8 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct socket *so2; int error = 0; + if (req == PRU_CONTROL) + return (EOPNOTSUPP); if (req != PRU_SEND && control && control->m_len) { error = EOPNOTSUPP; goto release; @@ -470,11 +472,6 @@ uipc_detach(struct socket *so) return (0); } -const struct pr_usrreqs uipc_usrreqs = { - .pru_attach = uipc_attach, - .pru_detach = uipc_detach, -}; - int uipc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) diff --git a/sys/net/if.c b/sys/net/if.c index c7a3f6b1924..b29620db8ac 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.648 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: if.c,v 1.649 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2258,12 +2258,11 @@ forceup: break; /* FALLTHROUGH */ default: - if (so->so_proto->pr_usrreqs->pru_control != NULL) { - error = ((*so->so_proto->pr_usrreqs->pru_control)(so, - cmd, data, ifp)); - if (error != EOPNOTSUPP) - break; - } + error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, + (struct mbuf *) cmd, (struct mbuf *) data, + (struct mbuf *) ifp, p)); + if (error != EOPNOTSUPP) + break; switch (cmd) { case SIOCAIFADDR: case SIOCDIFADDR: diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index fc08630cfb6..f89f1449f1f 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.230 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.231 2022/02/25 23:51:03 guenther Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -199,11 +199,6 @@ pfdatatopacket(void *data, int len, struct mbuf **packet) return (0); } -const struct pr_usrreqs pfkeyv2_usrreqs = { - .pru_attach = pfkeyv2_attach, - .pru_detach = pfkeyv2_detach, -}; - const struct protosw pfkeysw[] = { { .pr_type = SOCK_RAW, @@ -212,7 +207,8 @@ const struct protosw pfkeysw[] = { .pr_flags = PR_ATOMIC | PR_ADDR, .pr_output = pfkeyv2_output, .pr_usrreq = pfkeyv2_usrreq, - .pr_usrreqs = &pfkeyv2_usrreqs, + .pr_attach = pfkeyv2_attach, + .pr_detach = pfkeyv2_detach, .pr_sysctl = pfkeyv2_sysctl, } }; @@ -339,6 +335,9 @@ pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, struct pkpcb *kp; int error = 0; + if (req == PRU_CONTROL) + return (EOPNOTSUPP); + soassertlocked(so); if (control && control->m_len) { diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 9a9d6f40c4b..da157d46e0e 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.325 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: rtsock.c,v 1.326 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -214,6 +214,9 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct rtpcb *rop; int error = 0; + if (req == PRU_CONTROL) + return (EOPNOTSUPP); + soassertlocked(so); if (control && control->m_len) { @@ -2386,11 +2389,6 @@ rt_setsource(unsigned int rtableid, struct sockaddr *src) * Definitions of protocols supported in the ROUTE domain. */ -const struct pr_usrreqs route_usrreqs = { - .pru_attach = route_attach, - .pru_detach = route_detach, -}; - const struct protosw routesw[] = { { .pr_type = SOCK_RAW, @@ -2399,7 +2397,8 @@ const struct protosw routesw[] = { .pr_output = route_output, .pr_ctloutput = route_ctloutput, .pr_usrreq = route_usrreq, - .pr_usrreqs = &route_usrreqs, + .pr_attach = route_attach, + .pr_detach = route_detach, .pr_init = route_prinit, .pr_sysctl = sysctl_rtable } diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 15d63ac295f..9a81ad184c7 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.97 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: in_proto.c,v 1.98 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -190,7 +190,8 @@ const struct protosw inetsw[] = { .pr_ctlinput = udp_ctlinput, .pr_ctloutput = ip_ctloutput, .pr_usrreq = udp_usrreq, - .pr_usrreqs = &udp_usrreqs, + .pr_attach = udp_attach, + .pr_detach = udp_detach, .pr_init = udp_init, .pr_sysctl = udp_sysctl }, @@ -203,7 +204,8 @@ const struct protosw inetsw[] = { .pr_ctlinput = tcp_ctlinput, .pr_ctloutput = tcp_ctloutput, .pr_usrreq = tcp_usrreq, - .pr_usrreqs = &tcp_usrreqs, + .pr_attach = tcp_attach, + .pr_detach = tcp_detach, .pr_init = tcp_init, .pr_slowtimo = tcp_slowtimo, .pr_sysctl = tcp_sysctl @@ -216,7 +218,8 @@ const struct protosw inetsw[] = { .pr_input = rip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, }, { .pr_type = SOCK_RAW, @@ -226,7 +229,8 @@ const struct protosw inetsw[] = { .pr_input = icmp_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_init = icmp_init, .pr_sysctl = icmp_sysctl }, @@ -242,7 +246,8 @@ const struct protosw inetsw[] = { #endif .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ipip_sysctl, .pr_init = ipip_init }, @@ -259,7 +264,8 @@ const struct protosw inetsw[] = { #endif .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, /* XXX */ - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, }, #endif #if defined(MPLS) && NGIF > 0 @@ -270,7 +276,8 @@ const struct protosw inetsw[] = { .pr_flags = PR_ATOMIC|PR_ADDR, .pr_input = in_gif_input, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, }, #endif /* MPLS && GIF */ { @@ -281,7 +288,8 @@ const struct protosw inetsw[] = { .pr_input = igmp_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_init = igmp_init, .pr_fasttimo = igmp_fasttimo, .pr_slowtimo = igmp_slowtimo, @@ -297,7 +305,8 @@ const struct protosw inetsw[] = { .pr_ctlinput = ah4_ctlinput, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ah_sysctl }, { @@ -309,7 +318,8 @@ const struct protosw inetsw[] = { .pr_ctlinput = esp4_ctlinput, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = esp_sysctl }, { @@ -320,7 +330,8 @@ const struct protosw inetsw[] = { .pr_input = ipcomp46_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ipcomp_sysctl }, #endif /* IPSEC */ @@ -333,7 +344,8 @@ const struct protosw inetsw[] = { .pr_input = gre_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = gre_usrreq, - .pr_usrreqs = &gre_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = gre_sysctl }, #endif /* NGRE > 0 */ @@ -346,7 +358,8 @@ const struct protosw inetsw[] = { .pr_input = carp_proto_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = carp_sysctl }, #endif /* NCARP > 0 */ @@ -359,7 +372,8 @@ const struct protosw inetsw[] = { .pr_input = pfsync_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = pfsync_sysctl }, #endif /* NPFSYNC > 0 */ @@ -371,7 +385,8 @@ const struct protosw inetsw[] = { .pr_flags = PR_ATOMIC|PR_ADDR, .pr_ctloutput = rip_ctloutput, .pr_usrreq = divert_usrreq, - .pr_usrreqs = &divert_usrreqs, + .pr_attach = divert_attach, + .pr_detach = divert_detach, .pr_init = divert_init, .pr_sysctl = divert_sysctl }, @@ -385,7 +400,8 @@ const struct protosw inetsw[] = { .pr_input = ip_etherip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = etherip_sysctl }, #endif /* NETHERIP */ @@ -397,7 +413,8 @@ const struct protosw inetsw[] = { .pr_input = rip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_usrreqs = &rip_usrreqs, + .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_init = rip_init } }; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index d99c6dde5be..5b987fb7561 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.65 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.66 2022/02/25 23:51:03 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -41,9 +41,6 @@ #include -int divert_attach(struct socket *, int); -int divert_detach(struct socket *); - struct inpcbtable divbtable; struct cpumem *divcounters; @@ -246,6 +243,11 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp = sotoinpcb(so); int error = 0; + if (req == PRU_CONTROL) { + return (in_control(so, (u_long)m, (caddr_t)addr, + (struct ifnet *)control)); + } + soassertlocked(so); if (inp == NULL) { @@ -344,12 +346,6 @@ divert_detach(struct socket *so) return (0); } -const struct pr_usrreqs divert_usrreqs = { - .pru_attach = divert_attach, - .pru_detach = divert_detach, - .pru_control = in_control, -}; - int divert_sysctl_divstat(void *oldp, size_t *oldlenp, void *newp) { diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h index 3062c7eb72e..11780b57956 100644 --- a/sys/netinet/ip_divert.h +++ b/sys/netinet/ip_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.h,v 1.13 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip_divert.h,v 1.14 2022/02/25 23:51:03 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,7 +70,7 @@ int divert_packet(struct mbuf *, int, u_int16_t); int divert_sysctl(int *, u_int, void *, size_t *, void *, size_t); int divert_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); - -extern const struct pr_usrreqs divert_usrreqs; +int divert_attach(struct socket *, int); +int divert_detach(struct socket *); #endif /* _KERNEL */ #endif /* _IP_DIVERT_H_ */ diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 0e7e2643931..eb68cb0b752 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.c,v 1.72 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip_gre.c,v 1.73 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -92,9 +92,4 @@ gre_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, #endif return rip_usrreq(so, req, m, nam, control, p); } - -const struct pr_usrreqs gre_usrreqs = { - .pru_attach = rip_attach, - .pru_detach = rip_detach, -}; #endif /* if NGRE > 0 */ diff --git a/sys/netinet/ip_gre.h b/sys/netinet/ip_gre.h index 033ca8684e7..7645ae15cc2 100644 --- a/sys/netinet/ip_gre.h +++ b/sys/netinet/ip_gre.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_gre.h,v 1.15 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip_gre.h,v 1.16 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: ip_gre.h,v 1.3 1998/10/07 23:33:02 thorpej Exp $ */ /* @@ -54,7 +54,5 @@ #ifdef _KERNEL int gre_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); - -extern const struct pr_usrreqs gre_usrreqs; #endif /* _KERNEL */ #endif /* _NETINET_IP_GRE_H_ */ diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index fb621024127..22cf4383019 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.89 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip_var.h,v 1.90 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -261,9 +261,6 @@ int rip_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int rip_attach(struct socket *, int); int rip_detach(struct socket *); - -extern const struct pr_usrreqs rip_usrreqs; - #ifdef MROUTING extern struct socket *ip_mrouter[]; /* multicast routing daemon */ #endif diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 46724bb97cd..b2e81678e90 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.120 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.121 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -432,6 +432,10 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct inpcb *inp; int error = 0; + if (req == PRU_CONTROL) + return (in_control(so, (u_long)m, (caddr_t)nam, + (struct ifnet *)control)); + soassertlocked(so); inp = sotoinpcb(so); @@ -613,9 +617,3 @@ rip_detach(struct socket *so) return (0); } - -const struct pr_usrreqs rip_usrreqs = { - .pru_attach = rip_attach, - .pru_detach = rip_detach, - .pru_control = in_control, -}; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 945b4299edb..67035bd4553 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.182 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.183 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -100,9 +100,6 @@ #include #endif -int tcp_attach(struct socket *, int); -int tcp_detach(struct socket *); - #ifndef TCP_SENDSPACE #define TCP_SENDSPACE 1024*16 #endif @@ -152,6 +149,17 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, int error = 0; short ostate; + if (req == PRU_CONTROL) { +#ifdef INET6 + if (sotopf(so) == PF_INET6) + return in6_control(so, (u_long)m, (caddr_t)nam, + (struct ifnet *)control); + else +#endif /* INET6 */ + return (in_control(so, (u_long)m, (caddr_t)nam, + (struct ifnet *)control)); + } + soassertlocked(so); if (control && control->m_len) { @@ -661,19 +669,6 @@ tcp_detach(struct socket *so) return (error); } -const struct pr_usrreqs tcp_usrreqs = { - .pru_attach = tcp_attach, - .pru_detach = tcp_detach, - .pru_control = in_control, -}; -#ifdef INET6 -const struct pr_usrreqs tcp6_usrreqs = { - .pru_attach = tcp_attach, - .pru_detach = tcp_detach, - .pru_control = in6_control, -}; -#endif - /* * Initiate (or continue) disconnect. * If embryonic state, just send reset (once). diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 927ad2b3fcf..7d8f615d4d2 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.138 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.139 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -703,6 +703,8 @@ struct tcpcb * int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t); int tcp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); +int tcp_attach(struct socket *, int); +int tcp_detach(struct socket *); void tcp_xmit_timer(struct tcpcb *, int); void tcpdropoldhalfopen(struct tcpcb *, u_int16_t); void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int); @@ -736,10 +738,5 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp, } #endif -extern const struct pr_usrreqs tcp_usrreqs; -#ifdef INET6 -extern const struct pr_usrreqs tcp6_usrreqs; -#endif - #endif /* _KERNEL */ #endif /* _NETINET_TCP_VAR_H_ */ diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 3e2f2a1a34a..e5069f1d395 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.270 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.271 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -112,9 +112,6 @@ #include #endif -int udp_attach(struct socket *, int); -int udp_detach(struct socket *); - /* * UDP protocol implementation. * Per RFC 768, August, 1980. @@ -1030,6 +1027,17 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp; int error = 0; + if (req == PRU_CONTROL) { +#ifdef INET6 + if (sotopf(so) == PF_INET6) + return (in6_control(so, (u_long)m, (caddr_t)addr, + (struct ifnet *)control)); + else +#endif /* INET6 */ + return (in_control(so, (u_long)m, (caddr_t)addr, + (struct ifnet *)control)); + } + soassertlocked(so); inp = sotoinpcb(so); @@ -1242,19 +1250,6 @@ udp_detach(struct socket *so) return (0); } -const struct pr_usrreqs udp_usrreqs = { - .pru_attach = udp_attach, - .pru_detach = udp_detach, - .pru_control = in_control, -}; -#ifdef INET6 -const struct pr_usrreqs udp6_usrreqs = { - .pru_attach = udp_attach, - .pru_detach = udp_detach, - .pru_control = in6_control, -}; -#endif - /* * Sysctl for udp variables. */ diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index aa1eeba09c4..8042f407103 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.36 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: udp_var.h,v 1.37 2022/02/25 23:51:03 guenther Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -139,10 +139,7 @@ int udp6_output(struct inpcb *, struct mbuf *, struct mbuf *, int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t); int udp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); - -extern const struct pr_usrreqs udp_usrreqs; -#ifdef INET6 -extern const struct pr_usrreqs udp6_usrreqs; -#endif +int udp_attach(struct socket *, int); +int udp_detach(struct socket *); #endif /* _KERNEL */ #endif /* _NETINET_UDP_VAR_H_ */ diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 85d660b3516..0f7a96af941 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.245 2022/02/25 08:33:26 guenther Exp $ */ +/* $OpenBSD: in6.c,v 1.246 2022/02/25 23:51:04 guenther Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -115,6 +115,7 @@ const struct in6_addr in6mask64 = IN6MASK64; const struct in6_addr in6mask96 = IN6MASK96; const struct in6_addr in6mask128 = IN6MASK128; +int in6_ioctl(u_long, caddr_t, struct ifnet *, int); int in6_ioctl_change_ifaddr(u_long, caddr_t, struct ifnet *); int in6_ioctl_get(u_long, caddr_t, struct ifnet *); int in6_check_embed_scope(struct sockaddr_in6 *, unsigned int); diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 8e523d13404..3e2675d8a1c 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.108 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.109 2022/02/25 23:51:04 guenther Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -141,7 +141,8 @@ const struct protosw inet6sw[] = { .pr_ctlinput = udp6_ctlinput, .pr_ctloutput = ip6_ctloutput, .pr_usrreq = udp_usrreq, - .pr_usrreqs = &udp6_usrreqs, + .pr_attach = udp_attach, + .pr_detach = udp_detach, .pr_sysctl = udp_sysctl }, { @@ -153,7 +154,8 @@ const struct protosw inet6sw[] = { .pr_ctlinput = tcp6_ctlinput, .pr_ctloutput = tcp_ctloutput, .pr_usrreq = tcp_usrreq, - .pr_usrreqs = &tcp6_usrreqs, + .pr_attach = tcp_attach, + .pr_detach = tcp_detach, .pr_sysctl = tcp_sysctl }, { @@ -165,7 +167,8 @@ const struct protosw inet6sw[] = { .pr_ctlinput = rip6_ctlinput, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = rip6_sysctl }, { @@ -177,7 +180,8 @@ const struct protosw inet6sw[] = { .pr_ctlinput = rip6_ctlinput, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_init = icmp6_init, .pr_fasttimo = icmp6_fasttimo, .pr_sysctl = icmp6_sysctl @@ -212,7 +216,8 @@ const struct protosw inet6sw[] = { .pr_input = ah46_input, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = ah_sysctl }, { @@ -223,7 +228,8 @@ const struct protosw inet6sw[] = { .pr_input = esp46_input, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = esp_sysctl }, { @@ -234,7 +240,8 @@ const struct protosw inet6sw[] = { .pr_input = ipcomp46_input, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = ipcomp_sysctl }, #endif /* IPSEC */ @@ -250,7 +257,8 @@ const struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, { .pr_type = SOCK_RAW, @@ -264,7 +272,8 @@ const struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, #if defined(MPLS) && NGIF > 0 { @@ -279,7 +288,8 @@ const struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, #endif /* MPLS */ #if NCARP > 0 @@ -291,7 +301,8 @@ const struct protosw inet6sw[] = { .pr_input = carp6_proto_input, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = carp_sysctl }, #endif /* NCARP */ @@ -303,7 +314,8 @@ const struct protosw inet6sw[] = { .pr_flags = PR_ATOMIC|PR_ADDR, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = divert6_usrreq, - .pr_usrreqs = &divert6_usrreqs, + .pr_attach = divert6_attach, + .pr_detach = divert6_detach, .pr_init = divert6_init, .pr_sysctl = divert6_sysctl }, @@ -317,7 +329,8 @@ const struct protosw inet6sw[] = { .pr_input = ip6_etherip_input, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, #endif /* NETHERIP */ #if NGRE > 0 @@ -329,7 +342,8 @@ const struct protosw inet6sw[] = { .pr_input = gre_input6, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, #endif /* NGRE */ { @@ -340,7 +354,8 @@ const struct protosw inet6sw[] = { .pr_input = rip6_input, .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, - .pr_usrreqs = &rip6_usrreqs, + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_init = rip6_init } }; diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index fc83232dde1..083e0938fb3 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.64 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.65 2022/02/25 23:51:04 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -42,9 +42,6 @@ #include -int divert6_attach(struct socket *, int); -int divert6_detach(struct socket *); - struct inpcbtable divb6table; struct cpumem *div6counters; @@ -251,6 +248,11 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp = sotoinpcb(so); int error = 0; + if (req == PRU_CONTROL) { + return (in6_control(so, (u_long)m, (caddr_t)addr, + (struct ifnet *)control)); + } + soassertlocked(so); if (inp == NULL) { @@ -350,12 +352,6 @@ divert6_detach(struct socket *so) return (0); } -const struct pr_usrreqs divert6_usrreqs = { - .pru_attach = divert6_attach, - .pru_detach = divert6_detach, - .pru_control = in6_control, -}; - int divert6_sysctl_div6stat(void *oldp, size_t *oldlenp, void *newp) { diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h index 51b524069b5..2cdac520317 100644 --- a/sys/netinet6/ip6_divert.h +++ b/sys/netinet6/ip6_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.h,v 1.11 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip6_divert.h,v 1.12 2022/02/25 23:51:04 guenther Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -70,8 +70,8 @@ int divert6_packet(struct mbuf *, int, u_int16_t); int divert6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int divert6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); - -extern const struct pr_usrreqs divert6_usrreqs; +int divert6_attach(struct socket *, int); +int divert6_detach(struct socket *); #endif /* _KERNEL */ #endif /* _IP6_DIVERT_H_ */ diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index a3c86ef4519..8460fbda64c 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.90 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.91 2022/02/25 23:51:04 guenther Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -348,6 +348,8 @@ int rip6_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); int rip6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); +int rip6_attach(struct socket *, int); +int rip6_detach(struct socket *); int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int dest6_input(struct mbuf **, int *, int, int); @@ -369,8 +371,6 @@ int ip6_output_ipsec_send(struct tdb *, struct mbuf *, struct route_in6 *, int, int); #endif /* IPSEC */ -extern const struct pr_usrreqs rip6_usrreqs; - #endif /* _KERNEL */ #endif /* !_NETINET6_IP6_VAR_H_ */ diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 5f31d59c8ca..80ea8ef7b6f 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.140 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.141 2022/02/25 23:51:04 guenther Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -97,9 +97,6 @@ #include -int rip6_attach(struct socket *, int); -int rip6_detach(struct socket *); - /* * Raw interface to IP6 protocol. */ @@ -562,6 +559,10 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct inpcb *in6p; int error = 0; + if (req == PRU_CONTROL) + return (in6_control(so, (u_long)m, (caddr_t)nam, + (struct ifnet *)control)); + soassertlocked(so); in6p = sotoinpcb(so); @@ -765,12 +766,6 @@ rip6_detach(struct socket *so) return (0); } -const struct pr_usrreqs rip6_usrreqs = { - .pru_attach = rip6_attach, - .pru_detach = rip6_detach, - .pru_control = in6_control, -}; - int rip6_sysctl_rip6stat(void *oldp, size_t *oldplen, void *newp) { diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index c7feca678e8..a494fe3edd7 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.34 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: protosw.h,v 1.35 2022/02/25 23:51:04 guenther Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -58,7 +58,6 @@ struct sockaddr; struct socket; struct domain; struct proc; -struct pr_usrreqs; struct protosw { short pr_type; /* socket type used for */ @@ -81,7 +80,9 @@ struct protosw { /* user request: see list below */ int (*pr_usrreq)(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); - const struct pr_usrreqs *pr_usrreqs; + + int (*pr_attach)(struct socket *, int); + int (*pr_detach)(struct socket *); /* utility hooks */ void (*pr_init)(void); /* initialization hook */ @@ -226,15 +227,7 @@ char *prcorequests[] = { #endif #ifdef _KERNEL -struct ifnet; - -struct pr_usrreqs { - int (*pru_attach)(struct socket *, int _proto); - int (*pru_detach)(struct socket *); - int (*pru_control)(struct socket *, u_long _cmd, caddr_t _data, - struct ifnet *_ifp); -}; - +struct sockaddr; const struct protosw *pffindproto(int, int, int); const struct protosw *pffindtype(int, int); void pfctlinput(int, struct sockaddr *); diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index 156aa3c538c..b3641bde092 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.24 2022/02/25 08:36:01 guenther Exp $ */ +/* $OpenBSD: unpcb.h,v 1.25 2022/02/25 23:51:04 guenther Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -120,6 +120,4 @@ void unp_shutdown(struct unpcb *); int unp_externalize(struct mbuf *, socklen_t, int); int unp_internalize(struct mbuf *, struct proc *); void unp_dispose(struct mbuf *); - -extern const struct pr_usrreqs uipc_usrreqs; #endif /* _KERNEL */