Commit graph

1950 commits

Author SHA1 Message Date
Leonid Evdokimov
0749d81343 pf tests: check cleared time when zeroing stats for table addresses
Verify that we reset the cleared time when we zero an address' counters in
a table.

PR:		282877, 282984
Reviewed by:	kp
MFC after:	2 weeks
Signed-off-by:	Leonid Evdokimov <leon@darkk.net.ru>
Differential Revision:	https://reviews.freebsd.org/D48242
2025-01-02 13:34:50 +01:00
Alan Somers
3f83f32d7d fusefs: minor refactor in the tests
Do more work in MockFS's constructor's member initializer list, instead
of the body of the constructor.  It's easier to read this way.

Sponsored by:	ConnectWise
2024-12-24 14:55:48 -07:00
Alan Somers
969d1aa4db fusefs: fix a memory leak
Fix a leak of a fuse_ticket structure.  The leak mostly affected
NFS-exported fuse file systems, and was triggered by a failure during
FUSE_LOOKUP.

MFC after:	2 weeks
Sponsored by:	ConnectWise
2024-12-23 13:37:19 -07:00
Mark Johnston
c9756953bd inpcb: Further restrict binding to a port owned by a different UID
See commit 4f02a7d739 for more background.

I cannot see a good reason to continue ignoring mismatching UIDs when
binding to INADDR_ANY.  Looking at the sdr.V2.4a7n sources (mentioned in
bugzilla PR 7713), there is a CANT_MCAST_BIND hack wherein the
application binds to INADDR_ANY instead of a multicast address, but
CANT_MCAST_BIND isn't defined for FreeBSD builds.

It seems unlikely that we still have a use-case for allowing sockets
from different UIDs to bind to the same port when binding to the
unspecified address.  And, as noted in D47832, applications like sdr
would have been broken by the inverted SO_REUSEPORT check removed in
that revision, apparently without any bug reports.  Let's break
compatibility and simply disallow this case outright.

Also, add some comments, remove a hack in a regression test which tests
this funtionality, and add a new regression test to exercise the
remaining checks that were added in commit 4658dc8325.

MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47870
2024-12-23 15:41:06 +00:00
CismonX
f0f596bd95 fusefs: ignore FUSE_NO_OPEN(DIR)_SUPPORT flags
The FUSE_NO_OPEN_SUPPORT and FUSE_NO_OPENDIR_SUPPORT flags
are only meant to indicate kernel features, and should be ignored
if they appear in the FUSE_INIT reply flags.

Also fix the corresponding test cases.

MFC after:	2 weeks
Reviewed by:	Alan Somers <asomers@FreeBSD.org>
Signed-off-by:	CismonX <admin@cismon.net>
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1509
2024-12-19 17:09:49 -07:00
Gleb Smirnoff
ff7e00eb4d tests: remove reference to renamed test
Fixes:	ae5c3dfd3e
2024-12-18 10:38:10 -08:00
Alan Somers
53f73aaffd fusefs: delete a comment in the tests
Even on a riscv embedded system, the fusefs tests run fast enough that
10 seconds is a reasonable timeout.

[skip ci]

MFC after:	2 weeks
Sponsored by:	ConnectWise
2024-12-18 11:24:03 -07:00
Alan Somers
b187997579 fusefs: More accurately test the unique tokens in the test suite
Every fuse ticket has a "unique" token.  As the name implies, they're
supposed to be unique.  Previously the fusefs test suite verified their
uniqueness by relying on the fact that they are also sequential.  But
they aren't guaranteed to be sequential.  Enhance the tests by removing
that convenient assumption.

MFC after:	2 weeks
Sponsored by:	Axcient
2024-12-18 09:21:35 -07:00
Kristof Provost
5d1219378d pf: teach nat64 to handle 0 UDP checksums
For IPv4 it's valid for a UDP checksum to be 0 (i.e. no checksum). This isn't
the case for IPv6, so if we translate a UDP packet from IPv4 to IPv6 we need to
ensure that the checksum is calculated.

