localedef: off by one bug drops the highest code point from every collation table
localedef(1) writes one fewer entry than it has into the "large" (code point
above UCHAR_MAX) collation table, and records a count one short. The table is
built in code point order, so the entry lost is always the character with the
highest code point in the locale. For that character wcsxfrm(3) returns 0 and
wcscoll(3) gives it no weight: it sorts with the ignorables and compares equal
to unrelated characters.
Reviewed by: rmoeller, kevans
Approved by: kevans (mentor)
Differential Revision: https://reviews.freebsd.org/D60057
netlink: Do not change interface flags on an empty ifinfomsg
Since f89f82e4042a, _nl_modify_ifp_generic() treats ifi_change == 0
as a request to apply all of ifi_flags. A RTM_NEWLINK request that
only modifies attributes carries a zeroed ifinfomsg, so it brought
the interface down and cleared its permanent promiscuous mode as a
side effect.
Only apply flags for an empty ifi_change when ifi_flags is set,
which matches the behavior of Linux.
Fixes: f89f82e4042a ("netlink: Fix IFF_UP flag handling in RTM_NEWLINK's modify_link handler")
Differential Revision: https://reviews.freebsd.org/D61504
nd6: Keep addresses tentative when DAD cannot run
in6_ifa_need_dad() ignored the interface state, making addresses on
down/ifdisabled interfaces optimistic and usable while DAD was deferred.
Guard it like nd6_dad_start() and re-evaluate it in in6_if_up() and
nd6_timer().
Also, reject IN6_IFF_NOTREADY sources in nd6_ns_output_fib() and
GRAND because optimistic DAD can fail while sockets are already using
the address.
While here, add some tests to make sure these never happen.
Reported by: llm-postcr
Fixes: c7cd7e7fad57 ("nd6: Add support for Optimistic DAD (RFC 4429)")
Differential Revision: https://reviews.freebsd.org/D55229
tcp/rack: reject unknown rate_sample_method values
The net.inet.tcp.rack.rate_sample_method sysctl is copied into every
new RACK connection but accepts any integer, while the
TCP_BBR_RACK_RTT_USE socket option only accepts USE_RTT_HIGH (0),
USE_RTT_LOW (1) and USE_RTT_AVG (2). With any other value,
tcp_rack_xmit_timer_commit() panics an INVARIANTS kernel on the first
RTT sample of each new connection ("Unknown rtt variant"). Without
INVARIANTS it returns early on every sample, so the connection never
updates its SRTT, RTTVAR or RTO.
Validate the sysctl with a handler that accepts only the three values
that the socket option accepts, and document the third value in the
sysctl description and in tcp_rack(4).
Reviewed by: tuexen
Co-authored-by: Claude Opus 5.5
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D62072
tcp/rack: range-check pace_max_seg sysctl and socket option
The net.inet.tcp.rack.pacing.pace_max_seg sysctl is a 32-bit integer,
but rack_init() copies it into each new connection's 7-bit bitfield
rc_user_set_max_segs. Values that do not fit are truncated, and a value
of 128 becomes 0. A connection with rc_user_set_max_segs of 0 ends up
with a pacing max segment size of 0, and rack_setup_fast_output() then
executes rounddown(left_to_send, 0), causing an integer divide fault:
Fatal trap 18: integer divide fault while in kernel mode
#5 rack_do_segment_nounlock+0x29eb
... (fault in rack_setup_fast_output() inlined into rack_output())
The TCP_RACK_PACE_MAX_SEG socket option clamps values above
MAX_USER_SET_SEG (63), but it accepts 0, which leads to the same
division by zero.
Validate the sysctl with a handler that only accepts 1 to
MAX_USER_SET_SEG, and reject a socket option value of 0 with EINVAL
[12 lines not shown]
tests/net/bpf: run the bpf:inject test with RSS again
1abb62867f2a skipped the test on RSS kernels because epair(4) delivered
the injected frames out of order. The reordering within a flow is fixed
in if_epair, but the test still failed in about one run in seven: the
first capture starts with the ARP request from ping(8), which is not an
IP packet and goes to the first epair queue, while the ICMP flow goes to
the queue its hash selects. Written back to back by the inject step,
the two may arrive in either order.
Add static ARP entries on both ends so that the captures hold only the
ICMP flow, and remove the skip. On an 8-CPU RSS kernel the test then
passed 250 of 250 runs with the if_epair fix and failed 26 of 150
without it.
While here, use the -j option of ifconfig(8), netstat(1) and arp(8)
instead of jexec(8).
Reviewed by: glebius, pouria
[2 lines not shown]
arp: Teach arp to attach and run itself in a jail
Add a -j jail option, which makes arp(8) attach to the named jail
before it does its work. This lets the host display and change the ARP
table of a vnet jail that does not have arp(8) installed, such as a
thin jail or a Linux jail. For example, `arp -j foo -an` or
`arp -j foo -d -a`.
The file given to -f is opened before attaching and processed inside
the jail, as sysctl(8) and ngctl(8) do. It must be a regular file or
a pipe, so that no directory or device descriptor is carried into the
jail. Host names are resolved inside the jail, as route(8) and
netstat(1) do.
Reviewed by: pouria, zlei, ziaee
MFC after: 1 week
Relnotes: yes
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D61725
fdescfs: descend through /dev/fd/N when mounted linrdlnk
Linux resolves a path below /proc/self/fd/N in the directory the
descriptor names, and linprocfs makes /proc/<pid>/fd a symlink to
/dev/fd. Under linrdlnk the fdescfs node carries only VV_READLINK,
which namei will not walk through, so such a path fails with ENOTDIR.
Return the underlying vnode from fdesc_lookup for a non-final component,
or a trailing slash, reusing the machinery the nodup option already
uses. The last component is untouched, so open("/dev/fd/N") keeps its
dup(2) semantic; a descriptor with no vnode behind it, such as a pipe,
yields ENOTDIR.
Add ATF coverage for traversal, descriptor reuse, and preservation of
last-component and mount-option semantics.
Approved by: adrian (mentor)
Reviewed by: kib, adrian
Differential Revision: https://reviews.freebsd.org/D59393
[2 lines not shown]
pci: restore resizable BAR sizes in pci_cfg_restore()
After a device reset, resizable BARs return to their default sizes.
Restore them to the sizes they had prior to reset.
Reviewed by: imp, adrian
Differential Revision: https://reviews.freebsd.org/D61110
Approved by: adrian (mentor)
(cherry picked from commit 665afd2a9d6469ce692de4018c7c015a194c201d)
tcp: count only the SACK blocks that fit in tcp_maxseg()
tcp_addoptions() sends only the SACK blocks that fit in TCP_MAXOLEN.
tcp_maxseg() counted every pending block and clamped the total, so
without timestamps and with five or more blocks pending it came out 4
bytes below the segment tcp_output() sends. Limited transmit after an
RTO then sent one full segment and failed the "sent too much" KASSERT.
PR: 282605
Approved by: adrian (mentor)
Signed-off-by: Nick Price <nprice at FreeBSD.org>
Reviewed by: tuexen, glebius, adrian
Differential Revision: https://reviews.freebsd.org/D60460
(cherry picked from commit d3b02115d4b373c719d9a716da38d94511de3f07)
netipsec: Do not unlock the sahtree twice in ipsec6_common_input_cb()
For transport mode, ipsec6_common_input_cb() releases the sahtree read
lock before it walks the remaining header chain. The error exits of
that walk jumped to the bad label, which released the lock a second
time. A packet that exceeds net.inet6.ip6.hdrnestlimit, is truncated,
or fails the inbound policy check on its last header is enough to get
there.
The second rm_runlock() panics kernels with INVARIANTS. Without
INVARIANTS it unbalances td_pinned and removes a tracker that is no
longer queued, which may corrupt the per-CPU tracker list.
Give the header chain walk its own exit label that skips the unlock.
Reported by: llm-postcr
Reviewed by: markj, kib
Fixes: 183513d15f22 ("sys/netipsec: ensure sah stability...")
MFC after: 1 week
[2 lines not shown]
sysrc: Fix unlikely and rare edge-case
Fix 1 issue identified in post-commit review of eaf7113:
POSTCR-1.1: with -F, the "unchanged" check compares a file path
against the new value, so a value equal to the path is silently
not written
Add an ATF test to ensure we catch the edge-case possibility.
Special note: To replicate this misbehavior you'd have to do
something like: sysrc -f /etc/rc.conf foo=1 and then execute
sysrc -F -f /etc/rc.conf foo=/etc/rc.conf
Reported by: llm-postcr
Fixes: eaf7113bef8f ("sysrc: Add "unchanged" messages")
tcp: count only the SACK blocks that fit in tcp_maxseg()
tcp_addoptions() sends only the SACK blocks that fit in TCP_MAXOLEN.
tcp_maxseg() counted every pending block and clamped the total, so
without timestamps and with five or more blocks pending it came out 4
bytes below the segment tcp_output() sends. Limited transmit after an
RTO then sent one full segment and failed the "sent too much" KASSERT.
PR: 282605
Approved by: adrian (mentor)
Signed-off-by: Nick Price <nprice at FreeBSD.org>
Reviewed by: tuexen, glebius, adrian
Differential Revision: https://reviews.freebsd.org/D60460
(cherry picked from commit d3b02115d4b373c719d9a716da38d94511de3f07)
wpa_supplicant: Mark FreeBSD scan result levels as dBm
The FreeBSD driver wrapper converts net80211's half-dB RSSI relative
to the noise floor into an absolute signal level, but leaves
WPA_SCAN_LEVEL_DBM unset.
Without the flag, scan_snr() uses the raw level instead of subtracting
the noise floor. The scan comparator also uses uncapped raw levels
rather than its dB-based SNR calculation. This can favour a stronger
2.4 GHz BSS over a faster 5 GHz BSS.
Set the flag alongside the existing conversion in the __FreeBSD__
branch, as other driver wrappers do for levels reported in dBm.
Tested with base wpa_supplicant 2.11 on FreeBSD 15.1-RELEASE-p7,
using an Intel 8265 on a dual-band network. Three stock cold starts
selected 2.4 GHz; two starts with this change selected 5 GHz HT40.
PR: 301132
Reviewed by: emaste
acpica: Fix SRAT memory region insertion sort
The SRAT table can list memory regions in any order, but we need them
sorted. There is an insertion sort to accomplish this when building
the mem_info array, but instead of inserting the new region before
the *first* higher-base-address region, it was inserting the new
region before the *last* higher-base-address region; i.e. if the array
already held "1 3 4" then inserting "2" would produce "1 3 2 4".
Break out of the insertion-location-finding loop when we find the right
spot to insert the new memory region into the list, rather than looking
further.
Reviewed by: jhb
Fixes: dd540b46236b ("Add a parser for the ACPI SRAT table...")
MFC after: 1 day
Sponsored by: Amazon
Tested on: c5n.9xlarge, c6a.24xlarge, c6a.metal, c7a.metal-48xl
c7i.metal-24xl, c7i.metal-48xl, c8a.metal-24xl
[5 lines not shown]
EC2: Set hw.dmar.enable="1"
Large EC2 "bare metal" instances route interrupts to APIC IDs > 255,
and unlike the "virtualized" instances, don't support extended APIC
destination IDs (since that's a hypervisor feature, and bare metal
instances have no hypervisor).
Enable the IOMMU for interrupt remapping; this unbreaks booting on
m8i.metal-96xl and variants thereof (e.g. c8in).
MFC after: 1 day
Sponsored by: Amazon
Tested on: c5n.9xlarge, c6a.24xlarge, c8in.96xlarge, c5.metal,
c6in.metal, c6a.metal, c7a.metal-48xl, c7i.metal-24xl,
c7i.metal-48xl, c8a.metal-24xl, c8a.metal-48xl,
c8i.metal-48xl, c8i.metal-96xl, c8in.metal-48xl,
c8in.metal-96xl, m5.metal, m8azn.metal-24xl
(cherry picked from commit 3c03ab02cf312d4fdf37ce3ff90b901722c4b3cb)
bhyve: disable SIGPIPE for IPC connections
Currently, if an IPC client (e.g. bhyvectl --get-vm-pid) exits
before reading the response, the VM crashes with SIGPIPE.
Set SO_NOSIGPIPE on a socket to prevent that.
While here, update other error paths in init_ipc_thread()
to return -1 on error instead of an error number to make error
handling consistent.
Reviewed by: markj
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62000
pf: fix memory leak on failure in DIOCADDETHRULE
If we fail pf_nveth_rule_to_keth_rule() we jumped to
DIOCADDETHRULE_error, which doesn't free the rule.
Free the rule directly, because pf_free_eth_rule() expects the rules
lock to be held, and at this point we've only allocated the rule itself,
not any of the child objects.
Reported by: llm-postcr
Fixes: e732e742b37f ("pf: Initial Ethernet level filtering code")
Sponsored by: Rubicon Communications, LLC ("Netgate")
pf: fix NULL dereference on failure in DIOCADDETHRULE
If the ticket or anchor check in DIOCADDETHRULE fails
we pf_free_eth_rule() on a struct pf_keth_rule with NULL
ipsrc.addr.p.tbl/ipdst.addr.p.tbl. That ends up dereferencing that NULL
pointer.
Teach pf_free_eth_rule() to check for NULL in those fields so it's safe
to free a rule we're in the process of creating.
Reported by: llm-postcr
Sponsored by: Rubicon Communications, LLC ("Netgate")
bhyve: fix bootorder for PCI slots >= 10
Currently, bhyve writes slots as decimals. Firmware such as EDK2
interprets them as hexadecimals, so slot 10 becomes 16, breaking
the configured boot order.
Reviewed by: markj
Fixes: 6632a0a4e3ab ("bhyve: add helper to create a bootorder")
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61997
mmc: Allow HS400ES with HS400 at a single I/O voltage
mmc_host_timing() allows HS400ES only if the host supports HS400 at
both 1.2 V and 1.8 V. A host with only 1.8 V I/O, such as the Zhihe
A210, gets plain HS400 instead, which needs tuning in HS200 first.
Accept HS400 at either voltage, as the plain HS400 check does, and use
the same rule in the sdhci capability printout.
Signed-off-by: Han Gao <gaohan at iscas.ac.cn>
Reviewed by: imp
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/2523
riscv: Add the T-Head C908 and C920v2 marchid values
Older T-Head cores report a zero marchid, but the C908 and C920v2 have
their own: 0x8000000009140d00 and 0x80000000090c0d00, as read on the
Zhihe A210, whose firmware also uses them to tell its two clusters
apart. Add them so that these cores are named instead of "Unknown".
Signed-off-by: Han Gao <gaohan at iscas.ac.cn>
Reviewed by: mhorne
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/2584
riscv: Fence after enabling the MMU in locore
Writing satp doesn't flush cached translations. If the kernel is entered
with translation already on, the hart may keep using the firmware's
mappings after locore switches page tables if they share an ASID.
Add an sfence.vma after each satp write in locore.
Signed-off-by: Han Gao <gaohan at iscas.ac.cn>
Reviewed by: mhorne
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/2522
riscv: Apply the T-HEAD errata only to early cores
The XTheadMae page attributes and the vendor cache operations are needed
by the early T-HEAD cores (C906, C910, C920), which report zero marchid
and mimpid. Later cores such as the C908 and C920v2 report non-zero
values and implement the standard Svpbmt and Zicbom extensions instead.
Setting the T-HEAD memory attribute bits there makes the early page
tables use reserved PBMT encodings.
Check marchid and mimpid before applying the quirks, both in
handle_thead_quirks() and in the early PTE setup in locore.
Signed-off-by: Han Gao <gaohan at iscas.ac.cn>
Reviewed by: mhorne
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/2522
bhyve: Reinitialise swtpm's TPM at startup
bhyve does not currently reinitialise swtpm on startup, which results in
PCRs being carried over across reboots. This means that any guest VM
implementing measured boot controls, such as Windows with BitLocker and
Secure Boot enabled, will consider the system compromised and refuse to
start or ask for a recovery key.
swtpm has a control channel that allows us to send commands for that
purpose: CMD_INIT shuts the TPM down and starts it again clearing the
PCRs in the process, like a cold boot on real hardware.
Connect a second socket when the new ctrl_path option is set and send
CMD_INIT there. Without the option nothing changes.
MFC after: 2 weeks
Sponsored by: Defenso
Signed-off-by: Quentin Thébault <quentin.thebault at defenso.fr>
Reviewed by: kevans, novel
Differential Revision: https://reviews.freebsd.org/D59322
dummynet: copy only the user-visible scheduler in copy_obj()
For a DN_SCH object copy_obj() writes the whole struct dn_schk (192
bytes on amd64) into the listing buffer, but checks and advances by
o.len, which is sizeof(struct dn_sch) (92 bytes). The extra bytes,
kernel pointers included, overrun the buffer when the scheduler is
near its end. "ipfw pipe show" or "dnctl pipe show" is enough, from
the host or from a VNET jail; KASAN reports a 192-byte write in
copy_obj().
Keep only a struct dn_sch in the local copy, which is what the code
wrote before 0ac43d9728a7, and read siht from the struct dn_schk that
contains it. Add a test that lists pipes and schedulers from a VNET
jail.
PR: 224485
Reported by: david at catwhisker.org
Reviewed by: kp
Fixes: 0ac43d9728a7 ("In dummynet(4), random chunks of memory are casted to struct dn_*,")
[3 lines not shown]
tdelete(3): Document return value when deleting root node
tsearch.3 said that tdelete() returns a pointer to the parent of the
deleted node, but the root has no parent. In that case, tdelete()
returns an unspecified non-NULL pointer (currently (void *)1) which must
not be dereferenced. Document this.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D61969
clntrdma.h: Add the RPCRDMA_HEADER_LEN macro from clnt_rdma.c
The RPCRDMA_HEADER_LEN() macro is moved from clnt_rdma.c to
clntrdma.h so it can be included in xprt_verbs.c.
MFC after: 1 month
Fixes: 884ee8d6c9b4 ("nfscl: Add some glue for client side NFS over RDMA")
clnt_rdma: Fixes for three issues listed below
There are three small issues:
1. An unused Reply chunk gets its descriptor freed, but the mbuf
and pages are left allocated, effectively leaking.
2. The reused send/receive buffers would probably need
DMA synchronization.
3. Some receive errors don't notify the RPC layer. A zero-credit
reply can also leave callers waiting.
This patch fixes these.
This patch also fixes positioning of NET_EPOCH().
Reviewed by: rmacklem
Sponsored by: VersatusHPC
MFC after: 1 month