From 4fb053a8d5cca51b3ebdf34a236bd5320909952f Mon Sep 17 00:00:00 2001 From: Paul Irofti Date: Tue, 24 Apr 2018 15:40:56 +0000 Subject: Push NET_LOCK down in the default ifioctl case. For the PRU_CONTROL bit the NET_LOCK surrounds in[6]_control() and on the ENOTSUPP case we guard the driver if_ioctl functions. OK mpi@ --- sys/net/if.c | 9 +++++---- sys/net/raw_usrreq.c | 7 ++++--- sys/netinet/in.c | 13 ++++++++++--- sys/netinet/ip_divert.c | 7 ++++--- sys/netinet/raw_ip.c | 6 +++--- sys/netinet/tcp_usrreq.c | 7 ++++--- sys/netinet/udp_usrreq.c | 6 +++--- sys/netinet6/in6.c | 13 ++++++++++--- sys/netinet6/ip6_divert.c | 7 ++++--- sys/netinet6/raw_ip6.c | 6 +++--- 10 files changed, 50 insertions(+), 31 deletions(-) (limited to 'sys') diff --git a/sys/net/if.c b/sys/net/if.c index 4905b757210..d8eb308f899 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.549 2018/03/20 08:58:19 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.550 2018/04/24 15:40:55 pirofti Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2126,13 +2126,14 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) break; /* FALLTHROUGH */ default: - NET_LOCK(); error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, (struct mbuf *) cmd, (struct mbuf *) data, (struct mbuf *) ifp, p)); - if (error == EOPNOTSUPP) + if (error == EOPNOTSUPP) { + NET_LOCK(); error = ((*ifp->if_ioctl)(ifp, cmd, data)); - NET_UNLOCK(); + NET_UNLOCK(); + } break; } diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index 4b32be9ad24..9e572af1ec4 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_usrreq.c,v 1.34 2017/11/03 12:49:42 florian Exp $ */ +/* $OpenBSD: raw_usrreq.c,v 1.35 2018/04/24 15:40:55 pirofti Exp $ */ /* $NetBSD: raw_usrreq.c,v 1.11 1996/02/13 22:00:43 christos Exp $ */ /* @@ -54,10 +54,11 @@ raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, int error = 0; int len; - soassertlocked(so); - if (req == PRU_CONTROL) return (EOPNOTSUPP); + + soassertlocked(so); + if (control && control->m_len) { m_freem(m); return (EOPNOTSUPP); diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 60b02a4656c..fbf73d6880f 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in.c,v 1.147 2018/03/02 15:52:11 claudio Exp $ */ +/* $OpenBSD: in.c,v 1.148 2018/04/24 15:40:55 pirofti Exp $ */ /* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */ /* @@ -185,7 +185,9 @@ int in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) { int privileged; + int error; + NET_LOCK(); privileged = 0; if ((so->so_state & SS_PRIV) != 0) privileged++; @@ -194,11 +196,16 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) switch (cmd) { case SIOCGETVIFCNT: case SIOCGETSGCNT: - return (mrt_ioctl(so, cmd, data)); + error = mrt_ioctl(so, cmd, data); + goto out; } #endif /* MROUTING */ - return (in_ioctl(cmd, data, ifp, privileged)); + error = in_ioctl(cmd, data, ifp, privileged); + +out: + NET_UNLOCK(); + return error; } int diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 1e1c2e200af..78d7f16e3f6 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.56 2017/11/02 14:01:18 florian Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.57 2018/04/24 15:40:55 pirofti Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -242,12 +242,13 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp = sotoinpcb(so); int error = 0; - soassertlocked(so); - if (req == PRU_CONTROL) { return (in_control(so, (u_long)m, (caddr_t)addr, (struct ifnet *)control)); } + + soassertlocked(so); + if (inp == NULL) { error = EINVAL; goto release; diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 79f2a0ca94a..0bdbd5eb9ab 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.108 2017/12/04 13:40:34 bluhm Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.109 2018/04/24 15:40:55 pirofti Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -368,12 +368,12 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct inpcb *inp = sotoinpcb(so); int error = 0; - soassertlocked(so); - if (req == PRU_CONTROL) return (in_control(so, (u_long)m, (caddr_t)nam, (struct ifnet *)control)); + soassertlocked(so); + if (inp == NULL) { error = EINVAL; goto release; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index cd7f7e398dd..6b1e036b574 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.167 2018/02/05 14:53:26 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.168 2018/04/24 15:40:55 pirofti Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -131,8 +131,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, int error = 0; short ostate; - soassertlocked(so); - if (req == PRU_CONTROL) { #ifdef INET6 if (sotopf(so) == PF_INET6) @@ -143,6 +141,9 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, return (in_control(so, (u_long)m, (caddr_t)nam, (struct ifnet *)control)); } + + soassertlocked(so); + if (control && control->m_len) { m_freem(control); m_freem(m); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 001a41a0810..4c113c025a8 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.246 2018/04/06 10:59:11 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.247 2018/04/24 15:40:55 pirofti Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1057,8 +1057,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp; int error = 0; - soassertlocked(so); - if (req == PRU_CONTROL) { #ifdef INET6 if (sotopf(so) == PF_INET6) @@ -1070,6 +1068,8 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, (struct ifnet *)control)); } + soassertlocked(so); + inp = sotoinpcb(so); if (inp == NULL) { error = EINVAL; diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 338adcbc50a..a89c306d713 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.220 2018/04/24 10:46:25 florian Exp $ */ +/* $OpenBSD: in6.c,v 1.221 2018/04/24 15:40:55 pirofti Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -181,7 +181,9 @@ int in6_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) { int privileged; + int error; + NET_LOCK(); privileged = 0; if ((so->so_state & SS_PRIV) != 0) privileged++; @@ -190,11 +192,16 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) switch (cmd) { case SIOCGETSGCNT_IN6: case SIOCGETMIFCNT_IN6: - return (mrt6_ioctl(so, cmd, data)); + error = mrt6_ioctl(so, cmd, data); + goto out; } #endif /* MROUTING */ - return (in6_ioctl(cmd, data, ifp, privileged)); + error = in6_ioctl(cmd, data, ifp, privileged); + +out: + NET_UNLOCK(); + return error; } int diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index e41e734733c..be67d64d1a5 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.55 2017/11/02 14:01:18 florian Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.56 2018/04/24 15:40:55 pirofti Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -245,12 +245,13 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, struct inpcb *inp = sotoinpcb(so); int error = 0; - soassertlocked(so); - if (req == PRU_CONTROL) { return (in6_control(so, (u_long)m, (caddr_t)addr, (struct ifnet *)control)); } + + soassertlocked(so); + if (inp == NULL) { error = EINVAL; goto release; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 464e44090d9..d75031fd090 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.126 2018/02/01 21:11:33 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.127 2018/04/24 15:40:55 pirofti Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -547,12 +547,12 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct inpcb *in6p = sotoinpcb(so); int error = 0; - soassertlocked(so); - if (req == PRU_CONTROL) return (in6_control(so, (u_long)m, (caddr_t)nam, (struct ifnet *)control)); + soassertlocked(so); + switch (req) { case PRU_DISCONNECT: if ((so->so_state & SS_ISCONNECTED) == 0) { -- cgit v1.2.3