Commit Graph

106 Commits

Author SHA1 Message Date
Christiano Haesbaert 42d7e7a402 Fix multiple vulnerabilities in the resolver
This fixes some vulnerabilities in the resolver that make spoofing DNS
queries somewhat trivial due to the code failing to randomize xid, as
well as match the reply xid with the query, and the origin of the packet:

 - xid of the query was fixed at zero
 - xid from the reply was never checked
 - source address of the reply was never checked

This means anyone can flood the host with a fake reply with xid 0,
guessing the source port is trivial as it's less than 16bits (2^16 -
1024), which would cause odin to resolve a hostname to whatever an
attacker wanted.

While here also plug in two memory leaks.

Since this is CVE material, I've contacted @kelimion before hand which
instructed to put it in a PR.

There are also more bugs as the code conflates answer section,
authority section and aditional section into one, while in reality
only the anwer section should be taken into consideration.
2025-02-23 17:28:32 +01:00
Jeroen van Rijn 940da61869 Fix missing error when TCP connection refused.
Fixes #4867
2025-02-23 12:47:22 +01:00
Jeroen van Rijn 963663b8e1 Merge pull request #4814 from haesbaert/dns-cleanup
Cleanup allocated dns runtime data
2025-02-09 02:12:02 +01:00
Christiano Haesbaert cd53949c92 Cleanup allocated dns runtime data
While harmless, the runtime should clean up non-user allocated data.
On the same veign of: https://github.com/odin-lang/Odin/pull/4680

I'm kinda new to Odin and wrote netcat, in order to get a clean valgrind run,
one has to manually destroy dns_configuration:
https://github.com/haesbaert/learn-odin/blob/main/netcat/netcat.odin#L168-L169

While here unexport the destroy procedure and make destruction idempotent.
2025-02-09 00:26:25 +01:00
Christiano Haesbaert 605527f9db Fix some compression bugs in dns.
- A compression pointer is when the two higher bits are set, the code was
   considering only 0xC0 as a pointer, where in reality anything from 0xC0-0xFF is
   a pointer, probably went unnoticed since you need big packets to have long pointers.
 - Make sure we can access the lower byte of the pointer by checking len, the
   code was careful to not access past the first byte, but ignored the second.
 - As per RFC9267 make sure a pointer only points backwards, this one is not so
   bad, as the code had a iteration_max that ended up guarding against infinite jumps.

Lightly tested, some eyes are welcome, but these are remote DOSable.
2025-02-09 00:00:11 +01:00
Jeroen van Rijn 0683a3d672 Merge pull request #4681 from haesbaert/sockaddr
Add net.dial_tcp_from_host{_or_endpoint} and unify them
2025-02-08 12:45:02 +01:00
Jeroen van Rijn cc29bdaefc Simplify *nix mDNS 2025-01-27 23:04:15 +01:00
Jeroen van Rijn 8998d74a92 Add mDNS for *nix. 2025-01-27 22:55:48 +01:00
Jeroen van Rijn d85c2c1ca7 Add mDNS/Bonjour/Avahi (.local) support for Windows 2025-01-27 22:16:24 +01:00
Christiano Haesbaert 5699c533c6 Add net.dial_tcp_from_host{_or_endpoint} and unify them
The main motivation for this is to have sinergy with flags parsing, currently
flags for a sockaddr returns a net.Host_Or_Endpoint, but we can't just dial
from it since there isn't a variant.

Consider the following:

```
Options :: struct {
	target: net.Host_Or_Endpoint `args:"pos=0,required" usage:"host:port"`,
}

before :: proc() -> (sock: net.TCP_Socket, err: net.Network_Error) {
	opt: Options

	flags.parse_or_exit(&opt, os.args)
	switch t in opt.target {
	case net.Host:
		sock, err = net.dial_tcp(t.hostname, t.port)
	case net.Endpoint:
		sock, err = net.dial_tcp(t)
	}
	return
}

after :: proc() -> (sock: net.TCP_Socket, err: net.Network_Error) {
	opt: Options

	flags.parse_or_exit(&opt, os.args)
	sock, err = net.dial_tcp(opt.target)
	return
}

```

For completion, add dial_tcp_from_host() and define the upper functions in terms
of the newly added ones, cuts one repeated block, now:

