Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.83.2.9 retrieving revision 1.116 diff -u -p -r1.83.2.9 -r1.116 --- src/sys/kern/uipc_socket.c 2005/04/01 14:30:57 1.83.2.9 +++ src/sys/kern/uipc_socket.c 2006/03/01 12:38:21 1.116 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.83.2.9 2005/04/01 14:30:57 skrll Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.116 2006/03/01 12:38:21 yamt Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.83.2.9 2005/04/01 14:30:57 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.116 2006/03/01 12:38:21 yamt Exp $"); #include "opt_sock_counters.h" #include "opt_sosend_loan.h" @@ -105,13 +105,13 @@ int somaxconn = SOMAXCONN; #ifdef SOSEND_COUNTERS #include -struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, +static struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "sosend", "loan big"); -struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, +static struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "sosend", "copy big"); -struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, +static struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "sosend", "copy small"); -struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, +static struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "sosend", "kva limit"); #define SOSEND_COUNTER_INCR(ev) (ev)->ev_count++ @@ -132,7 +132,7 @@ soinit(void) /* Set the initial adjusted socket buffer size. */ if (sb_max_set(sb_max)) - panic("bad initial sb_max value: %lu\n", sb_max); + panic("bad initial sb_max value: %lu", sb_max); } @@ -142,25 +142,23 @@ int use_sosend_loan = 0; int use_sosend_loan = 1; #endif -struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; -struct mbuf *so_pendfree; +static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; +static struct mbuf *so_pendfree; #ifndef SOMAXKVA #define SOMAXKVA (16 * 1024 * 1024) #endif int somaxkva = SOMAXKVA; -int socurkva; -int sokvawaiters; +static int socurkva; +static int sokvawaiters; #define SOCK_LOAN_THRESH 4096 #define SOCK_LOAN_CHUNK 65536 static size_t sodopendfree(struct socket *); static size_t sodopendfreel(struct socket *); -static __inline vsize_t sokvareserve(struct socket *, vsize_t); -static __inline void sokvaunreserve(vsize_t); -static __inline vsize_t +static vsize_t sokvareserve(struct socket *so, vsize_t len) { int s; @@ -200,7 +198,7 @@ sokvareserve(struct socket *so, vsize_t return len; } -static __inline void +static void sokvaunreserve(vsize_t len) { int s; @@ -392,7 +390,7 @@ sosend_loan(struct socket *so, struct ui vaddr_t lva, va; int npgs, i, error; - if (uio->uio_segflg != UIO_USERSPACE) + if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace)) return (0); if (iov->iov_len < (size_t) space) @@ -407,13 +405,12 @@ sosend_loan(struct socket *so, struct ui /* XXX KDASSERT */ KASSERT(npgs <= M_EXT_MAXPAGES); - KASSERT(uio->uio_lwp != NULL); lva = sokvaalloc(len, so); if (lva == 0) return 0; - error = uvm_loan(&uio->uio_lwp->l_proc->p_vmspace->vm_map, sva, len, + error = uvm_loan(&uio->uio_vmspace->vm_map, sva, len, m->m_ext.ext_pgs, UVM_LOAN_TOPAGE); if (error) { sokvafree(lva, len); @@ -455,10 +452,9 @@ socreate(int dom, struct socket **aso, i { const struct protosw *prp; struct socket *so; - struct proc *p; + uid_t uid; int error, s; - p = l->l_proc; if (proto) prp = pffindproto(dom, proto, type); else @@ -481,10 +477,12 @@ socreate(int dom, struct socket **aso, i so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; so->so_mowner = &prp->pr_domain->dom_mowner; #endif - if (p != 0) - so->so_uid = p->p_ucred->cr_uid; - else - so->so_uid = UID_MAX; + if (l != NULL) { + uid = l->l_proc->p_ucred->cr_uid; + } else { + uid = 0; + } + so->so_uidinfo = uid_find(uid); error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, (struct mbuf *)(long)proto, (struct mbuf *)0, l); if (error) { @@ -547,10 +545,10 @@ sofree(struct socket *so) return; } if (so->so_rcv.sb_hiwat) - (void)chgsbsize(so->so_uid, &so->so_rcv.sb_hiwat, 0, + (void)chgsbsize(so->so_uidinfo, &so->so_rcv.sb_hiwat, 0, RLIM_INFINITY); if (so->so_snd.sb_hiwat) - (void)chgsbsize(so->so_uid, &so->so_snd.sb_hiwat, 0, + (void)chgsbsize(so->so_uidinfo, &so->so_snd.sb_hiwat, 0, RLIM_INFINITY); sbrelease(&so->so_snd, so); sorflush(so); @@ -935,7 +933,7 @@ int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp) { - struct lwp *l; + struct lwp *l = curlwp; struct mbuf *m, **mp; int flags, len, error, s, offset, moff, type, orig_resid; const struct protosw *pr; @@ -946,7 +944,6 @@ soreceive(struct socket *so, struct mbuf mp = mp0; type = 0; orig_resid = uio->uio_resid; - l = uio->uio_lwp; if (paddr) *paddr = 0; @@ -1409,6 +1406,11 @@ sosetopt(struct socket *so, int level, i error = EINVAL; goto bad; } + if (mtod(m, struct linger *)->l_linger < 0 || + mtod(m, struct linger *)->l_linger > (INT_MAX / hz)) { + error = EDOM; + goto bad; + } so->so_linger = mtod(m, struct linger *)->l_linger; /* fall thru... */