557 Commits
Author SHA1 Message Date
Tristan a6f94564f2 fix: use snprintf to prevent stack buffer overflow in REGISTER_SUPER_ACK IPv6 handling (#1251)
sprintf(ip_tmp, "%s:%u", ...) in the REGISTER_SUPER_ACK decoder can
overflow the 48-byte ip_tmp stack buffer when formatting an IPv6
address (up to 45 chars) with a port number, producing up to 52 bytes.

Replace sprintf with snprintf(ip_tmp, sizeof(ip_tmp), ...) so the
output is truncated to the buffer size.
2026-10-17 14:56:56 +02:00
HoneyBunnyQTandClaude Opus 5.5 fdd969b9c7 Remotely triggerable Denial of Service (#1249)
* header_encryption: require a full common header before decrypting

packet_header_decrypt() takes header_len from the decrypted magic and
only checked header_len <= packet_len.  For a packet of another
community (or a made-up one) the value is arbitrary; below 16 the
header_len - 16 argument to speck_ctr() wraps to a huge size_t and the
decryption reads and writes far past packet[].  One crafted UDP datagram
(or ~1 in 2^28 random ones per key) crashes any edge or supernode that
attempts header decryption; a supernode tries its federation key on
every non-plain header.  Require at least the 24-byte common header, as
the encrypt side already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* transform_cc20: decrypt only the ciphertext, not the IV length extra

transop_decode_cc20() passed in_len (iv + ciphertext) as the length of
the ciphertext that follows the iv, so cc20_crypt() read 16 bytes past
the input and wrote 16 past the output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 11:28:41 +02:00
Akhil KoulandAkhil Koul 4831375d6e fix: use lzo1x_decompress_safe to prevent stack buffer overflow (#1245)
Replace lzo1x_decompress() with lzo1x_decompress_safe() in
transop_decode_lzo(). The unsafe variant does not enforce the output
buffer size limit, allowing a crafted compressed payload to overflow
the N2N_PKT_BUF_SIZE (2048 byte) stack buffer in handle_PACKET().

The safe variant (already bundled in src/minilzo.c) validates output
bounds during decompression, preventing the overflow.

The post-decompression size check was ineffective because the overflow
had already occurred before the check executed.

CAN-2026-2035137

Co-authored-by: Akhil Koul <akkoul@amazon.com>
2026-08-05 10:59:21 +02:00
Lars Wallenborn 98738bce4f edge, supernode: allow -t 0 to disable the management UDP port (#1242)
* supernode: allow -t 0 to disable the management port

* supernode: skip mgmt-socket fd_set/fd_isset when disabled

* edge: allow -t 0 to disable the management port

* edge: skip mgmt-socket fd_set/fd_isset when disabled

* docs: document -t 0 to disable the management port
2026-08-05 10:59:03 +02:00
Michael Bommarito 854fbbe01b wire: bound decoded auth.token_size and num_sn to destination sizes (#1243)
decode_buf() verifies that the source packet still holds the requested
number of bytes, but not that the requested length fits the destination
buffer. The REGISTER_SUPER / UNREGISTER_SUPER / REGISTER_SUPER_ACK /
REGISTER_SUPER_NAK decoders read auth.token_size (a 16-bit field) and
num_sn (an 8-bit count) directly from the wire and pass them to
decode_buf() targeting fixed-size destinations: auth.token is
N2N_AUTH_MAX_TOKEN_SIZE (48) bytes, and the REGISTER_SUPER_ACK backup
list is bounded by REG_SUPER_ACK_PAYLOAD_SPACE.

A length field larger than its destination therefore lets a malformed
packet write past the end of the buffer. Validate token_size against
N2N_AUTH_MAX_TOKEN_SIZE and num_sn against REG_SUPER_ACK_PAYLOAD_SPACE
before calling decode_buf(), returning a decode error otherwise. A
conforming peer never sends a larger value, so well-formed traffic is
unaffected.

Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
2026-06-22 06:59:21 +02:00
thomasysliu 682555ffde Update for MINGW windows build (#1232)
Add missing header stdlib.h, iphlpapi.h
Force type casting for CryptGenRandom, setsockopt, strncpy
ifdef for getenv proto type
2026-03-02 22:37:26 +01:00
Simon Brodeur 23e5160fc8 Update tuntap_linux.c (#1169)
Let the kernel takes care of assigning the port ID of the netlink socket
2025-05-02 18:26:25 +02:00
Hamish Coleman fff50a7d80 Ensure the code style is kept 2023-10-24 11:20:13 +01:00
Hamish Coleman d2bafa716d Fix API initialisation to actually ignore invalid packets or passwords 2023-10-24 11:20:13 +01:00
Hamish Coleman beb14c8d70 Dont treat bools as a magic number and simplify negated tests where possible 2023-10-24 11:20:13 +01:00
Hamish Coleman 1a598fa43b Ensure that we initialise the purgeability of peer structures when we allocate them 2023-10-24 11:20:13 +01:00
shaxxx 7c107887f4 Fix auto IP tracking 2023-08-27 15:04:39 +01:00
Hamish Coleman f79153166b Concentrate more windows wierdness in one place - allowing proper ordering of crazy defs and includes 2023-08-03 21:40:31 +01:00
Hamish Coleman 65359c7916 Add a missing library function 2023-08-03 21:40:31 +01:00
Hamish Coleman 5514d91976 For some reason, these headers dont work for 64bit - windows is strange 2023-08-03 21:40:31 +01:00
Hamish Coleman 3bf584c580 Add tweaks to support windows XP 2023-08-03 21:40:31 +01:00
Hamish Coleman 439939dc7b Simplify tuntap_open by using one function prototype for all OS 2023-08-03 21:40:31 +01:00
Hamish Coleman 6b8ba8aa94 Move the examples to their own directory 2023-07-31 20:56:49 +01:00
Hamish Coleman 6ddaaaa917 Move win32 specific file to the right dir 2023-07-31 20:56:49 +01:00
Hamish Coleman 83078c8104 Simplify win32 build process
When building on win32 systems, simply add the win32 specific functions
to the libn2n.a, which simplifies the commands needed.

By moving the win32 source code into the src directory, the source code
is better consolidated.
2023-07-31 20:56:49 +01:00
Hamish Coleman 6957b16537 Address compiler warning on older gcc 2023-07-06 02:54:36 +08:00
Hamish Coleman 433b14c52f Simplify openssl library detection and macros 2023-07-02 22:18:09 +08:00
Hamish Coleman f05c24b259 Fix openssl support and add it to tests 2023-07-01 19:08:43 +08:00
Hamish Coleman 473b89c963 Simplify build system by using standard macro
Most environments have predefined macros that identify the environment
to the source code.  If we use these macros instead of defining our own
then there is one less parameter difference to keep track of with
different builds

cf:
    http://web.archive.org/web/20191012035921/http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
    https://sourceforge.net/p/predef/wiki/OperatingSystems/
2023-07-01 19:08:43 +08:00
Hamish Coleman 041233dc8b Address more windows compile warnings 2023-06-29 06:00:56 +08:00
Hamish Coleman d21a4fe0a2 Remove some unneeded includes 2023-06-25 22:40:46 +08:00
Hamish Coleman 548e1204f3 Address warning - another windows pedantic header order issue 2023-06-25 22:40:46 +08:00
Hamish Coleman 0d005d189d Fix silent failure of sizeof for STRBUF_INIT() 2023-06-25 21:08:36 +08:00
Hamish Coleman a2c78e140a Minor fixes for FreeBSD 2023-06-25 19:25:00 +08:00
Hamish Coleman 89125ec423 Use the defined access method for structure.
Not all struct sockaddr are going to have the sa_family as their first field.
Since there is a named structure member, we can simply use that and let
the compiler sort it out.

This fixes a bug with at least FreeBSD and allows us to remove the
special case for Apple.
2023-06-25 19:25:00 +08:00
Hamish Coleman cfc9c8c10d Simplify and make more consistant the pthread library 2023-06-25 17:56:09 +08:00
Hamish Coleman 21ac30c121 Use the correct modern windows sockets header
As suggested in a PR from @Legend-Master (this change is basically
unrelated to the main point of his PR, so extracted here)

Windows is a confusing and disappointing development environment.  They
completely replaced all the definitions in winsock.h with exact
equivalents in winsock2.h (except for a small number of deprecated
functions).

However they didnt make them mutually exclusive - so if you include
both, you get errors.  They also automatically include winsock.h from
windows.h, so you must remember to include winsock2.h first.  They also
didnt just remove winsock.h and replace it with the new contents.

(Probably in the name of "compatibility", whilst swearing that the new
winsock is the same as the old one - because if you cannot believe two
inconsistent things simultaneously, you shouldnt be a windows
programmer)

All these things are totally nuts.  Thanks, windows dev environment,
for not noticing that this is nuts
2023-06-25 02:46:03 +08:00
Hamish Coleman 1b83e0e0e9 Remove some config items that are just wrong with cross compilation 2023-06-25 02:07:49 +08:00
Hamish Coleman 4f9a7d31d3 Fix bug in returned interface address 2023-06-24 23:31:20 +08:00
Hamish Coleman a7fc1c2bbc Merge branch 'dev' into iwyu 2023-06-18 12:31:58 +01:00
Hamish Coleman 585b3cec59 iwyu: n2n.h
There is still cleanup work to be done in the headers, but this
concludes the major include-what-you-use refactoring.  No functional
change is intended or expected and all tests are passing.

It is now a lot easier to see what is used from each header and work on
possible refactoring in the future.

The include-what-you-use tool is awkward to use with the current state
of the build system - and will always be difficult to use in a
multi-platform safe way.  However, I hope to provide a non manual
process for running with the tool in the future.
2023-06-18 12:14:23 +01:00
Hamish Coleman b9dcb3fd35 iwyu: wire.c 2023-06-18 09:32:08 +01:00
Hamish Coleman de56ebb127 iwyu: tuntap_linux.c 2023-06-18 09:12:36 +01:00
Tony e397a5af75 Add close window support for Windows (#1111)
* Add close window support for Windows

* Support logoff and shudown events as well

Without this change, when you close the terminal/shell window, it won't have the time to clean up which can cause authentication errors if you try to reconnect.

Blocking here infinitely is fine since when our main thread returns, it will shut down anyway

I found Go is doing this when I was searching, and there's a comment explained how it works: https://github.com/golang/go/issues/41884#issuecomment-706695923
2023-06-18 09:02:05 +01:00
Tony 76cbff370e Fix purgeable is always false on supernode peer list (#1117)
* Fix purgeable is always false on sn peer list
- And change sn_purge to bool

* Change all keep_on_running to bool

* Fix wrong `keep_running` type
2023-06-18 08:58:49 +01:00
Hamish Coleman 852fc6ea8f Minimal update to transform_zstd suggested by iwyu.
This file was not active during the iwyu run, so it will need to be
expanded upon later.
2023-06-16 11:05:35 +01:00
Hamish Coleman 0e175d35f6 iwyu: transform_tf.c 2023-06-16 09:44:53 +01:00
Hamish Coleman 76629dcf6a iwyu: transform_speck.c 2023-06-16 09:44:04 +01:00
Hamish Coleman 6deebe6f1a iwyu: transform_null.c 2023-06-16 09:43:02 +01:00
Hamish Coleman 89cb9419c7 iwyu: transform_lzo.c 2023-06-16 09:42:18 +01:00
Hamish Coleman 8b6fcb8ab6 iwyu: transform_cc20.c 2023-06-16 09:41:08 +01:00
Hamish Coleman 8443c29428 iwyu: transform_aes.c 2023-06-16 09:40:16 +01:00
Hamish Coleman fa4cf74ff2 iwyu: supernode.c 2023-06-16 09:33:52 +01:00
Hamish Coleman 6ee14559f9 iwyu: sn_utils.c 2023-06-16 09:26:04 +01:00
Hamish Coleman a8356c93db iwyu: sn_selection.c 2023-06-16 09:19:39 +01:00