Really fix low port allocation, by always passing a valid lwp to

in_pcbbind().

Okay dyoung@.

Note that the network code is another candidate for major cleanup... also
note that this issue is likely to be present in netinet6 code, too.
This commit is contained in:
elad 2007-12-16 14:12:34 +00:00
parent 9fe6472fc5
commit 7beaf4911f
4 changed files with 16 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_pcb.c,v 1.119 2007/08/21 08:34:33 dyoung Exp $ */
/* $NetBSD: in_pcb.c,v 1.120 2007/12/16 14:12:34 elad Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -98,7 +98,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.119 2007/08/21 08:34:33 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.120 2007/12/16 14:12:34 elad Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -226,6 +226,7 @@ in_pcbbind(void *v, struct mbuf *nam, struct lwp *l)
struct sockaddr_in *sin = NULL; /* XXXGCC */
u_int16_t lport = 0;
int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
kauth_cred_t cred = l->l_cred;
if (inp->inp_af != AF_INET)
return (EINVAL);
@ -272,10 +273,10 @@ in_pcbbind(void *v, struct mbuf *nam, struct lwp *l)
#ifndef IPNOPRIVPORTS
/* GROSS */
if (ntohs(lport) < IPPORT_RESERVED &&
(l == 0 || kauth_authorize_network(l->l_cred,
kauth_authorize_network(cred,
KAUTH_NETWORK_BIND,
KAUTH_REQ_NETWORK_BIND_PRIVPORT, so, sin,
NULL)))
NULL))
return (EACCES);
#endif
#ifdef INET6
@ -316,7 +317,7 @@ noname:
if (inp->inp_flags & INP_LOWPORT) {
#ifndef IPNOPRIVPORTS
if (l == 0 || kauth_authorize_network(l->l_cred,
if (kauth_authorize_network(cred,
KAUTH_NETWORK_BIND,
KAUTH_REQ_NETWORK_BIND_PRIVPORT, so,
sin, NULL))

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_pcb.h,v 1.43 2007/09/19 04:33:43 dyoung Exp $ */
/* $NetBSD: in_pcb.h,v 1.44 2007/12/16 14:12:34 elad Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -63,6 +63,7 @@
#ifndef _NETINET_IN_PCB_H_
#define _NETINET_IN_PCB_H_
#include <sys/kauth.h>
#include <sys/queue.h>
#include <netinet/in_pcb_hdr.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_input.c,v 1.272 2007/11/09 23:55:58 dyoung Exp $ */
/* $NetBSD: tcp_input.c,v 1.273 2007/12/16 14:12:34 elad Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -152,7 +152,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.272 2007/11/09 23:55:58 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.273 2007/12/16 14:12:34 elad Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -174,6 +174,7 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.272 2007/11/09 23:55:58 dyoung Exp $
#ifdef TCP_SIGNATURE
#include <sys/md5.h>
#endif
#include <sys/lwp.h> /* for lwp0 */
#include <net/if.h>
#include <net/route.h>
@ -3723,7 +3724,7 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst,
am->m_len = src->sa_len;
bcopy(src, mtod(am, void *), src->sa_len);
if (inp) {
if (in_pcbconnect(inp, am, NULL)) {
if (in_pcbconnect(inp, am, &lwp0)) {
(void) m_free(am);
goto resetandabort;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_usrreq.c,v 1.139 2007/11/27 22:45:30 christos Exp $ */
/* $NetBSD: tcp_usrreq.c,v 1.140 2007/12/16 14:12:35 elad Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.139 2007/11/27 22:45:30 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.140 2007/12/16 14:12:35 elad Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -361,8 +361,7 @@ tcp_usrreq(struct socket *so, int req,
case PRU_LISTEN:
#ifdef INET
if (inp && inp->inp_lport == 0) {
error = in_pcbbind(inp, (struct mbuf *)0,
(struct lwp *)0);
error = in_pcbbind(inp, (struct mbuf *)0, l);
if (error)
break;
}
@ -389,8 +388,7 @@ tcp_usrreq(struct socket *so, int req,
#ifdef INET
if (inp) {
if (inp->inp_lport == 0) {
error = in_pcbbind(inp, (struct mbuf *)0,
(struct lwp *)0);
error = in_pcbbind(inp, (struct mbuf *)0, l);
if (error)
break;
}