aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet6/sctp6_usrreq.c
Commit message (Collapse)AuthorAgeFilesLines
* sctp(4): Fix typos in source code commentsGordon Bergling2024-08-121-3/+3
| | | | | | | | | | - s/collasped/collapsed/ - s/defininitions/definitions/ - s/optionaly/optionally/ Obtained from: NetBSD (cherry picked from commit 58c99e07506e67c06d703b080c2fc22cc39237f2)
* sctp: cleanup cdefs.h includeMichael Tuexen2024-01-111-1/+0
| | | | (cherry picked from commit c3179e6660e1365111b89cb6c05c3a4c47375e73)
* sctp: remove duplicate codeMichael Tuexen2024-01-111-47/+1
| | | | | | No functional change intended. (cherry picked from commit 9ade2745db8be213e9da2225795cafb8e7575e29)
* sctp: cleanupMichael Tuexen2024-01-111-8/+1
| | | | | | No functional change intended. (cherry picked from commit c7587f7a3f8ddcc8dd209c9cff7b9ec3bf353dec)
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-231-2/+0
| | | | | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/ Similar commit in current: (cherry picked from commit 685dc743dc3b)
* sctp: improve sctp_pathmtu_adjustment()Michael Tuexen2022-02-221-1/+1
| | | | | | | | | | 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. (cherry picked from commit 2de2ae331be2504d1038b2124e7d44f23aa70405)
* sctp: Tighten up locking around sctp_aloc_assoc()Mark Johnston2022-02-221-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31908 (cherry picked from commit 2d5c48eccd9f29b9df8020bb1c3a8ffda38df37b)
* sctp: improve handling of IPv4 addresses on IPV6 socketsMichael Tuexen2022-02-221-2/+4
| | | | | | Reported by: syzbot+08fe66e4bfc2777cba95@syzkaller.appspotmail.com (cherry picked from commit 784692c74019fa69b5298fb1693a97f107c56b4b)
* sctp: Fix errno in case of association setup failuresMichael Tuexen2021-07-131-1/+1
| | | | | | | Do not report always ETIMEDOUT, but only when appropriate. In other cases report ECONNABORTED. (cherry picked from commit 105b68b42dd11bce5c554b1ef0ddf73aa069d7da)
* sctp: initialize sequence numbers for ECN correctlyMichael Tuexen2021-07-131-1/+1
| | | | | | Reported by: Junseok Yang (for the userland stack) (cherry picked from commit c7f048ab3532a9f081addd6da0adf96f25271de8)
* Fix mbuf leaks in various pru_send implementationsMark Johnston2021-05-261-0/+25
| | | | | | | | | | | | | | | The various protocol implementations are not very consistent about freeing mbufs in error paths. In general, all protocols must free both "m" and "control" upon an error, except if PRUS_NOTREADY is specified (this is only implemented by TCP and unix(4) and requires further work not handled in this diff), in which case "control" still must be freed. This diff plugs various leaks in the pru_send implementations. Reviewed by: tuexen Sponsored by: The FreeBSD Foundation (cherry picked from commit d8acd2681bcfb2ff7eb154df82f268b1cb191b4c)
* Add missing sockaddr length and family validation to various protocolsMark Johnston2021-05-171-0/+21
| | | | | | | | | | | | | | | Several protocol methods take a sockaddr as input. In some cases the sockaddr lengths were not being validated, or were validated after some out-of-bounds accesses could occur. Add requisite checking to various protocol entry points, and convert some existing checks to assertions where appropriate. Reported by: syzkaller+KASAN Reviewed by: tuexen, melifaro Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29519 (cherry picked from commit f161d294b92732df6254a89f393ab24999e122bf)
* net: Introduce IPV6_DSCP(), IPV6_ECN() and IPV6_TRAFFIC_CLASS() macrosHans Petter Selasky2021-05-101-1/+1
| | | | | | | | | | | | | Introduce convenience macros to retrieve the DSCP, ECN or traffic class bits from an IPv6 header. Use them where appropriate. Reviewed by: ae (previous version), rscheff, tuexen, rgrimes Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D29056 (cherry picked from commit bb4a7d94b99fbf7f59c876ffff8ded5f6a5b5c3e)
* net: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-6/+0
| | | | Notes: svn path=/head/; revision=365071
* Retire SCTP_SO_LOCK_TESTING.Michael Tuexen2020-06-071-14/+0
| | | | | | | | | | | | This was intended to test the locking used in the MacOS X kernel on a FreeBSD system, to make use of WITNESS and other debugging infrastructure. This hasn't been used for ages, to take it out to reduce the #ifdef complexity. MFC after: 1 week Notes: svn path=/head/; revision=361895
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (14 of many)Pawel Biernacki2020-02-241-3/+4
| | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Approved by: kib (mentor, blanket) Differential Revision: https://reviews.freebsd.org/D23639 Notes: svn path=/head/; revision=358285
* Epochify SCTP.Michael Tuexen2020-02-181-1/+10
| | | | Notes: svn path=/head/; revision=358083
* Update the hostcache also for PTB messages received for SCTP/IPv6.Michael Tuexen2019-12-011-0/+5
| | | | | | | | | | | | The corresponding code for SCTP/IPv4 was introduced in https://svnweb.freebsd.org/base?view=revision&revision=317597 Submitted by: Julius Flohr MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D22605 Notes: svn path=/head/; revision=355264
* Fix m_pullup() problem after removing PULLDOWN_TESTs and KAME EXT_*macros.Bjoern A. Zeeb2019-12-011-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | r354748-354750 replaced the KAME macros with m_pulldown() calls. Contrary to the rest of the network stack m_len checks before m_pulldown() were not put in placed (see r354748). Put these m_len checks in place for now (to go along with the style of the network stack since the initial commits). These are not put in for performance but to avoid an error scenario (even though it also will help performance at the moment as it avoid allocating an extra mbuf; not because of the unconditional function call). The observed error case went like this: (1) an mbuf with M_EXT arrives and we call m_pullup() unconditionally on it. (2) m_pullup() will call m_get() unless the requested length is larger than MHLEN (in which case it'll m_freem() the perfectly fine mbuf) and migrate the requested length of data and pkthdr into the new mbuf. (3) If m_get() succeeds, a further m_pullup() call going over MHLEN will fail. This was observed with failing auto-configuration as an RA packet of 200 bytes exceeded MHLEN and the m_pullup() called from nd6_ra_input() dropped the mbuf. (Re-)adding the m_len checks before m_pullup() calls avoids this problems with mbufs using external storage for now. MFC after: 3 weeks Sponsored by: Netflix Notes: svn path=/head/; revision=355254
* netinet*: replace IP6_EXTHDR_GET()Bjoern A. Zeeb2019-11-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | In a few places we have IP6_EXTHDR_GET() left in upper layer protocols. The IP6_EXTHDR_GET() macro might perform an m_pulldown() in case the data fragment is not contiguous. Convert these last remaining instances into m_pullup()s instead. In CARP, for example, we will a few lines later call m_pullup() anyway, the IPsec code coming from OpenBSD would otherwise have done the m_pullup() and are copying the data a bit later anyway, so pulling it in seems no better or worse. Note: this leaves very few m_pulldown() cases behind in the tree and we might want to consider removing them as well to make mbuf management easier again on a path to variable size mbufs, especially given m_pulldown() still has an issue not re-checking M_WRITEABLE(). Reviewed by: gallatin MFC after: 8 weeks Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D22335 Notes: svn path=/head/; revision=354749
* Ensure that the flags indicating IPv4/IPv6 are not changed by failingMichael Tuexen2019-10-241-3/+10
| | | | | | | | | | | | | | | bind() calls. This would lead to inconsistent state resulting in a panic. A fix for stable/11 was committed in https://svnweb.freebsd.org/base?view=revision&revision=338986 An accelerated MFC is planned as discussed with emaste@. Reported by: syzbot+2609a378d89264ff5a42@syzkaller.appspotmail.com Obtained from: jtl@ MFC after: 1 day Sponsored by: Netflix, Inc. Notes: svn path=/head/; revision=354044
* Remove line not needed.Michael Tuexen2019-10-131-2/+0
| | | | | | | | Submitted by: markj@ MFC after: 3 days Notes: svn path=/head/; revision=353466
* Improve consistency. No functional change.Michael Tuexen2019-08-051-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=350588
* IPv6 cleanup: kernelBjoern A. Zeeb2019-08-021-28/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Finish what was started a few years ago and harmonize IPv6 and IPv4 kernel names. We are down to very few places now that it is feasible to do the change for everything remaining with causing too much disturbance. Remove "aliases" for IPv6 names which confusingly could indicate that we are talking about a different data structure or field or have two fields, one for each address family. Try to follow common conventions used in FreeBSD. * Rename sin6p to sin6 as that is how it is spelt in most places. * Remove "aliases" (#defines) for: - in6pcb which really is an inpcb and nothing separate - sotoin6pcb which is sotoinpcb (as per above) - in6p_sp which is inp_sp - in6p_flowinfo which is inp_flow * Try to use ia6 for in6_addr rather than in6p. * With all these gone also rename the in6p variables to inp as that is what we call it in most of the network stack including parts of netinet6. The reasons behind this cleanup are that we try to further unify netinet and netinet6 code where possible and that people will less ignore one or the other protocol family when doing code changes as they may not have spotted places due to different names for the same thing. No functional changes. Discussed with: tuexen (SCTP changes) MFC after: 3 months Sponsored by: Netflix Notes: svn path=/head/; revision=350531
* When calling sctp_initialize_auth_params(), the inp must have atMichael Tuexen2019-07-141-5/+2
| | | | | | | | | | | least a read lock. To avoid more complex locking dances, just call it in sctp_aloc_assoc() when the write lock is still held. Reported by: syzbot+08a486f7e6966f1c3cfb@syzkaller.appspotmail.com MFC after: 1 week Notes: svn path=/head/; revision=349986
* Use a macro to set the assoc state. I missed this in r337706.Michael Tuexen2018-08-141-1/+1
| | | | Notes: svn path=/head/; revision=337738
* Whitespace changes due to changes in ident.Michael Tuexen2018-07-191-0/+7
| | | | Notes: svn path=/head/; revision=336511
* Revert https://svnweb.freebsd.org/changeset/base/336503Michael Tuexen2018-07-191-9/+2
| | | | | | | since I also ran the export script with different parameters. Notes: svn path=/head/; revision=336508
* Whitespace changes due to change if ident.Michael Tuexen2018-07-191-2/+9
| | | | Notes: svn path=/head/; revision=336503
* Fix a logical inversion bug.Michael Tuexen2018-04-081-1/+1
| | | | | | | | | Thanks to Irene Ruengeler for finding and reporting this bug. MFC after: 3 days Notes: svn path=/head/; revision=332273
* Retire SCTP_WITH_NO_CSUM option.Michael Tuexen2017-12-071-8/+0
| | | | | | | | | | | This option was used in the early days to allow performance measurements extrapolating the use of SCTP checksum offloading. Since this feature is now available, get rid of this option. This also un-breaks the LINT kernel. Thanks to markj@ for making me aware of the problem. Notes: svn path=/head/; revision=326672
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Allow the setting of the MTU for future paths using an SCTP socket option.Michael Tuexen2017-11-031-0/+4
| | | | | | | | | This functionality was missing. MFC after: 1 week Notes: svn path=/head/; revision=325370
* Fix a locking issue found by Coverity scanning the usrsctp library.Michael Tuexen2017-09-091-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=323377
* Use memset/memcpy instead of bzero/bcopy.Michael Tuexen2017-07-191-1/+1
| | | | | | | | | | Just use one variant instead of both. Use the memset/memcpy ones since they cause less problems in crossplatform deployment. MFC after: 1 week Notes: svn path=/head/; revision=321204
* Fix an issue with MTU calculation if an ICMP messaeg is receivedMichael Tuexen2017-04-261-3/+3
| | | | | | | | | for an SCTP/UDP packet. MFC after: 1 week Notes: svn path=/head/; revision=317464
* Use consistently uint32_t for mtu values.Michael Tuexen2017-04-261-2/+2
| | | | | | | | | | This does not change functionality, but this cleanup is need for further improvements of ICMP handling. MFC after: 1 week Notes: svn path=/head/; revision=317457
* Remove IPsec related PCB code from SCTP.Andrey V. Elsukov2017-02-131-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The inpcb structure has inp_sp pointer that is initialized by ipsec_init_pcbpolicy() function. This pointer keeps strorage for IPsec security policies associated with a specific socket. An application can use IP_IPSEC_POLICY and IPV6_IPSEC_POLICY socket options to configure these security policies. Then ip[6]_output() uses inpcb pointer to specify that an outgoing packet is associated with some socket. And IPSEC_OUTPUT() method can use a security policy stored in the inp_sp. For inbound packet the protocol-specific input routine uses IPSEC_CHECK_POLICY() method to check that a packet conforms to inbound security policy configured in the inpcb. SCTP protocol doesn't specify inpcb for ip[6]_output() when it sends packets. Thus IPSEC_OUTPUT() method does not consider such packets as associated with some socket and can not apply security policies from inpcb, even if they are configured. Since IPSEC_CHECK_POLICY() method is called from protocol-specific input routine, it can specify inpcb pointer and associated with socket inbound policy will be checked. But there are two problems: 1. Such check is asymmetric, becasue we can not apply security policy from inpcb for outgoing packet. 2. IPSEC_CHECK_POLICY() expects that caller holds INPCB lock and access to inp_sp is protected. But for SCTP this is not correct, becasue SCTP uses own locks to protect inpcb. To fix these problems remove IPsec related PCB code from SCTP. This imply that IP_IPSEC_POLICY and IPV6_IPSEC_POLICY socket options will be not applicable to SCTP sockets. To be able correctly check inbound security policies for SCTP, mark its protocol header with the PR_LASTHDR flag. Reported by: tuexen Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D9538 Notes: svn path=/head/; revision=313697
* Merge projects/ipsec into head/.Andrey V. Elsukov2017-02-061-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Small summary ------------- o Almost all IPsec releated code was moved into sys/netipsec. o New kernel modules added: ipsec.ko and tcpmd5.ko. New kernel option IPSEC_SUPPORT added. It enables support for loading and unloading of ipsec.ko and tcpmd5.ko kernel modules. o IPSEC_NAT_T option was removed. Now NAT-T support is enabled by default. The UDP_ENCAP_ESPINUDP_NON_IKE encapsulation type support was removed. Added TCP/UDP checksum handling for inbound packets that were decapsulated by transport mode SAs. setkey(8) modified to show run-time NAT-T configuration of SA. o New network pseudo interface if_ipsec(4) added. For now it is build as part of ipsec.ko module (or with IPSEC kernel). It implements IPsec virtual tunnels to create route-based VPNs. o The network stack now invokes IPsec functions using special methods. The only one header file <netipsec/ipsec_support.h> should be included to declare all the needed things to work with IPsec. o All IPsec protocols handlers (ESP/AH/IPCOMP protosw) were removed. Now these protocols are handled directly via IPsec methods. o TCP_SIGNATURE support was reworked to be more close to RFC. o PF_KEY SADB was reworked: - now all security associations stored in the single SPI namespace, and all SAs MUST have unique SPI. - several hash tables added to speed up lookups in SADB. - SADB now uses rmlock to protect access, and concurrent threads can do SA lookups in the same time. - many PF_KEY message handlers were reworked to reflect changes in SADB. - SADB_UPDATE message was extended to support new PF_KEY headers: SADB_X_EXT_NEW_ADDRESS_SRC and SADB_X_EXT_NEW_ADDRESS_DST. They can be used by IKE daemon to change SA addresses. o ipsecrequest and secpolicy structures were cardinally changed to avoid locking protection for ipsecrequest. Now we support only limited number (4) of bundled SAs, but they are supported for both INET and INET6. o INPCB security policy cache was introduced. Each PCB now caches used security policies to avoid SP lookup for each packet. o For inbound security policies added the mode, when the kernel does check for full history of applied IPsec transforms. o References counting rules for security policies and security associations were changed. The proper SA locking added into xform code. o xform code was also changed. Now it is possible to unregister xforms. tdb_xxx structures were changed and renamed to reflect changes in SADB/SPDB, and changed rules for locking and refcounting. Reviewed by: gnn, wblock Obtained from: Yandex LLC Relnotes: yes Sponsored by: Yandex LLC Differential Revision: https://reviews.freebsd.org/D9352 Notes: svn path=/head/; revision=313330
* Whitespace changes.Michael Tuexen2016-12-261-3/+3
| | | | | | | | | | The toolchain for processing the sources has been updated. No functional change. MFC after: 3 days Notes: svn path=/head/; revision=310590
* Whitespace changes.Michael Tuexen2016-12-061-6/+0
| | | | | | | | | | | The tools using to generate the sources has been updated and produces different whitespaces. Commit this seperately to avoid intermixing these with real code changes. MFC after: 3 days Notes: svn path=/head/; revision=309607
* Don't consider the socket when processing an incoming ICMP/ICMP6 packet,Michael Tuexen2016-06-231-2/+1
| | | | | | | | | | | which was triggered by an SCTP packet. Whether a socket exists, is just not relevant. Approved by: re (kib) MFC after: 1 week Notes: svn path=/head/; revision=302138
* When a client uses UDP encapsulation and lists IP addresses in the INITMichael Tuexen2016-05-011-1/+3
| | | | | | | | | | | chunk, enable UDP encapsulation for all those addresses. This helps clients using a userland stack to support multihoming if they are not behind a NAT. MFC after: 1 week Notes: svn path=/head/; revision=298902
* Address issues found by the XCode code analyzer.Michael Tuexen2016-04-181-2/+1
| | | | Notes: svn path=/head/; revision=298223
* Fix the ICMP6 handling for SCTP.Michael Tuexen2016-04-161-194/+165
| | | | | | | | | Keep the IPv4 code in sync. MFC after: 1 week Notes: svn path=/head/; revision=298132
* Don't leak an address in an error path.Michael Tuexen2016-02-231-0/+2
| | | | | | | | CID: 1351729 MFC after: 3 days Notes: svn path=/head/; revision=295929
* Fix reporting of mapped addressed in getpeername() and getsockname() forMichael Tuexen2016-02-181-25/+24
| | | | | | | | IPv6 SCTP sockets. This bugs were found because of an issue reported by PVS / D5245. Notes: svn path=/head/; revision=295771
* Verify the packet length in sctp6_input().Gleb Smirnoff2016-01-141-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The sctp6_ctlinput() function does not properly check the length of the packet it receives from the ICMP6 input routine. This means that an attacker can craft a packet that will cause a kernel panic. When the kernel receives an ICMP6 error message with one of the types/codes it handles, it calls icmp6_notify_error() to deliver it to the upper-level protocol. icmp6_notify_error() cycles through the extension headers (if any) to find the protocol number of the first non-extension header. It does NOT verify the length of the non-extension header. It passes information about the packet (including the actual packet) to the upper-level protocol's pr_ctlinput function. In the case of SCTP for IPv6, icmp6_notify_error() calls sctp6_ctlinput(). sctp6_ctlinput() assumes that the incoming packet contains a sufficiently-long SCTP header and calls m_copydata() to extract a copy of that header. In turn, m_copydata() assumes that the caller has already verified that the offset and length parameters are correct. If they are incorrect, it will dereference a NULL pointer and cause a kernel panic. In short, no one is sufficiently verifying the input, and the result is a kernel panic. Submitted by: jtl Security: SA-16:01.sctp Notes: svn path=/head/; revision=293906
* Fix the allocation of outgoing streams:Michael Tuexen2015-12-061-1/+1
| | | | | | | | | | | | | * When processing a cookie, use the number of streams announced in the INIT-ACK. * When sending an INIT-ACK for an existing association, use the value from the association, not from the end-point. MFC after: 1 week Notes: svn path=/head/; revision=291904
* Move including netinet/icmp6.h around to avoid a problem when includingMichael Tuexen2015-07-251-4/+1
| | | | | | | | | | netinet/icmp6.h and net/netmap.h. Both use ni_flags... This allows to build multistack with SCTP support. MFC after: 1 week Notes: svn path=/head/; revision=285877