Commit Graph

370 Commits

Author SHA1 Message Date
Michael Tuexen
04ede3675e sctp: only start shutdown guard timer when sending SHUTDOWN chunk
The intention is to protect a malicious peer not following the
shutdown procedures.

MFC after:	1 week
2023-05-03 20:28:46 +02:00
Michael Tuexen
d9ae4adff2 sctp: improve shutdown(..., SHUT_WR) handling
When shutdown(..., SHUT_WR) is called in the front states, send a
SHUTDOWN chunk when a COOKIE ACK chunk is received and there is
no outstanding data.

MFC after:	1 week
2023-05-03 17:33:49 +02:00
Michael Tuexen
1f0e13449b sctp: improve handling of stale cookie error causes
* If a measure of staleness of 0 is reported, use the RTT instead.
* Ensure that we always send a cookie preservative parameter by
  rounding up during the calculation.
* If allowed, perform a round trip time measurement.
* Clear the overall error counter, since the error cause also
  acts like an ACK.

MFC after:	1 week
2023-04-30 11:39:32 +02:00
Michael Tuexen
8ed1e2c880 sctp: enforce Kahn's rule during the handshake
Don't take RTT measurements on packets containing INIT or COOKIE-ECHO
chunks, when they were retransmitted.

MFC after:	1 week
2023-03-16 17:40:40 +01:00
Michael Tuexen
c91ae48a25 sctp: don't do RTT measurements with cookies
When receiving a cookie, the receiver does not know whether the
peer retransmitted the COOKIE-ECHO chunk or not. Therefore, don't
do an RTT measurement. It might be much too long.
To overcome this limitation, one could do at least two things:
1. Bundle the INIT-ACK chunk with a HEARTBEAT chunk for doing the
   RTT measurement. But this is not allowed.
2. Add a flag to the COOKIE-ECHO chunk, which indicates that it
   is the initial transmission, and not a retransmission. But
   this requires an RFC.

MFC after:	1 week
2023-03-16 10:45:13 +01:00
Michael Tuexen
6026b45aab sctp: improve negotiation of zero checksum feature
Enforce consistency between announcing 0-cksum support and actually
using it in the association. The value from the inp when the
INIT ACK is sent must be used, not the one from the inp when the
cookie is received.
2023-03-15 22:29:52 +01:00
Michael Tuexen
4a2b92d99f sctp: initial implementation of draft-tuexen-tsvwg-sctp-zero-checksum 2023-03-10 01:45:46 +01:00
Michael Tuexen
dd36606b1b sctp: improve sending of ABORT packets in response to INIT-ACKs
Ensure that the initiate tag of the INIT-ACK chunk is used as the
verification tag of the packet containing the ABORT chunk.

Reported by:	Suganya Dharma
MFC after:	1 week
2022-10-13 01:05:44 +02:00
Michael Tuexen
a5c2009dd8 sctp: improve handling of sctp inpcb flags
Use an atomic operation when the inp is not write locked.

Reported by:	syzbot+bf27083e9a3f8fde8b4d@syzkaller.appspotmail.com
MFC after:	3 days
2022-06-04 07:38:19 +02:00
Michael Tuexen
f210e4fbc5 sctp: cleanup, no functional change intended
MFC after:	3 days
2022-05-14 08:30:41 +02:00
Michael Tuexen
9b2a35b3a9 sctp: improve consistency
No functional change intended.

MFC after:	3 days
2022-05-14 06:28:19 +02:00
Michael Tuexen
e0127ea4c6 sctp: improve locking
Hold a refcount while giving up an stcp lock. This issue was
found by running syzkaller.

MFC after:	3 days
2022-04-15 13:58:45 +02:00
Michael Tuexen
e7e65008ff sctp: fix typos
Thanks to David Sanders for fixing the typos in the userland stack.

MFC after:	3 days
2022-03-29 21:09:51 +02:00
Michael Tuexen
5ac91821f5 sctp: get rid of stcb send lock
Just use the stcb lock instead to simplify locking.

Reported by:	syzbot+d00b202063150f85b110@syzkaller.appspotmail.com
Reported by:	syzbot+87f268a0a6d2d6383306@syzkaller.appspotmail.com
MFC after:	3 days
2022-03-29 01:50:17 +02:00
Michael Tuexen
502d5e8500 sctp: improve counting of incoming chunks
MFC after:	3 days
2022-01-01 20:59:47 +01:00
Michael Tuexen
2de2ae331b sctp: improve sctp_pathmtu_adjustment()
Allow the resending of DATA chunks to be controlled by the caller,
which allows retiring sctp_mtu_size_reset() in a separate commit.
Also improve the computaion of the overhead and use 32-bit integers
consistently.
Thanks to Timo Voelker for pointing me to the code.

