OPNSense/src 1633399 — sys/dev/ice ice_lib.c

Revert "ice(4): Fix link speed after changing cable type"

This reverts commit 27ffeba0e6b5b8d8ebb8eec9d2566f56421ee946.

PR: https://forum.opnsense.org/index.php?topic=52405.msg276938#msg276938
DeltaFile
+7-11sys/dev/ice/ice_lib.c
+7-111 files

OPNSense/src 68b64bb — sys/net pfil.c

pfil: Avoid potential mbuf tag leak

In '398254f9999e mbuf: simplify m_free' we removed tag processing
on m_free() of M_NOFREE mbufs. It is possible that a packet filter
could attach a tag to this stack mbuf and call m_free()
on it, meaning that 398254f9999e may have introduced a tag leak.

However,if a tag is attached without anyone calling m_free(), then
this leak was pre-existing.

Reviewed by: glebius
Differential Revision: https://reviews.freebsd.org/D60686
Fixes: 398254f9999e
Sponsored by: Netflix

(cherry picked from commit f4ff995e361fa72cea240c4dbac2d0931965c80f)
DeltaFile
+2-0sys/net/pfil.c
+2-01 files

OPNSense/src 717cbf3 — sys/netinet igmp.c

igmp: Refresh the ip header pointer after m_pullup()

There is a chance that the m_pullup() call immediately above invalidated
the "ip" pointer, so refresh it as we do with the IGMP header.
Otherwise the test in igmp_input_v3_query() for whether the packet is an
IGMPv3 general query might use a pointer to a freed mbuf.

MFC after:      1 week
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit dc47a6940d60d393b3d36ba0fc5cb84d06fafaea)
DeltaFile
+1-0sys/netinet/igmp.c
+1-01 files

OPNSense/src 6738896 — sys/netinet igmp.c

igmp: Deindent some code

No functional change intended.

MFC after:      1 week
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit 123342f3d2cccf432d3d0082097b6c97397ecc67)
DeltaFile
+32-33sys/netinet/igmp.c
+32-331 files

OPNSense/src cf3f8e3 — sys/netinet ip_carp.c, tests/sys/netinet carp.sh

carp: fix global demotion counter to VRRP advertisements

When net.inet.carp.preempt=1 and a physical interface goes down, the global
V_carp_demotion counter is incremented. For CARP this was already reflected in
outgoing advertisements via DEMOTE_ADVSKEW(), but VRRP sent the raw
sc_vrrp_prio unchanged, so demotion had no effect.

Add DEMOTE_VRRP_PRIO(), a macro analogous to DEMOTE_ADVSKEW():
It subtracts V_carp_demotion from the configured priority and clamps the result
to [0, 254]. Priority 0 is VRRPv3's "resign" signal and causes backups to
preempt immediately. Priority 255 (IP address owner) is never demoted.

Reviewed by:    kp
Approved by:    kp
Sponsored by:   Netflix
Differential Revision:  https://reviews.freebsd.org/D55558

(cherry picked from commit 9f71153aec0cb455cd49af6d4ca7e4c16fd45d7a)
DeltaFile
+61-0tests/sys/netinet/carp.sh
+14-3sys/netinet/ip_carp.c
+75-32 files

OPNSense/src 54820bb — sys/netinet sctp_output.c

sctp: initialize inp to avoid uninitialized use

If we take an early goto out_unlocked inp is uninitialized and then
may be used in SCTP_LTRACE_ERR_RET().  Initialize inp to NULL
to avoid warnings.

Found with:     gcc15 tinderbox build
Reviewed by:    tuexen, pouria
Differential Revision: https://reviews.freebsd.org/D56503

(cherry picked from commit 4cdbcc2b6a2e551529f7133665ef406869b48bf7)
DeltaFile
+1-0sys/netinet/sctp_output.c
+1-01 files

OPNSense/src 989cc33 — sys/netinet6 in6_src.c

netinet6: Fix check for pktinfo outgoing ifindex in route cache

lookup_route is only called for outgoing traffic, therefore
check nh_ifp index instead of nh_aifp as specified by RFC3542 sec 6.

Differential Revision: https://reviews.freebsd.org/D58544

(cherry picked from commit 7753a59fdf196fcbd8bb5706ad44bfc590bce0a9)
DeltaFile
+1-1sys/netinet6/in6_src.c
+1-11 files

OPNSense/src 00c1838 — sys/net iflib.c

iflib: Do not ring the transmit doorbell when nothing is pending

