From owner-freebsd-arch Wed Nov 7 11:44:57 2001 Delivered-To: freebsd-arch@freebsd.org Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by hub.freebsd.org (Postfix) with ESMTP id 6C15037B417 for ; Wed, 7 Nov 2001 11:44:04 -0800 (PST) Received: from fledge.watson.org (robert@fledge.pr.watson.org [192.0.2.3]) by fledge.watson.org (8.11.6/8.11.5) with SMTP id fA7JhuB45492 for ; Wed, 7 Nov 2001 14:43:56 -0500 (EST) (envelope-from robert@fledge.watson.org) Date: Wed, 7 Nov 2001 14:43:55 -0500 (EST) From: Robert Watson X-Sender: robert@fledge.watson.org To: freebsd-arch@FreeBSD.org Subject: Changing req->p to req->td in sysctl Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I'm in the process of pushing the (td) reference from ioctl() into if_ioctl() so that the thread information is available in a number of new places in the network stack. However, in order to pass it down, we now need it in a few newer places further up the stack (bpfattach(), ...). One of the places this touches is the sysctl() interface, where the process is passed in via req->p. The attached patch replaces the proc reference with a thread reference. Right now, it slightly increases complexity elsewhere (adds an additional dereference), but when we move to td->td_ucred, suser using the thread reference, and with the pushing of td down the stack, this will actually be a net improvement for simplicity. Please review, I'd like to commit in a day or two. Robert N M Watson FreeBSD Core Team, TrustedBSD Project robert@fledge.watson.org NAI Labs, Safeport Network Services ? sys/i386/conf/LINT Index: sys/compat/linux/linux_mib.c =================================================================== RCS file: /home/ncvs/src/sys/compat/linux/linux_mib.c,v retrieving revision 1.13 diff -u -r1.13 linux_mib.c --- sys/compat/linux/linux_mib.c 2001/09/08 19:07:03 1.13 +++ sys/compat/linux/linux_mib.c 2001/11/07 19:20:52 @@ -56,11 +56,11 @@ char osname[LINUX_MAX_UTSNAME]; int error; - strcpy(osname, linux_get_osname(req->p)); + strcpy(osname, linux_get_osname(req->td->td_proc)); error = sysctl_handle_string(oidp, osname, LINUX_MAX_UTSNAME, req); if (error || req->newptr == NULL) return (error); - error = linux_set_osname(req->p, osname); + error = linux_set_osname(req->td->td_proc, osname); return (error); } @@ -77,11 +77,11 @@ char osrelease[LINUX_MAX_UTSNAME]; int error; - strcpy(osrelease, linux_get_osrelease(req->p)); + strcpy(osrelease, linux_get_osrelease(req->td->td_proc)); error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req); if (error || req->newptr == NULL) return (error); - error = linux_set_osrelease(req->p, osrelease); + error = linux_set_osrelease(req->td->td_proc, osrelease); return (error); } @@ -98,11 +98,11 @@ int oss_version; int error; - oss_version = linux_get_oss_version(req->p); + oss_version = linux_get_oss_version(req->td->td_proc); error = sysctl_handle_int(oidp, &oss_version, 0, req); if (error || req->newptr == NULL) return (error); - error = linux_set_oss_version(req->p, oss_version); + error = linux_set_oss_version(req->td->td_proc, oss_version); return (error); } Index: sys/kern/kern_mib.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_mib.c,v retrieving revision 1.48 diff -u -r1.48 kern_mib.c --- sys/kern/kern_mib.c 2001/11/06 20:09:33 1.48 +++ sys/kern/kern_mib.c 2001/11/07 19:21:57 @@ -155,12 +155,12 @@ { int error; - if (jailed(req->p->p_ucred)) { + if (jailed(req->td->td_proc->p_ucred)) { if (!jail_set_hostname_allowed && req->newptr) return(EPERM); error = sysctl_handle_string(oidp, - req->p->p_ucred->cr_prison->pr_host, - sizeof req->p->p_ucred->cr_prison->pr_host, req); + req->td->td_proc->p_ucred->cr_prison->pr_host, + sizeof req->td->td_proc->p_ucred->cr_prison->pr_host, req); } else error = sysctl_handle_string(oidp, hostname, sizeof hostname, req); @@ -186,7 +186,7 @@ struct prison *pr; int error, level; - pr = req->p->p_ucred->cr_prison; + pr = req->td->td_proc->p_ucred->cr_prison; /* * If the process is in jail, return the maximum of the global and Index: sys/kern/kern_sysctl.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_sysctl.c,v retrieving revision 1.117 diff -u -r1.117 kern_sysctl.c --- sys/kern/kern_sysctl.c 2001/10/12 09:16:36 1.117 +++ sys/kern/kern_sysctl.c 2001/11/07 19:21:57 @@ -848,7 +848,7 @@ bzero(&req, sizeof req); - req.p = td->td_proc; + req.td = td; if (oldlenp) { req.oldlen = *oldlenp; @@ -1037,12 +1037,12 @@ /* Is this sysctl sensitive to securelevels? */ if (req->newptr && (oid->oid_kind & CTLFLAG_SECURE)) { - if (req->p == NULL) { + if (req->td == NULL) { error = securelevel_gt(NULL, 0); /* XXX */ if (error) return (error); } else { - error = securelevel_gt(req->p->p_ucred, 0); + error = securelevel_gt(req->td->td_proc->p_ucred, 0); if (error) return (error); } @@ -1050,14 +1050,14 @@ /* Is this sysctl writable by only privileged users? */ if (req->newptr && !(oid->oid_kind & CTLFLAG_ANYBODY)) { - if (req->p != NULL) { + if (req->td != NULL) { int flags; if (oid->oid_kind & CTLFLAG_PRISON) flags = PRISON_ROOT; else flags = 0; - error = suser_xxx(NULL, req->p, flags); + error = suser_xxx(NULL, req->td->td_proc, flags); if (error) return (error); } @@ -1132,7 +1132,7 @@ bzero(&req, sizeof req); - req.p = td->td_proc; + req.td = td; if (oldlenp) { if (inkernel) { Index: sys/kern/uipc_usrreq.c =================================================================== RCS file: /home/ncvs/src/sys/kern/uipc_usrreq.c,v retrieving revision 1.75 diff -u -r1.75 uipc_usrreq.c --- sys/kern/uipc_usrreq.c 2001/10/29 20:04:03 1.75 +++ sys/kern/uipc_usrreq.c 2001/11/07 19:22:35 @@ -850,7 +850,7 @@ for (unp = LIST_FIRST(head), i = 0; unp && i < n; unp = LIST_NEXT(unp, unp_link)) { if (unp->unp_gencnt <= gencnt) { - if (cr_cansee(req->p->p_ucred, + if (cr_cansee(req->td->td_proc->p_ucred, unp->unp_socket->so_cred)) continue; unp_list[i++] = unp; Index: sys/netinet/ip_divert.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/ip_divert.c,v retrieving revision 1.52 diff -u -r1.52 ip_divert.c --- sys/netinet/ip_divert.c 2001/09/12 08:37:54 1.52 +++ sys/netinet/ip_divert.c 2001/11/07 19:23:14 @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -485,7 +486,8 @@ s = splnet(); for (inp = LIST_FIRST(divcbinfo.listhead), i = 0; inp && i < n; inp = LIST_NEXT(inp, inp_list)) { - if (inp->inp_gencnt <= gencnt && !prison_xinpcb(req->p, inp)) + if (inp->inp_gencnt <= gencnt && !prison_xinpcb( + req->td->td_proc, inp)) inp_list[i++] = inp; } splx(s); Index: sys/netinet/raw_ip.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/raw_ip.c,v retrieving revision 1.86 diff -u -r1.86 raw_ip.c --- sys/netinet/raw_ip.c 2001/11/04 22:56:25 1.86 +++ sys/netinet/raw_ip.c 2001/11/07 19:23:14 @@ -627,7 +627,7 @@ for (inp = LIST_FIRST(ripcbinfo.listhead), i = 0; inp && i < n; inp = LIST_NEXT(inp, inp_list)) { if (inp->inp_gencnt <= gencnt) { - if (cr_cansee(req->p->p_ucred, + if (cr_cansee(req->td->td_proc->p_ucred, inp->inp_socket->so_cred)) continue; inp_list[i++] = inp; Index: sys/netinet/tcp_subr.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.116 diff -u -r1.116 tcp_subr.c --- sys/netinet/tcp_subr.c 2001/10/09 21:40:30 1.116 +++ sys/netinet/tcp_subr.c 2001/11/07 19:23:14 @@ -855,7 +855,7 @@ for (inp = LIST_FIRST(tcbinfo.listhead), i = 0; inp && i < n; inp = LIST_NEXT(inp, inp_list)) { if (inp->inp_gencnt <= gencnt) { - if (cr_cansee(req->p->p_ucred, + if (cr_cansee(req->td->td_proc->p_ucred, inp->inp_socket->so_cred)) continue; inp_list[i++] = inp; @@ -913,7 +913,7 @@ struct inpcb *inp; int error, s; - error = suser_xxx(0, req->p, PRISON_ROOT); + error = suser_xxx(0, req->td->td_proc, PRISON_ROOT); if (error) return (error); error = SYSCTL_IN(req, addrs, sizeof(addrs)); @@ -926,7 +926,7 @@ error = ENOENT; goto out; } - error = cr_cansee(req->p->p_ucred, inp->inp_socket->so_cred); + error = cr_cansee(req->td->td_proc->p_ucred, inp->inp_socket->so_cred); if (error) goto out; bzero(&xuc, sizeof(xuc)); @@ -953,7 +953,7 @@ struct inpcb *inp; int error, s, mapped = 0; - error = suser_xxx(0, req->p, PRISON_ROOT); + error = suser_xxx(0, req->td->td_proc, PRISON_ROOT); if (error) return (error); error = SYSCTL_IN(req, addrs, sizeof(addrs)); @@ -982,7 +982,7 @@ error = ENOENT; goto out; } - error = cr_cansee(req->p->p_ucred, inp->inp_socket->so_cred); + error = cr_cansee(req->td->td_proc->p_ucred, inp->inp_socket->so_cred); if (error) goto out; bzero(&xuc, sizeof(xuc)); Index: sys/netinet/udp_usrreq.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.99 diff -u -r1.99 udp_usrreq.c --- sys/netinet/udp_usrreq.c 2001/10/22 12:43:30 1.99 +++ sys/netinet/udp_usrreq.c 2001/11/07 19:23:14 @@ -583,7 +583,7 @@ for (inp = LIST_FIRST(udbinfo.listhead), i = 0; inp && i < n; inp = LIST_NEXT(inp, inp_list)) { if (inp->inp_gencnt <= gencnt) { - if (cr_cansee(req->p->p_ucred, + if (cr_cansee(req->td->td_proc->p_ucred, inp->inp_socket->so_cred)) continue; inp_list[i++] = inp; @@ -635,7 +635,7 @@ struct inpcb *inp; int error, s; - error = suser_xxx(0, req->p, PRISON_ROOT); + error = suser_xxx(0, req->td->td_proc, PRISON_ROOT); if (error) return (error); error = SYSCTL_IN(req, addrs, sizeof(addrs)); @@ -648,7 +648,7 @@ error = ENOENT; goto out; } - error = cr_cansee(req->p->p_ucred, inp->inp_socket->so_cred); + error = cr_cansee(req->td->td_proc->p_ucred, inp->inp_socket->so_cred); if (error) goto out; bzero(&xuc, sizeof(xuc)); Index: sys/netinet6/udp6_usrreq.c =================================================================== RCS file: /home/ncvs/src/sys/netinet6/udp6_usrreq.c,v retrieving revision 1.18 diff -u -r1.18 udp6_usrreq.c --- sys/netinet6/udp6_usrreq.c 2001/09/25 18:40:52 1.18 +++ sys/netinet6/udp6_usrreq.c 2001/11/07 19:23:21 @@ -464,7 +464,7 @@ struct inpcb *inp; int error, s; - error = suser(req->p); + error = suser(req->td->td_proc); if (error) return (error); Index: sys/sys/sysctl.h =================================================================== RCS file: /home/ncvs/src/sys/sys/sysctl.h,v retrieving revision 1.99 diff -u -r1.99 sysctl.h --- sys/sys/sysctl.h 2001/09/12 08:38:05 1.99 +++ sys/sys/sysctl.h 2001/11/07 19:23:25 @@ -111,7 +111,7 @@ * so that we can use the interface from the kernel or from user-space. */ struct sysctl_req { - struct proc *p; /* used for access checking */ + struct thread *td; /* used for access checking */ int lock; void *oldptr; size_t oldlen; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message