From f0a6a678cb989f769e4f4f073cf2d1a03c83df90 Mon Sep 17 00:00:00 2001 From: mvs Date: Wed, 31 Aug 2022 21:23:02 +0000 Subject: [PATCH] Move PRU_SENDOOB request to (*pru_sendoob)(). PRU_SENDOOB request always consumes passed `top' and `control' mbufs. To avoid dummy m_freem(9) handlers for all protocols release passed mbufs in the pru_sendoob() EOPNOTSUPP error path. Also fix `control' mbuf(9) leak in the tcp(4) PRU_SENDOOB error path. ok bluhm@ --- sys/kern/uipc_usrreq.c | 6 +-- sys/net/pfkeyv2.c | 5 +-- sys/net/rtsock.c | 5 +-- sys/netinet/ip_divert.c | 3 +- sys/netinet/raw_ip.c | 9 +---- sys/netinet/tcp_usrreq.c | 78 ++++++++++++++++++++++++++++----------- sys/netinet/tcp_var.h | 4 +- sys/netinet/udp_usrreq.c | 3 +- sys/netinet6/ip6_divert.c | 3 +- sys/netinet6/raw_ip6.c | 9 +---- sys/sys/protosw.h | 13 +++++-- 11 files changed, 77 insertions(+), 61 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 193d6c55ff5..3df75016711 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.180 2022/08/30 16:24:16 miod Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.181 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -247,10 +247,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, } break; - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: uipc_setaddr(unp, nam); break; diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index 0ec4e3c1fba..b1e71cc6c29 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.247 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.248 2022/08/31 21:23:02 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -426,9 +426,6 @@ pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, nam->m_len = pfkey_addr.sa_len; break; - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; default: panic("pfkeyv2_usrreq"); } diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index f4cfdeb52df..a5262ec08f8 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.348 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.349 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -251,9 +251,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, nam->m_len = route_src.sa_len; break; - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; default: panic("route_usrreq"); } diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 275f656f410..6d83c594e08 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.81 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.82 2022/08/31 21:23:02 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -280,7 +280,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, break; case PRU_CONNECT2: - case PRU_SENDOOB: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index ca617d96f52..4bc2d11ae17 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.142 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.143 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -482,13 +482,6 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, error = EOPNOTSUPP; break; - /* - * Not supported. - */ - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: in_setsockaddr(inp, nam); break; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 539c08653a1..2cede08b16d 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.201 2022/08/30 11:53:04 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.202 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -126,6 +126,7 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_abort = tcp_abort, .pru_sense = tcp_sense, .pru_rcvoob = tcp_rcvoob, + .pru_sendoob = tcp_sendoob, }; static int pr_slowhz = PR_SLOWHZ; @@ -229,27 +230,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, error = EOPNOTSUPP; break; - case PRU_SENDOOB: - if (sbspace(so, &so->so_snd) < -512) { - m_freem(m); - error = ENOBUFS; - break; - } - /* - * According to RFC961 (Assigned Protocols), - * the urgent pointer points to the last octet - * of urgent data. We continue, however, - * to consider it to indicate the first octet - * of data past the urgent section. - * Otherwise, snd_up should be one lower. - */ - sbappendstream(so, &so->so_snd, m); - tp->snd_up = tp->snd_una + so->so_snd.sb_cc; - tp->t_force = 1; - error = tcp_output(tp); - tp->t_force = 0; - break; - case PRU_SOCKADDR: #ifdef INET6 if (inp->inp_flags & INP_IPV6) @@ -1021,6 +1001,60 @@ out: return (error); } +int +tcp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *nam, + struct mbuf *control) +{ + struct inpcb *inp; + struct tcpcb *tp; + int error; + short ostate; + + soassertlocked(so); + + if (control && control->m_len) { + error = EINVAL; + goto release; + } + + if ((error = tcp_sogetpcb(so, &inp, &tp))) + goto release; + + if (so->so_options & SO_DEBUG) + ostate = tp->t_state; + + if (sbspace(so, &so->so_snd) < -512) { + error = ENOBUFS; + goto out; + } + + /* + * According to RFC961 (Assigned Protocols), + * the urgent pointer points to the last octet + * of urgent data. We continue, however, + * to consider it to indicate the first octet + * of data past the urgent section. + * Otherwise, snd_up should be one lower. + */ + sbappendstream(so, &so->so_snd, m); + m = NULL; + tp->snd_up = tp->snd_una + so->so_snd.sb_cc; + tp->t_force = 1; + error = tcp_output(tp); + tp->t_force = 0; + +out: + if (so->so_options & SO_DEBUG) + tcp_trace(TA_USER, ostate, tp, tp, NULL, PRU_SENDOOB, 0); + +release: + m_freem(control); + m_freem(m); + + return (error); +} + + /* * 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 56b978553ed..4d10f7900b6 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.152 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.153 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -727,6 +727,8 @@ int tcp_send(struct socket *, struct mbuf *, struct mbuf *, int tcp_abort(struct socket *); int tcp_sense(struct socket *, struct stat *); int tcp_rcvoob(struct socket *, struct mbuf *, int); +int tcp_sendoob(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); 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); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 938df27724c..86d05c8f541 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.296 2022/08/30 11:53:04 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.297 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1111,7 +1111,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, in_setpeeraddr(inp, addr); break; - case PRU_SENDOOB: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 847e3c35d0c..461250d057a 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.80 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.81 2022/08/31 21:23:02 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -286,7 +286,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, break; case PRU_CONNECT2: - case PRU_SENDOOB: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index bd50d72cf2a..fc685070dde 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.163 2022/08/30 11:53:04 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.164 2022/08/31 21:23:02 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -597,13 +597,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, error = EOPNOTSUPP; break; - /* - * Not supported. - */ - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: in6_setsockaddr(in6p, nam); break; diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 490d155a074..ecd56e90290 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.49 2022/08/29 08:08:17 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.50 2022/08/31 21:23:02 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -79,6 +79,8 @@ struct pr_usrreqs { int (*pru_abort)(struct socket *); int (*pru_sense)(struct socket *, struct stat *); int (*pru_rcvoob)(struct socket *, struct mbuf *, int); + int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); }; struct protosw { @@ -242,6 +244,7 @@ char *prcorequests[] = { #ifdef _KERNEL +#include #include #include @@ -367,8 +370,12 @@ static inline int pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr, struct mbuf *control) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_SENDOOB, top, addr, control, curproc); + if (so->so_proto->pr_usrreqs->pru_sendoob) + return (*so->so_proto->pr_usrreqs->pru_sendoob)(so, + top, addr, control); + m_freem(top); + m_freem(control); + return (EOPNOTSUPP); } static inline int -- 2.20.1