For a lightly used ring iflib_txd_db_check() may defer zero descriptors,
so its "pending >= limit" test is true even when nothing has been queued
since the last doorbell.  iflib_txq_drain() calls it before, inside and
after its loop, so a sender that drains its own packet wrote the tail
register three times per packet, twice with the value the hardware
already had.

The log of 81be655266fa ("iflib: ensure that tx interrupts enabled and
cleanups") calls skipping the doorbell when db_pending is zero "an
obvious missing optimization"; the comparison against a limit of zero
defeated it.  vmx(4) and mgb(4) have dropped such repeated requests in
the driver since 2019.  Return early when nothing is pending.

Reviewed by:            gallatin
MFC after:              2 weeks
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60290

    [2 lines not shown]
DeltaFile
+7-0sys/net/iflib.c
+7-01 files

OPNSense/src f4fddfa — sys/netlink netlink_message_parser.h

netlink: fix unsigned overflow on a truncated message

PR:                     295106
Submitted by:           Robert Morris <rtm at lcs.mit.edu>
Reviewed by:            pouria, melifaro
Differential Revision:  https://reviews.freebsd.org/D56916

(cherry picked from commit e924a2c80b9e1ace68d8ca0ffdacec65feec90a3)
DeltaFile
+6-0sys/netlink/netlink_message_parser.h
+6-01 files

OPNSense/src 8015491 — sys/netpfil/ipfw/nat64 nat64lsn.c

nat64lsn: Fix type confusion panic when using wrong NAT64 instance type

When an ipfw rule references a NAT64 instance by name using
'nat64lsn', the kernel looks up the instance in the shared
srvstate[] array without verifying the instance type.
If the named instance is actually a nat64clat or nat64stl
instance (created with 'nat64clat' or 'nat64stl'), the code
incorrectly casts the instance to nat64lsn_instance and
dereferences the ->cfg pointer, which causes a kernel panic.

The root cause is that all NAT64 instance types share the same
srvstate[] array but have different struct layouts.
For nat64lsn_instance, the field after 'no' is a pointer to nat64lsn_cfg.
For nat64clat_cfg, the same offset contains an embedded nat64_config struct.

Fix by adding a type check after NAT64_LOOKUP() to verify that the
instance's etlv matches IPFW_TLV_NAT64LSN_NAME before proceeding.
If the type doesn't match, return IP_FW_DENY to reject the packet
safely rather than crashing.

    [8 lines not shown]
DeltaFile
+2-1sys/netpfil/ipfw/nat64/nat64lsn.c
+2-11 files

OPNSense/src 829ea4e — sys/netpfil/ipfw/nat64 nat64stl.c nat64clat.c

ipfw/nat64: Fix type confusion panic when using wrong NAT64 instance type

Add etlv type validation to ipfw_nat64clat() and ipfw_nat64stl() to
verify that the retrieved instance is actually a nat64clat instance
before use.

All NAT64 instance types share the same srvstate[] array but have
different struct layouts.
Without type validation, using the wrong instance type with
a handler causes type confusion and kernel panic.

Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>
PR:             292023
Reviewed by:    pouria
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2259

(cherry picked from commit 2e6b22abf44d99b84abf17fe25ca2e8f89716c04)
DeltaFile
+2-1sys/netpfil/ipfw/nat64/nat64stl.c
+2-1sys/netpfil/ipfw/nat64/nat64clat.c
+4-22 files

OPNSense/src 2a3cdb7 — sys/netpfil/pf pf.c

pf: leave the epoch to purge unlinked rules

pf_purge_thread() calls pf_purge_unlinked_rules() in the network
epoch, where sleeping is not allowed, and it takes pf_config_lock, an
sx lock. If a rule is being added at the time, the purge thread
can sleep on the lock, which panics with INVARIANTS.

Reviewed by:            kp
Approved by:            kp (mentor)
Fixes:                  f92d9b1aad73 ("pflow: import from OpenBSD")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60160

(cherry picked from commit 82ab4adec95578b196eaf431d6ca87dd209aca6b)
DeltaFile
+6-0sys/netpfil/pf/pf.c
+6-01 files

OPNSense/src 7da85a4 — sys/netpfil/pf pf.c

pf: Drain the overload task before a vnet's rules are freed

pf_src_connlimit() queues an entry for pf_overload_task() when a
source exceeds max-src-conn or max-src-conn-rate and the rule has an
overload table.  The entry holds a pointer to the rule, and the task
runs from taskqueue_swi with the vnet of the queue.  Nothing drained
the task when the vnet went away: an entry queued just before could
be applied to a rule pf_unload_vnet_purge() had freed, or to a vnet
that was gone.

Drain the task at the start of pf_unload_vnet_purge(), before the
unlinked rules are freed.  No packet can queue another by then, as the
hooks are already removed.

Reviewed by:            kp
MFC after:              2 weeks
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60529

(cherry picked from commit 92d66a6b474fa6fe42fbe08002803d79a5af6594)
DeltaFile
+3-0sys/netpfil/pf/pf.c
+3-01 files

OPNSense/src 3eb67be — sys/netpfil/pf pf.c

pf: check extension header length.

pf_walk_header6() advances the packet offset for each IPv6 extension
header.  It was not checked that this does not exceed the packet
length if no next header was processed.  When used with af-to rules,
this could trigger a panic: m_copydata: null mbuf.

from Acts1631; OK henning@ sashan@

MFC after:      1 week
Obtained from:  OpenBSD, bluhm <bluhm at openbsd.org>, 6d56112588
Sponsored by:   Rubicon Communications, LLC ("Netgate")

(cherry picked from commit ccb19b359aae4b7e7315ad61d33d9a35d85849d1)
DeltaFile
+14-3sys/netpfil/pf/pf.c
+14-31 files

OPNSense/src 1c20525 — sys/netpfil/pf pf.c

pf: check AH header length.

pf_walk_header() advances the packet offset for each AH extension
header.  It was not checked that this does not exceed the packet
length if no next header was processed.  Fix it like in IPv6.

OK henning@ sashan@

MFC after:      1 week
Obtained from:  OpenBSD, bluhm <bluhm at openbsd.org>, fcd4e5522e
Sponsored by:   Rubicon Communications, LLC ("Netgate")

(cherry picked from commit b4d2c9835c0edfddd1d6742afa86d4873ccfad16)
DeltaFile
+11-2sys/netpfil/pf/pf.c
+11-21 files

OPNSense/src 86a0697 — sys/netpfil/pf pf_if.c pf.c

pf: modify pfik_flags atomically

The purge thread sets PFI_IFLAG_REFS on the interfaces that states
refer to without the rules lock, under which the other flags are
changed. The updates can interleave, so that a "set skip on" is lost,
or outlives its removal, until the next ruleset load.

Use atomic operations to modify the flags. In the purge thread, only
write if the flag is not already set.

Reviewed by:            kp
Approved by:            kp (mentor)
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60107

(cherry picked from commit c1241c6e30c792fb514f4689d2ed92ee21d3cf39)
DeltaFile
+10-2sys/netpfil/pf/pf.c
+5-5sys/netpfil/pf/pf_if.c
+15-72 files

OPNSense/src 6658853 — sys/netpfil/pf pf_ioctl.c

pf: Set the reassembly flags under the rules lock

DIOCSETREASS stored V_pf_status.reass twice with no lock, first the
flags it was given and then, if reassembly was not among them, zero.
pf_normalize_ip() and pf_normalize_ip6() read the flags with the rules
lock held for reading, so a packet could see the intermediate value.
Compute the flags first and store them once, with the rules lock held
for writing, as DIOCSETDEBUG and DIOCSETHOSTID do.

Reviewed by:            kp
Fixes:                  39282ef356db ("pf: backport OpenBSD syntax of "scrub" option for "match" and "pass" rules")
MFC after:              2 weeks
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60531

(cherry picked from commit b951994eddd4d274514df751da06680a32139037)
DeltaFile
+7-3sys/netpfil/pf/pf_ioctl.c
+7-31 files

OPNSense/src 06566a3 — sys/netpfil/pf pf_ioctl.c

pf: free the packet rate counter of a rule

pf_ioctl_addrule() allocates a counter_rate for every rule, whether it
has a max-pkt-rate or not, and pf_krule_free() never frees it.

Free it with the rest of the rule.

Reviewed by:            kp
Approved by:            kp (mentor)
Fixes:                  ff11f1c8c76c ("pf: add a generic packet rate matching filter")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60190

(cherry picked from commit 2fa4ef491608aad827f8ceef3eb389d8c07451fb)
DeltaFile
+1-0sys/netpfil/pf/pf_ioctl.c
+1-01 files

OPNSense/src 8d64472 — sys/netpfil/pf if_pfsync.c

pfsync: use result of m_pullup()

(cherry picked from commit f84cdc2584305f8b656ce3f3746868c4a58a9a82)
DeltaFile
+2-2sys/netpfil/pf/if_pfsync.c
+2-21 files

OPNSense/src c31c4f1 — sys/netpfil/pf pf_lb.c, tests/sys/netpfil/pf nat.sh

pf: first-match-wins for nat rules, even in anchors

Ensure we stop evaluating nat rules if we find a match in a nat-anchor.

PR:             299320
MFC after:      1 week
Sponsored by:   Rubicon Communications, LLC ("Netgate")

(cherry picked from commit b5219c068fbc133dde91d5cf48423e34ce27bd4f)
DeltaFile
+91-0tests/sys/netpfil/pf/nat.sh
+5-0sys/netpfil/pf/pf_lb.c
+96-02 files

OPNSense/src 347fe3f — sys/netpfil/pf pf_ioctl.c

pf: Register the netlink family only while the vnets are set up

pf_modevent() registers the generic netlink family at MOD_LOAD, before
vnet_pf_init() has set up the state hashes and locks the handlers use,
and pf_unload() unregisters it after vnet_pf_uninit() has torn them
down.  Sending PFNL_CMD_GETSTATES while pf loads or unloads panics in
pf_handle_getstates() on a NULL or freed V_pf_idhash.

Register the family from a SYSINIT ordered after vnet_pf_init(), and
unregister it from the matching SYSUNINIT, before vnet_pf_uninit().

Reviewed by:            kp
Fixes:                  2cef62886dc7 ("pf: convert state retrieval to netlink")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60651

(cherry picked from commit 68831d2a2cbb34e8daf24db7e4e15b8c09451f85)
DeltaFile
+20-3sys/netpfil/pf/pf_ioctl.c
+20-31 files

OPNSense/src 7885998 — sys/netpfil/pf pf_nl.c

pf: free an unparsed rule with pf_krule_free() in pf_handle_addrule()

When the PFNL_CMD_ADDRULE message fails to parse, pf_handle_addrule()
frees the rule with pf_free_rule(), which asserts the rules and config
locks (neither is held) and releases references that
pf_ioctl_addrule() has not taken yet. With INVARIANTS this panics on
any parse error; without, a rule address parsed as PF_ADDR_TABLE makes
pfr_detach_table() dereference NULL.

Use pf_krule_free(), as the ioctl paths do.

Reviewed by:            kp
Approved by:            kp (mentor)
Fixes:                  e249f5daa41f ("pf: fix memory leak on rule add parse failure")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60104

(cherry picked from commit be7e57fbf9729abdc14c9cb37a127c6a3fa95e27)
DeltaFile
+1-1sys/netpfil/pf/pf_nl.c
+1-11 files

OPNSense/src 646759e — sys/netpfil/pf pf_nl.c

pf: do not leak a source hash row lock in the netlink dump

pf_handle_get_srcnodes() returns with the lock of a source hash row
held when it cannot start the message for a source node.  Unlock the
row there, as the other error exit of the loop does.

Reviewed by:            kp
Approved by:            kp (mentor)
Fixes:                  9c125336727b ("pf: convert DIOCGETSRCNODES to netlink")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60251

(cherry picked from commit 782c6ea08603a4839c2c099842df92b6159b799f)
DeltaFile
+1-0sys/netpfil/pf/pf_nl.c
+1-01 files

OPNSense/src 2094cf0 — sys/netpfil/pf pf_nl.c

pf: take the rules read lock in pf_handle_getrule()

pfctl -sr calls PFNL_CMD_GETRULE once per rule, and
pf_handle_getrule() takes the rules write lock each time, so listing a
ruleset of N rules stops packet processing N times. Only zeroing the
counters (pfctl -z) needs the write lock. Take the read lock
otherwise, as DIOCGETRULENV does.

Reviewed by:            kp
Approved by:            kp (mentor)
Fixes:                  777a4702c591 ("pf: implement addrule via netlink")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60161

(cherry picked from commit 6d7f0162bd5d25919cc18119a6e5a371acb2cf78)
DeltaFile
+20-6sys/netpfil/pf/pf_nl.c
+20-61 files

OPNSense/src c2e1604 — sys/netpfil/pf pf_table.c

pf: Free a table entry that cannot be routed

pfr_insert_kentry() returned the error of pfr_route_kentry() and
leaked the entry it had created; pfr_insert_kentries() stopped at the
first entry it could not route and leaked it and the rest of the work
queue, which no caller frees.  Destroy an entry that cannot be routed
and go on with the next.

Reviewed by:            kp
MFC after:              2 weeks
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60532

(cherry picked from commit 989d72fd3d35daa6a056afdd0c6b0aba4c5d8ccf)
DeltaFile
+7-4sys/netpfil/pf/pf_table.c
+7-41 files

OPNSense/src 9662589 — sys/netpfil/pf pflow.c

pflow: Destroy exporters on module unload

Since 83641335f96c only jail removal destroys exporters.  Unloading
pflow with one left trips the assertion in vnet_pflowdetach() or,
without INVARIANTS, leaves pf calling into the freed module the next
time it removes a state that pflow exports.

Reviewed by:    kp
Fixes:          83641335f96c ("pf: clean up pflow sockets on jail removal")
MFC after:      1 week
Sponsored by:   Rubicon Communications, LLC ("Netgate")

(cherry picked from commit c91539772b07cb78369626716a4ddf92cf6caa5f)
DeltaFile
+5-1sys/netpfil/pf/pflow.c
+5-11 files

OPNSense/src 27f2d6a — sys/netpfil/pf pf_nl.h pf_nl.c

pf: Parse the GETSTATES state id as 64 bits

The GETSTATES dump sends PF_ST_ID as a u64, but the request parser
reads it as a u32 and rejects an id taken from the dump with EINVAL.
Nothing in base sends PF_ST_ID.  Parse and document it as a u64.

Reviewed by:            kp
Fixes:                  2cef62886dc7 ("pf: convert state retrieval to netlink")
MFC after:              1 week
Sponsored by:           Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D60543

(cherry picked from commit 74d2a0b79ffd8d43da61eaca36b39935594d8772)
DeltaFile
+2-2sys/netpfil/pf/pf_nl.c
+1-1sys/netpfil/pf/pf_nl.h
+3-32 files

OPNSense/src ce4a870 — sys/netpfil/pf pf_table.c, tests/sys/netpfil/pf table.sh

pf: do not loop on an address that is cleared twice in pfr_clr_astats()

pfr_clr_astats() looks up each address it is given and inserts the entry
it finds at the head of a work queue. If the same address is given more
than once, the entry is inserted twice and the second insertion makes it
its own successor. pfr_clstats_kentries() then walks the queue forever,
with the rules lock held for writing, so packet processing and every
other pf operation in that vnet stop as well. To reproduce:

pfctl -e
pfctl -t foo -T add 192.0.2.1
pfctl -t foo -T zero 192.0.2.1 192.0.2.1

Do as pfr_del_addrs() does: clear pfrke_mark on the entries named, then
queue an entry only the first time it is seen. An address given more
than once is cleared, and counted, once. Validate all addresses before
any entry is touched.

Add a regression test.

    [8 lines not shown]
DeltaFile
+34-0tests/sys/netpfil/pf/table.sh
+9-2sys/netpfil/pf/pf_table.c
+43-22 files

OPNSense/src 3b550b5 — sys/netpfil/pf pf.c, tests/sys/netpfil/pf icmp6.sh

pf: Do not corrupt neighbour advertisements when translating

When an ICMPv6 query or reply matches a translated state,
pf_test_state_icmp() copies the state's virtual id into icmp6_id.  Only
echo messages have an identifier there.  For all other types the
virtual id is 0 and those two bytes hold something else; in a neighbour
advertisement they hold the R, S and O flags.  The checksum was not
updated either, so icmp6_input() dropped the advertisement as a bad
checksum.

Unicast NUD probes to a link-local neighbour, such as the default
router, are sent from the link-local address.  With a nat rule that
matches it (e.g. "from any"), every advertisement answering a probe was
dropped: NUD failed, the neighbour cache entry was deleted, and traffic
to the neighbour stalled until it was resolved again.

Only rewrite the id of echo messages, as the ICMPv6 error path already
does, and update the checksum, as the IPv4 path does.


    [10 lines not shown]
DeltaFile
+73-0tests/sys/netpfil/pf/icmp6.sh
+13-1sys/netpfil/pf/pf.c
+86-12 files

OPNSense/src cc0ecc8 — sys/netpfil/pf pf_ioctl.c, tests/sys/netpfil/pf rules_counter.sh

pf: Do not hash pool address pointers into rule hashes

pf_hash_pool() hashes the first address of a pool as a whole struct
pf_addr_wrap, including the union that holds the kernel's pfi_dynaddr
or pfr_ktable pointer.

An interface pool such as "-> ($ext_if)" gets a new pfi_dynaddr on
every load, so with "set keepcounters" the rule never matches its
predecessor and loses its counters on every reload.  The pointers also
differ between hosts: once a filter rule in the main ruleset has an
interface or table pool, pfsync peers disagree on the ruleset checksum
and bind every synced state to the default rule.

Hash the address with that union cleared.  The rest of the address,
including the prefix length of an interface address, is hashed as
before, and the hash of a rule with a plain address pool does not
change.

Reviewed by:            kp

    [6 lines not shown]
DeltaFile
+53-0tests/sys/netpfil/pf/rules_counter.sh
+5-1sys/netpfil/pf/pf_ioctl.c
+58-12 files