Add a test case to verify this. Rework the server jail so it can listen for TCP
and UDP packets at the same time.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:19 +01:00
Kristof Provost
32cac60448 pf tests: test dummynet on nat64 rules
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
7f3d159b9f pf tests: test using an address range inside a table for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
bdb583afa1 pf tests: test address range as nat64 from address
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:18 +01:00
Kristof Provost
e0dcc51ddb pfctl: do not allow af-to tables without round-robin
Tables can only be used as a redirspec (i.e. in pf_map_addr()) in round-robin mode.
Enforce this for af-to tables as well.

Add a test case to verify.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
b0e3fb7e65 pf: fix nat64 round-robin addresses from a table
We do multiple lookups during the nat64 process, some of which will fail due
to address family mismatches. Do not reset the lookup offset so we actually use
different addresses from the table.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
9e039875cb pf tests: verify pool use for nat64
Verify that if we provide a pool of addresses we use the entire pool.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
125e395278 pf tests: test not having an IPv4 address to nat64 to
This isn't expected to work, for obvious reasons, but we also expect to not
panic doing this. Exercise this special case.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
27fca15016 pf tests: validate ToS translation with nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-17 11:07:17 +01:00
Kristof Provost
e128e988a2 pf tests: check packet reassembly with nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47805
2024-12-17 11:07:16 +01:00
Kristof Provost
b717c67686 pf tests: verify that we preserve the hop limit/TTL for ICMP errors
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47802
2024-12-17 11:07:16 +01:00
Kristof Provost
c6210cfd58 pf: fix if-bound with nat64
Just as with reply-to rules we don't know what interface we will send this out
of until we create the state. Create new nat64 rules as floating, but bind them
to the appropriate interface on the first pf_route(), when we do know.

Set state policy if-bound for the nat64 tests to validate this.

See also:	6460322a0
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47801
2024-12-17 11:07:16 +01:00
Kristof Provost
373d6dbf34 pf tests: verify that ICMP destination unreachable makes it through NAT64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47798
2024-12-17 11:07:15 +01:00
Kristof Provost
bc66cb3bfa pf tests: verify that ICMP port unreachable makes it through NAT64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47797
2024-12-17 11:07:15 +01:00
Kristof Provost
a4e0403295 pf tests: verify that TCP RST makes it through NAT64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47796
2024-12-17 11:07:15 +01:00
Kristof Provost
a43589dcbf pf tests: add an SCTP test case for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47794
2024-12-17 11:07:14 +01:00
Kristof Provost
7e309356b0 pf tests: add a UDP test case for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47793
2024-12-17 11:07:14 +01:00
Kristof Provost
22c634905b pf tests: add a TCP test case for nat64
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47792
2024-12-17 11:07:14 +01:00
Kristof Provost
0656a68056 pf tests: basic nat64 test case
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47791
2024-12-17 11:07:14 +01:00
Kyle Evans
1a2a0db0a9 tests: kern: improve logsigexit test
Use dmesg(8) instead rather than relying on a particular syslogd
configuration, and just skip the test if we can't access the msgbuf.

While we're here, remove some debugging output that we don't actually
need.
2024-12-14 22:40:15 -06:00
Kyle Evans
9647bf2423 tests: kern: add some tests for recently added logsigexit
We don't bother tweaking the sysctl in these tests, we'll just try with
it forced both on and off via proccontrol(1).  This could be problematic
in the face of pid wrapping if we got really unfortunate, but the
potential solutions need careful consideration- you probably don't want
to assume a certain velocity of messages into syslog, so just checking
the last N lines is probably similarly flakey.
2024-12-13 23:18:31 -06:00
Mark Johnston
4f02a7d739 inpcb: Remove bogus SO_REUSEPORT(_LB) checks in in_pcbbind()
This check for SO_REUSEPORT was added way back in commit 52b65dbe85.
Per the commit log, this commit restricted this port-stealing check to
unicast addresses, and then only if the existing socket does not have
SO_REUSEPORT set.  In other words, if there exists a socket bound to
INADDR_ANY, and we bind a socket to INADDR_ANY with the same port, then
the two sockets need not be owned by the same user if the existing
socket has SO_REUSEPORT set.