MFC after:	3 days
2021-12-30 15:16:05 +01:00
Michael Tuexen
3c1ba6f394 sctp: improve consistency, no functional change intended 2021-11-26 12:53:43 +01:00
Gordon Bergling
d2e616147d sctp: Fix a typo in a comment
- s/assue/assume/

MFC after:	3 days
2021-09-26 15:15:39 +02:00
Michael Tuexen
762ae0ec8d sctp: Simplify stream scheduler usage
Callers are getting the stcb send lock, so just KASSERT that.
No need to signal this when calling stream scheduler functions.
No functional change intended.

MFC after:	1 week
2021-09-21 17:13:57 +02:00
Michael Tuexen
4542164685 sctp: cleanup, no functional change intended
MFC after:	1 week
2021-09-15 10:18:11 +02:00
Michael Tuexen
29545986bd sctp: avoid LOR
Don't lock the inp-info lock while holding an stcb lock.

MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D31921
2021-09-12 21:11:14 +02:00
Mark Johnston
2d5c48eccd sctp: Tighten up locking around sctp_aloc_assoc()
All callers of sctp_aloc_assoc() mark the PCB as connected after a
successful call (for one-to-one-style sockets).  In all cases this is
done without the PCB lock, so the PCB's flags can be corrupted.  We also
do not atomically check whether a one-to-one-style socket is a listening
socket, which violates various assumptions in solisten_proto().

We need to hold the PCB lock across all of sctp_aloc_assoc() to fix
this.  In order to do that without introducing lock order reversals, we
have to hold the global info lock as well.

So:
- Convert sctp_aloc_assoc() so that the inp and info locks are
  consistently held.  It returns with the association lock held, as
  before.
- Fix an apparent bug where we failed to remove an association from a
  global hash if sctp_add_remote_addr() fails.
- sctp_select_a_tag() is called when initializing an association, and it
  acquires the global info lock.  To avoid lock recursion, push locking
  into its callers.
- Introduce sctp_aloc_assoc_connected(), which atomically checks for a
  listening socket and sets SCTP_PCB_FLAGS_CONNECTED.

There is still one edge case in sctp_process_cookie_new() where we do
not update PCB/socket state correctly.

Reviewed by:	tuexen
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31908
2021-09-11 10:15:21 -04:00
Michael Tuexen
aab1d593b2 sctp: minor cleanups, no functional change intended 2021-09-08 15:13:49 +02:00
Mark Johnston
e8e23ec127 sctp: Remove an unused sctp_inpcb field
This appears to be unused in usrsctp as well.  No functional change
intended.

Reviewed by:	tuexen
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31812
2021-09-07 11:19:29 -04:00
Mark Johnston
c98bf2a45e sctp: Always check for a vanishing inpcb when processing COOKIE-ECHO
We previously did this only in the normal case where no association
exists yet.  However, it is not safe to process COOKIE-ECHO even if an
association exists, as sctp_process_cookie_existing() may dereference
the socket pointer.

See also commit 0c7dc84076.

Reviewed by:	tuexen
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31755
2021-09-01 10:28:17 -04:00
Michael Tuexen
a3665770d7 sctp: improve handling of illegal parameters of INIT-ACK chunks
MFC after:	3 days
2021-08-20 14:06:41 +02:00
Michael Tuexen
eba8e643b1 sctp: improve handling of INIT chunks with invalid parameters
MFC after:	3 days
2021-08-19 00:33:28 +02:00
Michael Tuexen
105b68b42d sctp: Fix errno in case of association setup failures
Do not report always ETIMEDOUT, but only when appropriate. In
other cases report ECONNABORTED.

MFC after:	3 days
2021-07-09 23:19:25 +02:00
Michael Tuexen
c7f048ab35 sctp: initialize sequence numbers for ECN correctly
MFC after:	3 days
Reported by:	Junseok Yang (for the userland stack)
2021-06-27 20:14:48 +02:00
Michael Tuexen
6587a2bd1e sctp: Fix length check for ECNE chunks
MFC after:	3 days
2021-06-27 16:10:39 +02:00
Michael Tuexen
eec6aed5b8 sctp: fix another locking bug in COOKIE handling
Thanks to Tolya Korniltsev for reporting the issue for
the userland stack and testing the fix.