from_hostname_and_port_string is parse + from_host_or_endpoint
from_hostname_with_port_override is parse + override + from_host_or_endpoint
from_host is to_endpoint + from_endpoint
from_host_or_endpoint is from_endpoint or from_host
2025-01-12 02:41:35 +01:00
Laytan Laats 5c63617191 net: fix leaking sockets in listen_tcp if an error occurs 2024-10-08 21:08:14 +02:00
Laytan Laats d8af35f01e net: fix leaking sockets in dial_tcp if connect errors 2024-10-08 21:01:57 +02:00
gingerBill 327ca2ab71 Merge pull request #4261 from laytan/net-bound-endpoint
net: add `bound_endpoint` procedure
2024-09-19 12:53:42 +01:00
Laytan Laats 652557bfcd net: add bound_endpoint procedure 2024-09-17 22:22:19 +02:00
Karl Zylinski 3d7b924260 Fix a few incorrectly placed build tags. 2024-09-14 18:41:05 +02:00
Karl Zylinski 19f0127e55 Moved all packages in core, base, vendor, tests and examples to use new #+ file tag syntax. 2024-09-14 18:27:49 +02:00
Laytan Laats 288312a812 core: improve package doc comments for the documentation generator 2024-09-03 19:59:04 +02:00
Jeroen van Rijn 0a825fc44d Improve SRV handling in dns_windows.odin 2024-08-24 18:43:25 +02:00
gingerBill 70932dc478 Merge pull request #4089 from laytan/riscv64
add support for linux_riscv64 and freestanding_riscv64
2024-08-22 11:20:03 +01:00
Laytan 06fb500dfe make sure net.Network_Error is of size 8 2024-08-20 15:52:07 +02:00
Laytan ca6ef95b03 add support for linux_riscv64 and freestanding_riscv64 2024-08-20 14:06:40 +02:00
Jeroen van Rijn cc24d2de3e Merge pull request #3810 from Feoramund/freebsd-core-net
Port `core:net` to FreeBSD
2024-08-09 09:50:05 +02:00
Feoramund 4c0ab09c9a Handle EPIPE in Darwin core:net 2024-08-05 13:15:08 -04:00
Feoramund 6cc7f3b451 Add FreeBSD Accept_Error.Would_Block alias 2024-08-05 13:00:44 -04:00
Feoramund 3512d7c672 Move Darwin MSG_NOSIGNAL to core:os 2024-08-05 12:49:12 -04:00
Feoramund eba0774bf3 Prevent SIGPIPE on Darwin when writing to a closed core:net socket
Mimics behavior found on Linux implementation.
2024-08-05 12:23:09 -04:00
Feoramund fe754af13d Add new contribution notes to core:net 2024-08-05 03:05:49 -04:00
Feoramund 61e770d943 Clean up some FreeBSD core:net code 2024-08-05 03:05:43 -04:00
Feoramund 2b63684ccf Fix integer socket option values for FreeBSD 2024-08-05 02:14:41 -04:00
Feoramund 5ece6980eb Make EINVAL generic in FreeBSD Socket_Option_Error
The documentation for `setsockopt(2)` mentioned accept filters for
`EINVAL`, but I've found that it can arise for any manner of invalid
values for setting socket options.

We'll just have to leave this as a generic error.
2024-08-05 02:14:27 -04:00
Feoramund 8de48d81ea Use common name for ENOBUFS 2024-08-05 00:30:39 -04:00
Feoramund 32fb1fb61c Add missing ECONNRESET TCP_Send_Error
This was not specifically documented in `send(2)`.
2024-08-05 00:30:39 -04:00
Feoramund 05c50561ae Set NOSIGPIPE on all core:net FreeBSD sockets 2024-08-05 00:30:39 -04:00
Feoramund 46455dd0a6 Add more socket options for FreeBSD core:net 2024-08-05 00:30:24 -04:00
gingerBill 66b86bc7e0 Correct os errors for darwin 2024-08-04 12:23:18 +01:00
gingerBill 97c499dbb4 Begin mapping os.Error in the rest of the codebase 2024-08-04 11:58:04 +01:00
flysand7 4dcb75af6d Make all handles non-inheritable by default
The sockets are left as non-inheritable because they
never should be inherited.
2024-07-18 22:50:47 +11:00
Feoramund 8b915aae5e Update code for new -vet 2024-06-30 11:18:40 -04:00
h0mtanks 2b615b09f0 fixed whitespace 2024-06-30 13:47:11 +05:30
h0mtanks d1603ebac4 added missing would_block enum member 2024-06-30 13:42:55 +05:30
gingerBill e296d6fb90 Fix loads of indentation issues with mixing spaces and tabs 2024-06-29 19:50:51 +01:00
gingerBill 103eccf104 More style improvements 2024-06-29 19:23:58 +01:00
gingerBill 5413a8b744 Even more style fixes 2024-06-29 19:11:36 +01:00
gingerBill c88a1bef91 Add another -vet-cast check 2024-06-29 12:40:04 +01:00
Feoramund e61d893a74 Port core:net to FreeBSD 2024-06-26 10:05:24 -04:00
gingerBill f9fd8f0c25 Merge pull request #3439 from andreas-jonsson/netbsd
NetBSD support
2024-05-15 10:33:52 +01:00
gingerBill 6dc0ee3877 Fix #3577 2024-05-13 12:54:01 +01:00
Andreas T Jonsson 9a008d10f3 Merge branch 'master' into netbsd 2024-04-25 22:04:40 +02:00
Rickard Andersson 68f663ea85 fix(net): fix return type for send_tcp
Was `.Connection_Closed` but this is only inferrable if our return type
is not a sub-union of another.
2024-04-19 15:39:04 +03:00
Rickard Andersson efc84cd390 docs(net): add comment about EPIPE -> Connection_Closed 2024-04-19 15:37:20 +03:00