ipfw_nat: Allocate the link of an address or protocol redirect
add_redir_spool_cfg() sizes the array of alias links of a redirect by
pport_cnt, but ipfw(8) sets pport_cnt only for redirect_port. An
address or protocol redirect gets a zero-size allocation, and its one
link is stored past the end of it. malloc(9) hands out at least 16
bytes, so nothing else is overwritten, but KASAN catches the store
since 3cd5e9e4ee03 added the fwd:nexthop_nat_v4 test, which configures
a redirect_addr:
panic: ASan: Invalid access, 8-byte write at ..., MallocRedZone(fb)
add_redir_spool_cfg() at ip_fw_nat.c:223
nat44_config() at ip_fw_nat.c:543
nat44_cfg() at ip_fw_nat.c:603
Allocate at least one link.
Reported by: kp
MFC after: 3 days
Sponsored by: Rubicon Communications, LLC ("Netgate")
powerpc/powernv: byte swap the OPAL async completion token
OPAL messages are big endian, but opal_handle_async_completion() took
the token straight from params[0]. On little endian a token reads as a
huge number that the int then truncates to 0, so every completion was
recorded against token 0. A request that happened to get token 0
worked by luck. Any other one only finished if
OPAL_CHECK_ASYNC_COMPLETION saw the message before the kernel's message
poller took it, and otherwise opal_wait_completion() spun forever.
I hit this on a POWER9 PowerNV machine with a one byte read from an I2C
EEPROM, which never returned. Swap the token, and check that it's in
range before using it as an index.
Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62361
dtrace/powerpc: decode blr and bctr in the pid provider
OPX() shifted the instruction by two bits instead of one, so the
extended opcode never matched and blr and bctr weren't recognised.
They were treated like any other instruction, which means a single
step that powerpc doesn't have. A return probe on a function that ends
in blr panics an INVARIANTS kernel, and without INVARIANTS the traced
process spins on the tracepoint.
Fix the shift. Two more things were hidden behind it and have to be
fixed with it: bclr was typed as a bctr, so it would have returned
through CTR, and OP_RB() had the wrong mask, so some real or
instructions would have been taken for no-ops.
Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62360
powerpc: let DTrace decide whether a kernel trap instruction is its probe
trap() tells an fbt probe from a debugger breakpoint by reading the
instruction at the trap address and comparing it with the fbt one. When
a probe is disabled fbt puts the original instruction back, and other
CPUs can already be in the trap for it by then. Such a CPU finds the
original instruction, takes the trap for a breakpoint and drops into
KDB. I've had a guest stop like that twice, both times when dtrace(1)
exited with a probe on a busy function.
DTrace doesn't need the instruction to know its probe. fbt_invop()
looks the address up in its own table, and dtrace_invop_start() returns
-1 when nobody claims it. So ask it for every kernel trap instruction
and go on to KDB only when it says no, like amd64 does.
Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62358
clnt_rdma.c: Add ENODEV to the reconnect retry errors
The Intel 810 replies with ENODEV when a NIC is turned
off. Add ENODEV to the list of errors that cause a
retry of a connect.
MFC after: 1 month
Fixes: 80bee4d83637 ("nfsclrdma: Add code to support client side NFS over RDMA")
netipsec: Set the IPv6 payload length before the enc(4) input hook
ipsec6_common_input_cb() corrects ip6_plen for the removed IPsec header
only after it has run the IPSEC_ENC_BEFORE hook, so enc(4) hands the
packet to bpf and pfil with the payload length of the packet as it was
received. Since cb43e97aea11 ("pf: add missing IPv6 length check") pf
drops such a packet as short, so with pf enabled on enc0 and the default
net.enc.in.ipsec_filter_mask every inbound IPv6 packet protected by IPsec
was dropped. The IPv4 path already fixes ip_len before its hook.
Set the payload length before running the hook.
Fixes: fcf596178b5f ("Merge projects/ipsec into head/.")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
LinuxKPI: add SPACEMIT PCI IDs
Those were found in an updated wireless driver.
MFC after: 3 days
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D60632
LinuxKPI: 802.11: point vif->bss_conf.bssid at vif->cfg.ap_addr
In lkpi_sta_scan_to_auth(), vif->bss_conf.bssid was assigned directly to
ni->ni_bssid inside the ephemeral struct ieee80211_node. When
lkpi_sta_auth_to_scan() (or an error path in lkpi_sta_scan_to_auth())
reset vif->cfg.ap_addr and freed ni via ieee80211_free_node(ni),
vif->bss_conf.bssid was left dangling.
Subsequent driver accesses to link_conf->bssid / vif->bss_conf.bssid
while unassociated (for example ether_addr_copy(info.tsf_bssid,
link_conf->bssid) in iwl_mld_handle_scan_complete_notif()) then
dereferenced the freed ieee80211_node, triggering a deterministic 6-byte
UMAUseAfterFree panic under KASAN (and reading freed/reused UMA memory
without KASAN).
Point vif->bss_conf.bssid at vif->cfg.ap_addr in both
lkpi_ic_vap_create() and lkpi_sta_scan_to_auth(). vif->cfg.ap_addr is
embedded in struct ieee80211_vif with the same lifetime, is initialized
to ieee80211broadcastaddr at VAP creation, updated in
[12 lines not shown]
LinuxKPI: adjust return value of __ffs64
ffsll() returns an int; there is no need for __ffs64 to return an
unsigned long; reduce it to an unsigned int which callers may expect.
As the result is undefined for no bits set we do not have to worry about
the -1.
MFC after: 3 days
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D60715
LinuxKPI: 802.11: remove old key from driver on re-key
On a WPA group rekey, the LinuxKPI 802.11 compat layer installs the
new key but never tells the driver to remove the old one.
With hw_crypto enabled, at least iwlwifi keeps one firmware key slot
per installed key and only has 16, so after about 14 rekeys the table
is full. The next key install fails and the card carries on decrypting
with the old group key, so broadcast and multicast traffic stop arriving.
For now remove the key immediately as net80211 tries to install a new
key in the same slot. In theory this should be a deferred operation,
so leave an IMPROVE().
PR: 301069
MFC after: 3 days
linuxulator/powerpc: fill in the machine name in uname()
It was left empty, so config.guess and everything else looking at
uname -m could not tell what it was running on.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62280
mlx5en: fix RX HW timestamp overflow with 1GHz clock
mlx5e_mbuf_tstmp() splits the HW clock delta into seconds and a
sub-second remainder before scaling it by the calibration interval.
With a 1GHz core clock and the default 30 seconds recalibration
interval, both the remainder multiplied by the interval in ns and the
carry over multiplied by cclk exceed 2^64. RX timestamps end up off by
up to two seconds, which shows up as clock drift in NTP using HW RX
timestamps.
Take the whole calibration intervals out of the HW clock delta first,
so that the rest of the computation does not depend on how far the
timestamp is from the calibration point, e.g. after the system was
suspended. Then split the rest at 2^20 clocks, about 1ms at 1GHz,
instead of at seconds, using shifts and masks. The split no longer
depends on the clock frequency, so priv->cclk is removed.
Reviewed by: kib, gallatin
Sponsored by: Nvidia networking
[2 lines not shown]
imgact_elf: accept PT_INTERP segments up to 4096 bytes
The Yocto/Poky relocatable SDK NUL-pads the interpreter path in
PT_INTERP out to 4096 bytes (within Linux's POSIX PATH_MAX) so that
'relocate_sdk.py' can rewrite the path in place. The kernel rejected
any PT_INTERP with p_filesz > BSD's MAXPATHLEN (1024) with
"Invalid PT_INTERP" and ENOEXEC, so none of the SDK's binaries could
be run under the Linuxulator.
- The PT_INTERP segment may now be up to 'PT_INTERP_SEG_MAXSZ'
bytes, which may be greater than 'MAXPATHLEN'.
- The interpreter path within the segment must still be shorter
than 'MAXPATHLEN' -- when violated results in 'ENAMETOOLONG'
when the interpreter is looked up.
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D62075
(cherry picked from commit 7ee8d41ebb2ffb13e50ea59fd5bc43155123f323)
linuxulator/powerpc: report the CPU family in AT_PLATFORM
Linux passes the CPU family here, e.g. power9. glibc uses it for
__builtin_cpu_is().
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62279
linuxulator/powerpc: implement the FUTEX_WAKE_OP helpers
These were stubs returning ENOTSUP. Qt uses FUTEX_WAKE_OP, so Qt programs
hung as soon as they started a thread.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62278
linuxulator/powerpc: fix terminal ioctls
linux_ioctl() only looks at the low 16 bits of the command, so the PowerPC
handler was never called and isatty() failed. Return ENOIOCTL for commands
we don't know, so that other handlers get a chance.
struct termios has c_cc before c_line and carries the speeds on PowerPC,
and CSIZE is encoded like on BSD. Fix the codes for 57600 and 115200 baud
while here.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62277
Add USB quirk for WCH-Link adapter
WCH-Link is a debug adapter from QinHeng Electronics that features a
(proprietary) debug bridge for their RISC-V MCUs, as well as a serial
gateway, implemented as a CDC device. The CDC's call management
descriptor declares the data interface to be 1, but it is actually
interface 2. UQ_IGNORE_CDC_CM has already been implemented before to
handle this kind of firmware bug, so just add this quirk for WCH-Link.
Reported by: Holm Tiffe
(cherry picked from commit 1660d69068a0650fcda2ce7497dfa20e33f0b58d)
linuxulator/powerpc: use the PowerPC socket option numbers
Six socket options are numbered differently on PowerPC. linux_socket.h
already has an #ifndef for that, but nothing defined them.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62276
linuxulator/powerpc: enable socketcall
PowerPC had no separate socket syscalls before Linux 4.3, so binaries
built for older kernels use socketcall() for everything.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62275
linuxulator/powerpc: implement send, recv and ipc
glibc uses send(), recv() and the ipc() multiplexer on PowerPC. Without
them DNS lookups and SysV shared memory don't work.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62274
acpi: acpivar.h: Include ACPICA's acpi.h, remove the latter in consumers
<dev/acpica/acpivar.h> uses types from
<contrib/dev/acpica/include/acpi.h>, so have it include it directly.
This allows removing that include, and in passing some superfluous
includes from sys/contrib/dev/acpica/include, from all source files
including <dev/acpica/acpivar.h>.
Reviewed by: imp, jaeyoon
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62103
linuxulator/powerpc: move syscalls out of the 32-bit only slots
On powerpc64 select() is syscall 142, getrlimit() is 190 and umount2() is
52. We had them at 82, 76 and 22, which are 32-bit only. Linux programs
couldn't unmount anything.
mmap2 is 32-bit only as well. Use linux_mmap2() for mmap like amd64 and
arm64 do and remove our copy of it.
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D62273
rtld: preserve the FP and vector registers in __tls_get_addr() on powerpc64
LLVM assumes that __tls_get_addr() clobbers only r0, r4-r12, LR, CTR,
CR0, CR1 and CR5-CR7 (the GETtlsADDR pseudo in PPCInstr64Bit.td), as
glibc's implementation guarantees, and keeps live values in the other
registers across the call. Our slow path, which runs on the first
access to the TLS block of a dlopen()ed object, copies the TLS
initialization image with the generic memcpy() and memset(), which
clang vectorizes: for a 130-byte block they clobber vs0, vs1, v0, v2,
v3 and v5 on powerpc64le and v2, v4 and v5 in a POWER9 powerpc64 build.
Qt's QBindingStorage constructor zeroes vs0, calls __tls_get_addr() and
then stores vs0 into the object, so the first QObject created by a
process that dlopen()ed libQt6Core gets 0xffffffff in its binding
storage pointer and crashes on destruction; this is why devel/pyside6
cannot generate QtGui.pyi on powerpc64le.
Keep the fast path as it is and run the slow path through a trampoline
that saves and restores the volatile floating-point and vector
[13 lines not shown]
Add USB quirk for WCH-Link adapter
WCH-Link is a debug adapter from QinHeng Electronics that features a
(proprietary) debug bridge for their RISC-V MCUs, as well as a serial
gateway, implemented as a CDC device. The CDC's call management
descriptor declares the data interface to be 1, but it is actually
interface 2. UQ_IGNORE_CDC_CM has already been implemented before to
handle this kind of firmware bug, so just add this quirk for WCH-Link.
Reported by: Holm Tiffe
(cherry picked from commit 1660d69068a0650fcda2ce7497dfa20e33f0b58d)
stand: Support jumping to UEFI setup
Add support to reboot to UEFI setup. This basically add indication to
OsIndications then reboot. OsIndicationsSupported is checked before
making any decision.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D61996
EC2: Use stream-optimized VMDK format
Once enabled on all of the branches, this will reduce bandwidth
consumption from uploading weekly snapshot builds from ~500 GB to
~100 GB, as well as significantly speeding up the process.
MFC after: 2 months
Sponsored by: Amazon
(cherry picked from commit 34f2f57b836d9cec02130419f5272495860d4ddf)
netipsec: Do not zero the IPv6 UDP checksum after NAT-T decapsulation
When transport mode ESP arrives in UDP and the IKE daemon gave no
original addresses (NAT-OA) for the SA, the default
net.inet.ipsec.natt_cksum_policy has udp_ipsec_adjust_cksum() ignore the
checksum of the inner header: a TCP segment is marked as verified and
the checksum of a UDP datagram is set to zero. This is option c of RFC
3948, section 3.1.2, which was written with IPv4 in mind. UDP over IPv6
has no "no checksum" value, so udp6_input() dropped every such datagram.
With strongSwan, which installs no NAT-OA for these SAs, TCP and ICMPv6
worked over an IPv6 transport mode SA with UDP encapsulation and UDP
did not.
Mark the datagram as verified instead, as is done for TCP. Linux does
the same for both address families. A datagram that the sender gave a
zero checksum is still dropped.
Fixes: 80044c785cb0 ("Add UDP encapsulation of ESP in IPv6")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
powerpc: Avoid panicking on alignment errors
PowerPC ISA specifies that an alignment fault can occur when any load or
store accesses cache-inhibited or write-through memory. Since
copyin/copyout don't know what type of memory they will access we can't
always trust that memory is well behaved, or that it's properly aligned.
Avoid a panic by giving the fault handler a chance to deal with it and
propagate the fault back up.