This is a surprising semantic; bugzilla PR 7713 gives some additional
context.  That PR makes a case for the behaviour described above when
binding to a multicast address.  But, the SO_REUSEPORT check is only
applied when binding to a non-multicast address, so it doesn't really
make sense.  In the PR the committer notes that "unicast applications
don't set SO_REUSEPORT", which makes some sense, but also refers to
"multicast applications that bind to INADDR_ANY", which sounds a bit
suspicious.

OpenBSD performs the multicast check, but not the SO_REUSEPORT check.
DragonflyBSD removed the SO_REUSEPORT (and INADDR_ANY) checks back in
2014 (commit 0323d5fde12a4).  NetBSD explicitly copied our logic and
still has it.

The plot thickens: 20 years later, SO_REUSEPORT_LB was ported from
DragonflyBSD: this option provides similar semantics to SO_REUSEPORT,
but for unicast addresses it causes incoming connections/datagrams to be
distributed among all sockets in the group.  This commit (1a43cff92a)
inverted the check for SO_REUSEPORT while adding one for
SO_REUSEPORT_LB; this appears to have been inadvertent.  However:
- apparently no one has noticed that the semantics were changed;
- sockets belonging to different users can now be bound to the same port
  so long as they belong to a single lbgroup bound to INADDR_ANY, which
  is not correct.

Simply remove the SO_REUSEPORT(_LB) checks, as their original
justification was dubious and their current implementation is wrong; add
some tests.

Reviewed by:	glebius
MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47832
2024-12-12 14:25:15 +00:00
Leonid Evdokimov
5b59b0c61e pfctl: add -T reset to touch pfras_tzero only for non-zero entries
This will make it easier for scripts to detect idle hosts in tables.

PR:		282984
Reviewed by:	kp
MFC after:	2 weeks
2024-12-09 10:36:34 +01:00
Kajetan Staszkiewicz
ad6562ec85 pf: Don't pfsync states with unrecoverable routing information
States created by route-to rules can't be trusted when received with
pfsync version 1301 as they lack the rt and rt_kif information. They
are imported, though, and pf_route() function attempts to recover
the missing information for every forwarded packet.

Move the recovery operation to pfsync_state_import() so that it's
performed only once and if it's impossible don't import the state.
Add an additional check for cases when recovery might produce wrong
results.

Reviewed by:		kp
Approved by:		kp (mentor)
Sponsored by:		InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D47906
2024-12-05 23:03:12 +01:00
Damjan Jovanovic
61bf830cbb libalias: Add support for EIM NAT
Add support for endpoint-independent mapping ("full cone NAT") in
Libalias's UDP NAT.

This conforms to RFC 4787 requirements 1 and 3. All UDP packets sent out from a
particular internal address:port leave via the same NAT address:port,
regardless of their destination.

Add some libalias tests and supporting defines.

Reviewed by:    igoro, thj
Differential Revision:  https://reviews.freebsd.org/D46689D
2024-12-05 16:19:13 +00:00
Kristof Provost
c22c987984 pf: fix potential NULL dereference in SCTP multihome handling
When processing an SCTP ASCONF we re-run the rules processing to check
if the new state should be allowed as well. We used to do so against the
'all' interface, to allow new connections to use any interface.

This is problematic for two reasons, the first being it may unexpectedly
bypass interface restrictions. The more important one is that it
can trigger panics. If the ruleset contains a rule which filters on
interface group we'd attempt to process the group list for the 'all'
interface. As this isn't a real interface it doesn't have an associated
struct ifnet, and we end up dereferencing a NULL pointer.

Solve this by not overriding the interface, instead leaving the physical
interface the SCTP ASCONF arrived on. This implies that we may end up
binding to that interface (if if-bound), and thus denying traffic on
other interfaces. Users can allow this anyway by setting 'state-policy
floating' on the relevant SCTP rules. This arguably better reflects user
intent as well. That is, we'll consider SCTP multihomed states to be
floating if we're in floating mode, and if-bound if we're if-bound.

