| #
053a9884
|
| 23-Dec-2024 |
Gleb Smirnoff <glebius@FreeBSD.org> |
tcp: don't ever return ECONNRESET on close(2)
The SUS doesn't mention this error code as a possible one [1]. The FreeBSD manual page specifies a possible ECONNRESET for close(2):
[ECONNRESET] The u
tcp: don't ever return ECONNRESET on close(2)
The SUS doesn't mention this error code as a possible one [1]. The FreeBSD manual page specifies a possible ECONNRESET for close(2):
[ECONNRESET] The underlying object was a stream socket that was shut down by the peer before all pending data was delivered.
In the past it had been EINVAL (see 21367f630d72), and this EINVAL was added as a safety measure in 623dce13c64ef. After conversion to ECONNRESET it had been documented in the manual page in 78e3a7fdd51e6, but I bet wasn't ever tested to actually be ever returned, cause the tcp-testsuite[2] didn't exist back then. So documentation is incorrect since 2006, if my bet wins. Anyway, in the modern FreeBSD the condition described above doesn't end up with ECONNRESET error code from close(2). The error condition is reported via SO_ERROR socket option, though. This can be checked using the tcp-testsuite, temporarily disabling the getsockopt(SO_ERROR) lines using sed command [3]. Most of these getsockopt(2)s are followed by '+0.00 close(3) = 0', which will confirm that close(2) doesn't return ECONNRESET even on a socket that has the error stored, neither it is returned in the case described in the manual page. The latter case is covered by multiple tests residing in tcp- testsuite/state-event-engine/rcv-rst-*.
However, the deleted block of code could be entered in a race condition between close(2) and processing of incoming packet, when connection had already been half-closed with shutdown(SHUT_WR) and sits in TCPS_LAST_ACK. This was reported in the bug 146845. With the block deleted, we will continue into tcp_disconnect() which has proper handling of INP_DROPPED.
The race explanation follows. The connection is in TCPS_LAST_ACK. The network input thread acquires the tcpcb lock first, sets INP_DROPPED, acquires the socket lock in soisdisconnected() and clears SS_ISCONNECTED. Meanwhile, the syscall thread goes through sodisconnect() which checks for SS_ISCONNECTED locklessly(!). The check passes and the thread blocks on the tcpcb lock in tcp_usr_disconnect(). Once input thread releases the lock, the syscall thread observes INP_DROPPED and returns ECONNRESET.
- Thread 1: tcp_do_segment()->tcp_close()->in_pcbdrop(),soisdisconnected() - Thread 2: sys_close()...->soclose()->sodisconnect()->tcp_usr_disconnect()
Note that the lockless operation in sodisconnect() isn't correct, but enforcing the socket lock there will not fix the problem.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/ [2] https://github.com/freebsd-net/tcp-testsuite [3] sed -i "" -Ee '/\+0\.00 getsockopt\(3, SOL_SOCKET, SO_ERROR, \[ECONNRESET\]/d' $(grep -lr ECONNRESET tcp-testsuite)
PR: 146845 Reviewed by: tuexen, rrs, imp Differential Revision: https://reviews.freebsd.org/D48148
show more ...
|
| #
8269e767
|
| 14-Nov-2023 |
Brooks Davis <brooks@FreeBSD.org> |
libsys: relocate implementations and manpages
Remove core system call implementations and documentation to lib/libsys and lib/libsys/<arch> from lib/libc/sys and lib/libc/<arch>/<sys>. Update paths
libsys: relocate implementations and manpages
Remove core system call implementations and documentation to lib/libsys and lib/libsys/<arch> from lib/libc/sys and lib/libc/<arch>/<sys>. Update paths to allow libc to find them in their new home.
Reviewed by: kib, emaste, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/908
show more ...
|
| #
dc36d6f9
|
| 23-Nov-2023 |
Warner Losh <imp@FreeBSD.org> |
lib: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl s
lib: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script.
Sponsored by: Netflix
show more ...
|
| #
b2c76c41
|
| 16-Aug-2023 |
Warner Losh <imp@FreeBSD.org> |
Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
|
| #
aeb71118
|
| 01-Dec-2017 |
Warner Losh <imp@FreeBSD.org> |
Mark all the system calls that were in 1st Edition Unix as such in the HISTORY section. Note: Any system calls that were added prior to v7, but after v1 weren't changed.
Obtained from: http://www.tu
Mark all the system calls that were in 1st Edition Unix as such in the HISTORY section. Note: Any system calls that were added prior to v7, but after v1 weren't changed.
Obtained from: http://www.tuhs.org/cgi-bin/utree.pl?file=V1/man/man2
show more ...
|
| #
fbbd9655
|
| 28-Feb-2017 |
Warner Losh <imp@FreeBSD.org> |
Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is
Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point.
Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96
show more ...
|
| #
c36029e6
|
| 12-Sep-2013 |
Bryan Drewery <bdrewery@FreeBSD.org> |
Consistently reference file descriptors as "fd". 55 other manpages used "fd", while these used "d" and "filedes".
MFC after: 1 week Approved by: gjb Approved by: re (delphij)
|
| #
7ff82421
|
| 22-Jan-2012 |
Konstantin Belousov <kib@FreeBSD.org> |
Clarify the implementation-defined behaviour in case of close(2) returning error.
MFC after: 1 week
|
| #
c4f16b69
|
| 15-Jun-2009 |
John Baldwin <jhb@FreeBSD.org> |
Add a new 'void closefrom(int lowfd)' system call. When called, it closes any open file descriptors >= 'lowfd'. It is largely identical to the same function on other operating systems such as Solar
Add a new 'void closefrom(int lowfd)' system call. When called, it closes any open file descriptors >= 'lowfd'. It is largely identical to the same function on other operating systems such as Solaris, DFly, NetBSD, and OpenBSD. One difference from other *BSD is that this closefrom() does not fail with any errors. In practice, while the manpages for NetBSD and OpenBSD claim that they return EINTR, they ignore internal errors from close() and never return EINTR. DFly does return EINTR, but for the common use case (closing fd's prior to execve()), the caller really wants all fd's closed and returning EINTR just forces callers to call closefrom() in a loop until it stops failing.
Note that this implementation of closefrom(2) does not make any effort to resolve userland races with open(2) in other threads. As such, it is not multithread safe.
Submitted by: rwatson (initial version) Reviewed by: rwatson MFC after: 2 weeks
show more ...
|
| #
c879ae35
|
| 09-Jan-2007 |
Warner Losh <imp@FreeBSD.org> |
Per Regents of the University of Calfornia letter, remove advertising clause.
# If I've done so improperly on a file, please let me know.
|
| #
a82e937c
|
| 04-Dec-2006 |
Ruslan Ermilov <ru@FreeBSD.org> |
Grammar.
OK'ed by: sam
|
| #
78e3a7fd
|
| 04-Dec-2006 |
Sam Leffler <sam@FreeBSD.org> |
document recent change to return ECONNRESET for tcp sockets
MFC after: 1 month
|
| #
1a0a9345
|
| 02-Jul-2004 |
Ruslan Ermilov <ru@FreeBSD.org> |
Mechanically kill hard sentence breaks.
|
| #
720f2e44
|
| 13-Jun-2003 |
Tom Rhodes <trhodes@FreeBSD.org> |
Document ENOSPC.
PR: 52612 Submitted by: Marc Olzheim <marcolz@ilse.nl>
|
| #
2efeeba5
|
| 19-Dec-2002 |
Ruslan Ermilov <ru@FreeBSD.org> |
mdoc(7) police: "The .Fa argument.".
|
| #
2faeeff4
|
| 18-Dec-2002 |
Ruslan Ermilov <ru@FreeBSD.org> |
mdoc(7) police: Tidy up the syscall language.
Stop calling system calls "function calls".
Use "The .Fn system call" a-la "The .Nm utility".
When referring to a non-BSD implementation in the HISTOR
mdoc(7) police: Tidy up the syscall language.
Stop calling system calls "function calls".
Use "The .Fn system call" a-la "The .Nm utility".
When referring to a non-BSD implementation in the HISTORY section, call syscall a function, to be safe.
show more ...
|
| #
1f2cec10
|
| 15-Jul-2002 |
Giorgos Keramidas <keramida@FreeBSD.org> |
The .Fn function.
|
| #
00c3b17e
|
| 03-Jul-2002 |
Chris Costello <chris@FreeBSD.org> |
Correct a call to fcntl(F_SETFD) to use `FD_CLOEXEC' instead of `1'.
|
| #
db8caf03
|
| 26-Oct-2001 |
Ruslan Ermilov <ru@FreeBSD.org> |
Remove the internal implementation details of wrapping syscalls, which do not match the reality anyway.
Approved by: deischen, bde
|
| #
32eef9ae
|
| 01-Oct-2001 |
Ruslan Ermilov <ru@FreeBSD.org> |
mdoc(7) police: Use the new .In macro for #include statements.
|
| #
b1250632
|
| 09-Aug-2001 |
Yaroslav Tykhiy <ytykhiy@gmail.com> |
Use the ``.Rv -std'' mdoc(7) macro in appropriate cases.
Reviewed by: ru
|
| #
7ebcc426
|
| 15-Jul-2001 |
Dima Dorfman <dd@FreeBSD.org> |
Remove whitespace at EOL.
|
| #
a307d598
|
| 10-Jul-2001 |
Ruslan Ermilov <ru@FreeBSD.org> |
mdoc(7) police: removed HISTORY info from the .Os call.
|
| #
70d51341
|
| 09-Jul-2001 |
Dima Dorfman <dd@FreeBSD.org> |
mdoc(7) police: remove extraneous .Pp before and/or after .Sh.
|
| #
bb33e422
|
| 23-Jun-2000 |
Chris Costello <chris@FreeBSD.org> |
Replace .Va, .Ar and .Nm with .Fa or .Va where necessary, examples: ``.Ar errno'' -> ``.Va errno'' ``.Nm ops'' -> ``.Fa ops'' ``.Va fd'' -> ``.Fa fd''
|