kernel - Fix auto port assignment collision in network code
* When the SO_REUSEADDR or SO_REUSEPORT socket option is set on a
socket undergoing automatic lport assignment, the auto network port
assignment code in the kernel improperly ignores collisions against
ports assigned to wildcard sockets and may assign the same port. This
causes later connect() calls to fail.
* Can cause gdb services to sometimes fail to connect.
* Fixed by ignoring the options for the purposes of finding an unused
port.
Reported-by: Sergey Zigachev (servik)
rtld - do not allow both dynamic DTV index and static TLS offset
* If we are allocating static offset for an object with dynamic index,
return failure. In the opposite case, if dynamic index is requested for
statically allocated TLS area, directly use the offset instead of
setting the index.
Taken from FreeBSD, commit 91880e07f605edb90339685bc934699a4344de3b.
* While there, fix dtv timing race between threads.
Co-authored-by: Matthew Dillon <dillon at apollo.backplane.com>
Reported-by: Stephane Russell <srussell at prodigeinfo.qc.ca>
ifconfig(8): Fix IPv6 CIDR parsing error for wgaip (wg allowed-ip)
The inet_net_pton() is inherited from legacy ISC named code and uses a
legacy IPv6 CIDR format (e.g., 1:2:3:4/64), so it fails to parse some
now valid IPv6 CIDRs (e.g., 1:2:3:4::/64). This was causing 'wgaip'
option to fail configure some IPv6 allowed-ips/networks.
Given that inet_net_pton() is not standard and behaves differently
across BSDs and Linux, it might be not really useful to fix/improve it
(e.g., by porting OpenBSD's version). Instead, I chose to write
wg_aip_parse() to manually parse the CIDRs.
Reported-by: Michael Neumann (mneumann) on IRC
kernel - Improve umount -f operation
* Increase the process test/kill retry loop for umount -f from 10
to 50 (from 2.5 seconds to 12.5 seconds) to give processes more
time to exit after receiving a KILL signal.
* Make the tsleep() used for the retry delay unconditional to ensure a
reasonable period of time is allowed to elapse.
* Release the mount structure lock during the 0.25 second tsleep()
in the retry loop. This allows processes to unstick during the
umount -f retry loop.
* Add a P_MUSTKILL flag to the process structure, set if necessary
during a umount -f. Process core dumps (which are usually
uninterruptable) will be aborted if this flag is found to be set.
Further tests for this flag may be needed.
Reported-by: marino (via loki kernel crash)
kernel - Fix umount -f related panic
* Adjust umount -f (forced unmount) logic to kill processes which
still hold references to the mount in question, due to being chrooted
or jailed in the mount, their current directory being on the mount,
or having any open file via the mount.
To be frank, it is hard to find a nice way to rip a mount out from under
processes as their behavior upon suddenly having file descriptors go bad
is completely non-deterministic. A forced unmount is not supposed to be
kind to the system. The best solution is to kill the processes.
* Fixes panics related to regular use of umount -f if the operation
happens to race active operations by processes on the mount.
Reported-by: marino
kernel - Improve umount -f operation
* Increase the process test/kill retry loop for umount -f from 10
to 50 (from 2.5 seconds to 12.5 seconds) to give processes more
time to exit after receiving a KILL signal.
* Make the tsleep() used for the retry delay unconditional to ensure a
reasonable period of time is allowed to elapse.
* Release the mount structure lock during the 0.25 second tsleep()
in the retry loop. This allows processes to unstick during the
umount -f retry loop.
* Add a P_MUSTKILL flag to the process structure, set if necessary
during a umount -f. Process core dumps (which are usually
uninterruptable) will be aborted if this flag is found to be set.
Further tests for this flag may be needed.
Reported-by: marino (via loki kernel crash)
kern - Make lseek(2) generic
* Extend fileops with fo_seek function allowing pluggable lseek(2)
implementations. Part of preparation for linux DMA-BUF compat API.
* Move current vnode lseek implementation into vnode and devfs fileops.
Code is exactly the same in both, note about duplication added.
* Set remaining fileops to badfo_seek.
Mentored-By: dillon
world - Replace gnu diff, diff3, and sdiff with BSD versions
* Replace diff and diff3 with the OpenBSD diff and diff3,
Replace sdiff with the FreeBSD sdiff,
Remove the GNU diff, diff3, and sdiff
* Basic testing with dsynth bulk to ensure no significant compatibility
disruptions.
Submitted-by: Tyler <tyler.clark at foxide.xyz>
sbin/hammer2/cmd_debug.c: Refactor unreadable cmd_show()
0b7381572b131c74051832dc251604e7f77b5a54 added multi-volumes
support to cmd_show() (entry point of freemap,show,volhdr directives)
with minimum modification using goto, but the code has been not
so readable since then. Rewrite this entry point function.
The output is same except that "Volume %d header %d..."
by default (= when not showing volhdr or bref for all volumes)
appears before printing each volhdr or bref, rather than all
at once in the beginning.
sbin/hammer2/cmd_debug.c: Clear errno
otherwise affects next strtol(3) variant when no error.
strtol(3) says "If no conversion could be performed,
0 is returned and the global variable errno is set to EINVAL".
sys/vfs/hammer2: Change hammer2_inode_meta::target_type to unused84
No longer used or needed since
da0cdd33148ab3e3c227355de759c595c533841a in 2017.
target_type was only used for the initial hardlink design and
implementation, which is not how it works today.
rtld - Improve error reporting
* Prefix hex type values with 0x
* Include (%s) obj->path so the user has some idea which file is
responsible for the error.
Requested-by: servik
sbin/hammer2: Verify fstype UUID in hammer2_verify_volumes_common()
Its string form has to be HAMMER2_UUID_STRING.
Also move common volu_id check to hammer2_verify_volumes_common().
sbin/newfs_hammer2: Fail if input size is < alignment size
If aligned size becomes 0, it should fail with an error message
before hammer2_install_volume().
e.g. If a regular file av[0] is 4MiB, size becomes 0 after aligned.
Also add same sanity in hammer2_verify_volumes_common().
vol->size == 0 passes 8MiB or 1GiB alignment sanity.
sbin/newfs_hammer2: Remove redundant inode.meta.name_xxx zero clears
Remove obsolete code from b33a7e92438b9c9fc915e7c432666385051369db in 2012.
suproot has a name "SUPROOT" in inode itself if not in dirent,
and name_len is initialized with a proper length right after this.
dsynth - Make dummy /usr/packages directory for pkg compatibility
* For the chroot, make /usr/packages for pkg compatibility. Certain
pkg related temporary files are created there for reasons unknown.
poll - Fix events == 0 handling for TAP and TUN, fix console spam
* BSD poll() supports events == 0 representing a "HUP ONLY" event.
Most of our devices properly support this but TAP and TUN did not.
Fix TAP and TUN to support this feature. This fixes openvpn()
when operating under heavier loads.
* Fix console spam on non-debug kprintf()s by rate-limiting any
such spam if it occurs. If a device doe snot support poll()'s
HUP ONLY feature, the loop deregistration path will be hit and
generate a kprintf(). We don't want console spam to stall the
cpu.