Update the test cases to account for this, while adding a "pass on
lo" (i.e. pass on an interface group") rule to provoke this issue. Add
separate test cases for the floating and if-bound scenarios.

Reported by:	Franco Fichtner <franco@opnsense.org>
MFC after:	3 weeks
Sponsored by:	Orange Business Services
2024-12-03 19:27:49 +01:00
Mark Johnston
e090646d6f ndp tests: Update to chase commit 9206c79961
"netstat -rn" no longer prints the default route using symbol names, but
the test relied on it.  Update it to look for ::/0 instead.

MFC after:	1 week
Fixes:	9206c79961 ("usr.bin/netstat: -n should not print symbolic names")
2024-11-29 17:01:33 +00:00
Kajetan Staszkiewicz
b9c0321d54 pf: Fix source node locking
Source nodes are created quite early in pf_create_state(), even before
the state is allocated, locked and inserted into its hash row. They are
prone to being freed by source node killing or clearing ioctl while
pf_create_state() is still running.

The function pf_map_addr_sn() can be called in two very different paths.

One is for filter rules where it is called from
pf_create_state() after pf_insert_src_node(). In this case it is called
with a given source node and does not perform its own search and must
return the source node.

The other one is for NAT rules where it is called from
pf_get_translation() or its descendants. In this case it is called with
no known source node and performs its own search for source nodes. This
source node is then passed back to pf_create_state() without locking.

The states property of source node is increased in pf_find_src_node()
which allows for the counter to increase when a packet matches the NAT
rule but not a pass keep state rule.

The function pf_map_addr() operates on unlocked source node.

Modify pf_find_src_node() to return locked on source node found, so
that any subsequent operations can access the source node safely.

Move sn->states++ counter increase to pf_insert_src_node() to ensure
that it's called only from pf_create_state() and not from NAT ruleset
path, and have it increased only if the source node has really been
inserted or found, simplifying the cleanup.

Add locking in pf_src_connlimit() and pf_map_addr(). Sprinkle mutex
assertions in pf_map_addr().

Add a function pf_src_node_exists() to check a known source node is
still valid. Use it in pf_create_state() where it's impossible to hold
locks from pf_insert_src_node() because that would cause LoR (nodes
first, then state) against pf_src_connlimit() (state first, then node).

Don't propagate the source node found while parsing the NAT ruleset to
pf_create_state() because it must be found again and locked or created.

Reviewed by:		kp
Approved by:		kp (mentor)
Sponsored by:		InnoGames GmbH
Differential Revision:	https://reviews.freebsd.org/D47770
2024-11-28 18:31:55 +01:00
Dag-Erling Smørgrav
6748d4e0eb tests: Add regression test for ppoll() / pselect() race.
These tests demonstrate the bug that was fixed in ccb973da1f.

Sponsored by:	Klara, Inc.
Sponsored by:	NetApp, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D47738
2024-11-26 21:36:09 +01:00
Kristof Provost
56b7685ae3 pf: handle IPv6 fragmentation for route-to
If a fragmented IPv6 packet hits a route-to rule we have to first prevent
the pf_test(PF_OUT) check in pf_route6() from refragmenting (and calling
ip6_output()/ip6_forward()). We then have to refragment in pf_route6() and
transmit the packets on the route-to interface.

Split pf_refragment6() into two parts, the first to perform the refragmentation,
the second to call ip6_output()/ip6_forward() and call the former from
pf_route6().

Add a test case for route-to-ing fragmented IPv6 packets to verify this works
as expected.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47684
2024-11-26 15:06:52 +01:00
Kristof Provost
a46c121db4 netpfil tests: make dummynet tests more robust
These tests try to verify that packet prioritisation works as expected. This is
inherently a statistical process, and is difficuly to measure automatically.
Run the tests more times and accept more failures.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-11-24 09:34:09 +01:00
Kristof Provost
6463b6b591 pfctl: clear statistic for specified addresses
The ioctl DIOCRCLRASTATS provides the functionality of clearing stats
not only for the whole table for for addresses stored in that table. The
functionality was missing from pfctl, though. Add it now.