MFC after:	3 days
2021-05-12 23:05:28 +02:00
Michael Tuexen
12dda000ed sctp: fix locking in case of error handling during a restart
Thanks to Taylor Brandstetter for finding the issue and providing
a patch for the userland stack.

MFC after:	3 days
2021-05-12 15:29:06 +02:00
Michael Tuexen
d1cb8d11b0 sctp: improve consistency when handling chunks of wrong size
MFC after:	3 days
2021-05-06 01:02:41 +02:00
Michael Tuexen
b621fbb1bf sctp: drop packet with SHUTDOWN-ACK chunks with wrong vtags
MFC after:	3 days
2021-05-04 18:43:31 +02:00
Michael Tuexen
a89481d328 sctp: improve restart handling
This fixes in particular a possible use after free bug reported
Anatoly Korniltsev and Taylor Brandstetter for the userland stack.

MFC after:	3 days
2021-05-03 02:20:24 +02:00
Alexander Motin
655c200cc8 Fix build after 5f2e183505. 2021-05-02 20:07:38 -04:00
Michael Tuexen
5f2e183505 sctp: improve error handling in INIT/INIT-ACK processing
When processing INIT and INIT-ACK information, also during
COOKIE processing, delete the current association, when it
would end up in an inconsistent state.

MFC after:	3 days
2021-05-02 22:41:35 +02:00
Michael Tuexen
9de7354bb8 sctp: improve consistency in handling chunks with wrong size
Just skip the chunk, if no other handling is required by the
specification.
2021-04-28 18:11:06 +02:00
Michael Tuexen
059ec2225c sctp: cleanup verification of INIT and INIT-ACK chunks 2021-04-27 12:45:43 +02:00
Michael Tuexen
c70d1ef15d sctp: improve handling of illegal packets containing INIT chunks
Stop further processing of a packet when detecting that it
contains an INIT chunk, which is too small or is not the only
chunk in the packet. Still allow to finish the processing
of chunks before the INIT chunk.

Thanks to Antoly Korniltsev and Taylor Brandstetter for reporting
an issue with the userland stack, which made me aware of this
issue.

MFC after:	3 days
2021-04-26 10:43:58 +02:00
Michael Tuexen
163153c2a0 sctp: small cleanup, no functional change
MFC:		3 days
2021-04-26 02:56:48 +02:00
Michael Tuexen
7a051c0a78 sctp: improve consistency
No functional change intended.

MFC:	1 week
2021-01-24 00:07:41 +01:00
Michael Tuexen
0066de1c4b Harden the handling of outgoing streams in case of an restart or INIT
collision. This avouds an out-of-bounce access in case the peer can
break the cookie signature. Thanks to Felix Wilhelm from Google for
reporting the issue.

MFC after:		1 week
2020-12-13 23:51:51 +00:00
Michael Tuexen
aa6db9a045 Clean up more resouces of an existing SCTP association in case of
a restart.

This fixes a use-after-free scenario, which was reported by Felix
Wilhelm from Google in case a peer is able to modify the cookie.
However, this can also be triggered by an assciation restart under
some specific conditions.

MFC after:		1 week
2020-12-12 22:23:45 +00:00
Michael Tuexen
a92d501617 Improve the handling of cookie life times.
The staleness reported in an error cause is in us, not ms.
Enforce limits on the life time via sysct; and socket options
consistently. Update the description of the sysctl variable to
use the right unit. Also do some minor cleanups.
This also fixes an interger overflow issue if the peer can
modify the cookie. This was reported by Felix Weinrank by fuzz testing
the userland stack and in
https://oss-fuzz.com/testcase-detail/4800394024452096

MFC after:		3 days
2020-10-16 10:44:48 +00:00
Michael Tuexen
6f155d690b Reset delayed SACK state when restarting an SCTP association.
MFC after:		3 days
2020-10-06 14:26:05 +00:00
Michael Tuexen
b954d81662 Ensure variables are initialized before used.
MFC after:		3 days
2020-10-06 11:29:08 +00:00
Michael Tuexen
6176f9d6df Remove dead stores reported by clang static code analysis
MFC after:		3 days
2020-10-06 11:08:52 +00:00
Michael Tuexen
c8e55b3c0c Whitespace changes.
MFC after:		3 days
2020-10-06 09:51:40 +00:00
Michael Tuexen
b15f541113 Improve the input validation and processing of cookies.
This avoids setting the association in an inconsistent
state, which could result in a use-after-free situation.
This can be triggered by a malicious peer, if the peer
can modify the cookie without the local endpoint recognizing
it.
Thanks to Ned Williamson for reporting the issue.

MFC after:		3 days
2020-09-29 09:36:06 +00:00