[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: library/1427: close(2) with -pthread fails closing sockets



The following reply was made to PR library/1427; it has been noted by GNATS.

From: David Leonard <david.leonard@csee.uq.edu.au>
To: yval@hackers.co.il
Cc: GNATS Management <gnats@cvs.openbsd.org>
Subject: Re: library/1427: close(2) with -pthread fails closing sockets
Date: Mon, 2 Oct 2000 10:14:36 +1000 (EST)

 the threaded close() code assumes that fstat will work on any valid
 file descriptor, but when sockets are disconnected, a lack of pcb means
 that fstat returns EINVAL. the next 2 patches have been tested - they 
 allow fstat to do something reasonably sensible for udp and tcp sockets.
 the 3rd is a patch for unix sockets, which I'm not sure if it will break
 anything, or is in fact ever needed. the rest of the diffs are for the other
 protocols that i could find that gave errors for PRU_SENSE when a zeroed
 stat buffer would be okay.
 
 now that I think about it, rather than returning 0 with poor stat information,
 it might be wiser to return EOPNOTSUPP and have the thread close code
 deal with that. EINVAL is certainly wrong though.
 
 comments?
 
 Index: netinet/tcp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netinet/tcp_usrreq.c,v
 retrieving revision 1.47
 diff -u -r1.47 tcp_usrreq.c
 --- netinet/tcp_usrreq.c	2000/09/19 03:20:59	1.47
 +++ netinet/tcp_usrreq.c	2000/10/01 23:38:06
 @@ -148,7 +148,7 @@
  	 * a (struct inpcb) pointed at by the socket, and this
  	 * structure will point at a subsidary (struct tcpcb).
  	 */
 -	if (inp == 0 && req != PRU_ATTACH) {
 +	if (inp == 0 && req != PRU_ATTACH && req != PRU_SENSE) {
  		splx(s);
  		/*
  		 * The following corrects an mbuf leak under rare
 Index: netinet/udp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netinet/udp_usrreq.c,v
 retrieving revision 1.49
 diff -u -r1.49 udp_usrreq.c
 --- netinet/udp_usrreq.c	2000/09/22 17:51:46	1.49
 +++ netinet/udp_usrreq.c	2000/10/01 23:38:07
 @@ -1059,7 +1059,7 @@
  			return (in_control(so, (u_long)m, (caddr_t)addr,
  			    (struct ifnet *)control));
  	}
 -	if (inp == NULL && req != PRU_ATTACH) {
 +	if (inp == NULL && req != PRU_ATTACH && req != PRU_SENSE) {
  		error = EINVAL;
  		goto release;
  	}
 
 Index: kern/uipc_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/kern/uipc_usrreq.c,v
 retrieving revision 1.11
 diff -u -r1.11 uipc_usrreq.c
 --- kern/uipc_usrreq.c	1999/10/11 19:49:39	1.11
 +++ kern/uipc_usrreq.c	2000/10/01 23:38:08
 @@ -81,7 +81,7 @@
  		error = EOPNOTSUPP;
  		goto release;
  	}
 -	if (unp == 0 && req != PRU_ATTACH) {
 +	if (unp == 0 && req != PRU_ATTACH && req != PRU_SENSE) {
  		error = EINVAL;
  		goto release;
  	}
 @@ -252,6 +252,8 @@
  
  	case PRU_SENSE:
  		((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
 +		if (unp == 0)
 +			return (0);
  		if (so->so_type == SOCK_STREAM && unp->unp_conn != 0) {
  			so2 = unp->unp_conn->unp_socket;
  			((struct stat *) m)->st_blksize += so2->so_rcv.sb_cc;
 
 
 Index: netatalk/ddp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netatalk/ddp_usrreq.c,v
 retrieving revision 1.2
 diff -u -r1.2 ddp_usrreq.c
 --- netatalk/ddp_usrreq.c	1997/07/24 00:25:23	1.2
 +++ netatalk/ddp_usrreq.c	2000/10/01 23:38:06
 @@ -114,7 +114,7 @@
  	goto release;
      }
  
 -    if ( ddp == NULL && req != PRU_ATTACH ) {
 +    if ( ddp == NULL && req != PRU_ATTACH && req != PRU_SENSE ) {
  	error = EINVAL;
  	goto release;
      }
 Index: netccitt/pk_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netccitt/pk_usrreq.c,v
 retrieving revision 1.2
 diff -u -r1.2 pk_usrreq.c
 --- netccitt/pk_usrreq.c	1996/03/04 07:36:47	1.2
 +++ netccitt/pk_usrreq.c	2000/10/01 23:38:06
 @@ -92,7 +92,7 @@
  		error = EINVAL;
  		goto release;
  	}
 -	if (lcp == NULL && req != PRU_ATTACH) {
 +	if (lcp == NULL && req != PRU_ATTACH && req != PRU_SENSE) {
  		error = EINVAL;
  		goto release;
  	}
 @@ -238,11 +238,7 @@
  		break;
  
  	case PRU_SENSE:
 -#ifdef BSD4_3
  		((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
 -#else
 -		error = EOPNOTSUPP;
 -#endif
  		break;
  
  		/* End unimplemented hooks. */
 Index: netipx/ipx_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netipx/ipx_usrreq.c,v
 retrieving revision 1.8
 diff -u -r1.8 ipx_usrreq.c
 --- netipx/ipx_usrreq.c	2000/01/17 00:34:00	1.8
 +++ netipx/ipx_usrreq.c	2000/10/01 23:38:07
 @@ -407,7 +407,7 @@
  		error = EINVAL;
  		goto release;
  	}
 -	if (ipxp == NULL && req != PRU_ATTACH) {
 +	if (ipxp == NULL && req != PRU_ATTACH && req != PRU_SENSE) {
  		error = EINVAL;
  		goto release;
  	}
 Index: netipx/spx_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netipx/spx_usrreq.c,v
 retrieving revision 1.12
 diff -u -r1.12 spx_usrreq.c
 --- netipx/spx_usrreq.c	2000/01/15 19:05:30	1.12
 +++ netipx/spx_usrreq.c	2000/10/01 23:38:07
 @@ -1276,7 +1276,7 @@
                  return (ipx_control(so, (int)m, (caddr_t)nam,
  			(struct ifnet *)controlp));
  	if (ipxp == NULL) {
 -		if (req != PRU_ATTACH) {
 +		if (req != PRU_ATTACH && req != PRU_SENSE) {
  			error = EINVAL;
  			goto release;
  		}
 @@ -1423,6 +1423,9 @@
  		break;
  
  	case PRU_SENSE:
 +		m = NULL;
 +		break;
 +
  	case PRU_CONTROL:
  		m = NULL;
  		error = EOPNOTSUPP;
 Index: netiso/cltp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netiso/cltp_usrreq.c,v
 retrieving revision 1.2
 diff -u -r1.2 cltp_usrreq.c
 --- netiso/cltp_usrreq.c	1996/03/04 10:35:06	1.2
 +++ netiso/cltp_usrreq.c	2000/10/01 23:38:08
 @@ -304,7 +304,7 @@
  	if (req == PRU_CONTROL)
  		return (iso_control(so, (long) m, (caddr_t) nam,
  				    (struct ifnet *) control));
 -	if ((isop == NULL && req != PRU_ATTACH) ||
 +	if ((isop == NULL && req != PRU_ATTACH && req != PRU_SENSE) ||
  	    (control && control->m_len)) {
  		error = EINVAL;
  		goto release;
 Index: netiso/tp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netiso/tp_usrreq.c,v
 retrieving revision 1.3
 diff -u -r1.3 tp_usrreq.c
 --- netiso/tp_usrreq.c	1996/04/21 22:30:04	1.3
 +++ netiso/tp_usrreq.c	2000/10/01 23:38:08
 @@ -416,7 +416,7 @@
  	}
  #endif
  
 -	if ((u_long) tpcb == 0 && req != PRU_ATTACH) {
 +	if ((u_long) tpcb == 0 && req != PRU_ATTACH && req != PRU_SENSE) {
  #ifdef TPPT
  		if (tp_traceflags[D_REQUEST]) {
  			tptraceTPCB(TPPTusrreq, "req failed NO TPCB[", 0, 0, 0, 0);
 @@ -727,11 +727,13 @@
  
  	case PRU_PROTOSEND:
  	case PRU_PROTORCV:
 -	case PRU_SENSE:
  	case PRU_SLOWTIMO:
  	case PRU_FASTTIMO:
  		error = EOPNOTSUPP;
  		break;
 +
 +	case PRU_SENSE:
 +		return (0);
  
  	default:
  #ifdef ARGO_DEBUG
 Index: netiso/tuba_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netiso/tuba_usrreq.c,v
 retrieving revision 1.3
 diff -u -r1.3 tuba_usrreq.c
 --- netiso/tuba_usrreq.c	1998/01/03 22:32:56	1.3
 +++ netiso/tuba_usrreq.c	2000/10/01 23:38:08
 @@ -106,7 +106,7 @@
  	 * a (struct inpcb) pointed at by the socket, and this
  	 * structure will point at a subsidary (struct tcpcb).
  	 */
 -	if (inp == 0 && req != PRU_ATTACH) {
 +	if (inp == 0 && req != PRU_ATTACH && req != PRU_SENSE) {
  		splx(s);
  		return (EINVAL);/* XXX */
  	}
 Index: netns/idp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netns/idp_usrreq.c,v
 retrieving revision 1.4
 diff -u -r1.4 idp_usrreq.c
 --- netns/idp_usrreq.c	1997/01/18 17:31:02	1.4
 +++ netns/idp_usrreq.c	2000/10/01 23:38:08
 @@ -422,7 +422,7 @@
  		error = EINVAL;
  		goto release;
  	}
 -	if (nsp == NULL && req != PRU_ATTACH) {
 +	if (nsp == NULL && req != PRU_ATTACH && req != PRU_SENSE) {
  		error = EINVAL;
  		goto release;
  	}
 Index: netns/spp_usrreq.c
 ===================================================================
 RCS file: /usr/openbsd/cvs/src/sys/netns/spp_usrreq.c,v
 retrieving revision 1.8
 diff -u -r1.8 spp_usrreq.c
 --- netns/spp_usrreq.c	1999/01/11 05:12:35	1.8
 +++ netns/spp_usrreq.c	2000/10/01 23:38:08
 @@ -1329,7 +1329,7 @@
                  return (ns_control(so, (long)m, (caddr_t)nam,
  			(struct ifnet *)controlp));
  	if (nsp == NULL) {
 -		if (req != PRU_ATTACH) {
 +		if (req != PRU_ATTACH && req != PRU_SENSE) {
  			error = EINVAL;
  			goto release;
  		}
 @@ -1496,6 +1496,9 @@
  		break;
  
  	case PRU_SENSE:
 +		m = NULL;
 +		break;
 +
  	case PRU_CONTROL:
  		m = NULL;
  		error = EOPNOTSUPP;
 -- 
 David Leonard                           David.Leonard@csee.uq.edu.au
 Dept of Comp. Sci. and Elec. Engg   _   Room:78-640  Ph:+61 7 336 51187
 The University of Queensland       |+|  http://www.csee.uq.edu.au/~leonard/
 QLD 4072  AUSTRALIA               ~` '~ B73CD65FBEF4C089B79A8EBADF1A932F13EA0FC8
 
 Curses! - Mojo Jojo