PR:		282877
Obtained from:	OpenBSD, kirill <kirill@openbsd.org>, e496dff3a7
MFC after:	3 weeks
2024-11-22 12:22:16 +01:00
Mark Johnston
a079f2b52a fibs_test: Run in a jail
These tests assume exclusive use of one or more FIBs and so can't be run
in parallel.  Running them in a VNET jail sidesteps this problem.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
2024-11-21 18:54:59 +00:00
Kristof Provost
e27970ae8f netinet: handle blackhole routes
If during ip_forward() we find a blackhole (or reject) route we should stop
processing and count this in the 'cantforward' counter, just like we already do
for IPv6.
Blackhole routes are set to use the loopback interface, so we don't actually
incorrectly forward traffic, but we do fail to count it as unroutable.

Test this, both for IPv4 and IPv6.

Reviewed by:	melifaro
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47529
2024-11-20 16:52:41 +01:00
Kristof Provost
5eee34fa03 pf tests: check counters on anchors
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-11-18 18:57:53 +01:00
Franco Fichtner
3b337076ba pf: remove stale no_df tests from fragemtation_*.sh
compat: test case add was previously removed but not the test itself
pass: test was added twice

Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D47535
2024-11-13 10:34:08 +01:00
Kajetan Staszkiewicz
65b2077171 pf tests: Simplify handling of pfctl -s
Some pf tests check the output of pfctl -s[sSr] to find if relevant
states, source nodes or rules exist and if their counters have proper
values. The output is multiple lines per entry and contains varying
amount of whitespace. This makes parsing it rather hard.

Provide a function for standardization of output of pfctl -s[sSr] which
converts the output to a single line per entry and reduces whitespace
always to a single space. Adjust existing tests to make use of this
function.

Revieved by:		kp
Approved by:		kp (mentor)
Differental Revision:	https://reviews.freebsd.org/D47435
2024-11-12 18:17:12 +01:00
Kristof Provost
609fa228ba pft_ping: improve IPv6 address comparison
Don't use string comparisons, use socket.inet_pton() instead. This avoids
confusion when there are different ways to spell the same IP addres.
e.g. 64:ff9b::c000:202 and 64:ff9b::192.0.2.2 are two representations of the same
address.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-11-06 19:02:04 +01:00
Kristof Provost
a4e64fcd68 pf tests: test kill and clear source nodes paths
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-11-06 19:02:03 +01:00
Alan Somers
b032be711c Make the CTL tests more resilient
Fix the find_device function to work regardless of whether "camcontrol
devlist" lists the da device first and the pass device second or vice
versa.  On FreeBSD 14 and 15 it apparently always lists da first.  But
on 13 it can do it in either order.

MFC after:	2 weeks
MFC with:	fe1755fa
Sponsored by:	ConnectWise
Reviewed by:	emaste, markj, #cam
Differential Revision: https://reviews.freebsd.org/D47446
2024-11-04 19:06:53 -07:00
Mark Johnston
bfd03046d1 unix: Add support for atomically setting the socket mode
With this patch, it is possible to call fchmod() on a unix socket prior
to binding it to the filesystem namespace, so that the mode is set
atomically.  Without this, one has to call chmod() after bind(), leaving
a window where threads can connect to the socket with the default mode.
After bind(), fchmod() reverts to failing with EINVAL.

This interface is copied from Linux.

The behaviour of fstat() is unmodified, i.e., it continues to return the
mode as set by soo_stat().

PR:		282393
Reviewed by:	kib
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D47361
2024-11-03 16:46:53 +00:00
Igor Ostapenko
2cb39df0a1 tests: Switch sys/kern/sysctl_security_jail_children to execenv=jail
Kyua skips tests based on the jail execution environment if a system is
built WITHOUT_JAIL. Thus, the test case does not need to handle it.

Reviewed by:	markj
Approved by:	markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D47105
2024-10-29 21:28:02 +00:00