From owner-p4-projects@FreeBSD.ORG Sat Jul 8 19:22:55 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2622616A4E1; Sat, 8 Jul 2006 19:22:55 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0270716A4E0 for ; Sat, 8 Jul 2006 19:22:55 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0A32D43D69 for ; Sat, 8 Jul 2006 19:22:49 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k68JMnlY068472 for ; Sat, 8 Jul 2006 19:22:49 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k68JMndv068460 for perforce@freebsd.org; Sat, 8 Jul 2006 19:22:49 GMT (envelope-from jhb@freebsd.org) Date: Sat, 8 Jul 2006 19:22:49 GMT Message-Id: <200607081922.k68JMndv068460@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 101046 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jul 2006 19:22:55 -0000 http://perforce.freebsd.org/chv.cgi?CH=101046 Change 101046 by jhb@jhb_mutex on 2006/07/08 19:21:50 - Even though it's trivial, add a kern_close() and use it in various places instead of a struct close_args + close(). - Note a case in the svr4 streams gunk where we can leak the accept fd. - Add a kern_close() to accept() to close the fd if the copyout's fault. Affected files ... .. //depot/projects/smpng/sys/compat/linux/linux_socket.c#31 edit .. //depot/projects/smpng/sys/compat/svr4/svr4_stream.c#34 edit .. //depot/projects/smpng/sys/fs/portalfs/portal_vnops.c#23 edit .. //depot/projects/smpng/sys/i386/ibcs2/ibcs2_other.c#9 edit .. //depot/projects/smpng/sys/kern/kern_descrip.c#93 edit .. //depot/projects/smpng/sys/kern/uipc_syscalls.c#86 edit .. //depot/projects/smpng/sys/sys/syscallsubr.h#45 edit Differences ... ==== //depot/projects/smpng/sys/compat/linux/linux_socket.c#31 (text+ko) ==== @@ -705,9 +705,6 @@ struct sockaddr * __restrict name; socklen_t * __restrict anamelen; } */ bsd_args; - struct close_args /* { - int fd; - } */ c_args; int error, fd; if ((error = copyin(args, &linux_args, sizeof(linux_args)))) @@ -724,8 +721,7 @@ if (linux_args.addr) { error = linux_sa_put(PTRIN(linux_args.addr)); if (error) { - c_args.fd = td->td_retval[0]; - (void)close(td, &c_args); + (void)kern_close(td, td->td_retval[0]); return (error); } } ==== //depot/projects/smpng/sys/compat/svr4/svr4_stream.c#34 (text+ko) ==== @@ -1035,7 +1035,6 @@ struct svr4_strm *st = svr4_stream_get(fp); struct svr4_strfdinsert fdi; struct dup2_args d2p; - struct close_args clp; if (st == NULL) { DPRINTF(("fdinsert: bad file type\n")); @@ -1061,9 +1060,7 @@ return error; } - clp.fd = st->s_afd; - - if ((error = close(td, &clp)) != 0) { + if ((error = kern_close(td, st->s_afd)) != 0) { DPRINTF(("fdinsert: close(%d) failed %d\n", st->s_afd, error)); return error; @@ -1919,6 +1916,7 @@ return EINVAL; } + /* XXX: We leak the accept fd if we get an error here. */ if (uap->ctl) { if (ctl.len > sizeof(sc)) ctl.len = sizeof(sc); ==== //depot/projects/smpng/sys/fs/portalfs/portal_vnops.c#23 (text+ko) ==== @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -77,10 +78,8 @@ int fd; { int error; - struct close_args ua; - ua.fd = fd; - error = close(td, &ua); + error = kern_close(td, fd); /* * We should never get an error, and there isn't anything * we could do if we got one, so just print a message. ==== //depot/projects/smpng/sys/i386/ibcs2/ibcs2_other.c#9 (text+ko) ==== @@ -109,9 +109,7 @@ error = kern_connect(td, fd, (struct sockaddr *)&sun); if (error) { - struct close_args cl; - cl.fd = fd; - close(td, &cl); + kern_close(td, fd); return error; } td->td_retval[0] = fd; ==== //depot/projects/smpng/sys/kern/kern_descrip.c#93 (text+ko) ==== @@ -973,12 +973,20 @@ struct thread *td; struct close_args *uap; { + + return (kern_close(td, uap->fd)); +} + +int +kern_close(td, fd) + struct thread *td; + int fd; +{ struct filedesc *fdp; struct file *fp; - int fd, error; + int error; int holdleaders; - fd = uap->fd; error = 0; holdleaders = 0; fdp = td->td_proc->p_fd; ==== //depot/projects/smpng/sys/kern/uipc_syscalls.c#86 (text+ko) ==== @@ -313,11 +313,12 @@ * return a namelen of zero for older code which might * ignore the return value from accept. */ - if (error && name == NULL) { + if (error) { (void) copyout(&namelen, uap->anamelen, sizeof(*uap->anamelen)); return (error); } + if (error == 0 && name != NULL) { #ifdef COMPAT_OLDSOCK if (compat) @@ -329,6 +330,8 @@ if (error == 0) error = copyout(&namelen, uap->anamelen, sizeof(namelen)); + if (error) + kern_close(td, td->td_retval[0]); free(name, M_SONAME); return (error); } ==== //depot/projects/smpng/sys/sys/syscallsubr.h#45 (text+ko) ==== @@ -70,6 +70,7 @@ struct timespec *ats); int kern_clock_settime(struct thread *td, clockid_t clock_id, struct timespec *ats); +int kern_close(struct thread *td, int fd); int kern_connect(struct thread *td, int fd, struct sockaddr *sa); int kern_eaccess(struct thread *td, char *path, enum uio_seg pathseg, int flags);