Author: kib
Date: Thu May 14 17:54:08 2020
New Revision: 361037
URL: https://svnweb.freebsd.org/changeset/base/361037

Log:
  Fix spurious ENOTCONN from closed unix domain socket other' side.
  
  Sometimes, when doing read(2) over unix domain socket, for which the
  other side socket was closed, read(2) returns -1/ENOTCONN instead of
  EOF AKA zero-size read. This is because soreceive_generic() does not
  lock socket when testing the so_state SS_ISCONNECTED|SS_ISCONNECTING
  flags. It could end up that we do not observe so->so_rcv.sb_state bit
  SBS_CANTRCVMORE, and then miss SS_ flags.
  
  Change the test to check that the socket was never connected before
  returning ENOTCONN, by adding all state bits for connected.
  
  Reported and tested by:       pho
  In collaboration with:        markj
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week
  Differential revision:        https://reviews.freebsd.org/D24819

Modified:
  head/sys/kern/uipc_socket.c

Modified: head/sys/kern/uipc_socket.c
==============================================================================
--- head/sys/kern/uipc_socket.c Thu May 14 17:52:29 2020        (r361036)
+++ head/sys/kern/uipc_socket.c Thu May 14 17:54:08 2020        (r361037)
@@ -1969,8 +1969,9 @@ restart:
                                m = so->so_rcv.sb_mb;
                                goto dontblock;
                        }
-               if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) == 0 &&
-                   (so->so_proto->pr_flags & PR_CONNREQUIRED)) {
+               if ((so->so_state & (SS_ISCONNECTING | SS_ISCONNECTED |
+                   SS_ISDISCONNECTING | SS_ISDISCONNECTED)) == 0 &&
+                   (so->so_proto->pr_flags & PR_CONNREQUIRED) != 0) {
                        SOCKBUF_UNLOCK(&so->so_rcv);
                        error = ENOTCONN;
                        goto release;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to