stand/cd9660: handle padding after advancing the record pointer
cd9660_open() walks a CD9660 directory by moving dp to the next record
and then adding the record length to the byte counter off. dp has
already moved, so off gets the next record's length, not the current
one. At the end of a directory this can leave off block-aligned after
the last real record, so the loop reads one sector past the directory
extent before it can observe the zero padding. The following sector can
be the start of another file; parsing its bytes as a directory record
can make the Rock Ridge/SUSP scanner loop without making progress and
hang the loader before the kernel.
Follow the FreeBSD fix from D8101 and handle padding immediately after
the advance: if the new record has zero length it is padding, so resync
off to the block boundary and continue. Otherwise add the new record
length.
Obtained-from: FreeBSD (review: https://reviews.freebsd.org/D8101)
Bug: https://bugs.dragonflybsd.org/issues/3446
if_loop: Clean up if_simloop() a bit
* Use M_ASSERTPKTHDR() avoid an ad-hoc KASSERT().
* Use 'uint32_t' instead of plain 'int' to handle the BPF header.
* Use m_adj() to strip the BPF header.
* Replace the KASSERT() with a kprintf() warning if the BPF-injected
packet is too short.
pututxline(3): Initialize the lastlogx struct for updlastlogx()
This doesn't fix a real bug, because the uninitialized fields in 'struct
lastlogx' are currently unused by updlastlogx(). Fix it to be
future-proof.
timeout(1): skip SIGTHR and warn on failed sigaction
timeout(1) installs a handler on every signal so it can forward them to
its child.
The handler loop runs in the parent after fork(), so aborting when a
sigaction() call fails leaves the command running untracked, without a
time limit and without signal forwarding. Skip SIGTHR, and warn instead
of aborting if any other sigaction() fails.
The SIGTHR is reserved by the thread library for thread cancellation.
sigaction() rejects it with EINVAL.
This is a regression revealed by the merge of libthread_xu with libc.
Bug: https://bugs.dragonflybsd.org/issues/3445
if_tun: Fix error handling, input validation and minor issues
* tunclone(): Handle unit allocation failure; rollback changes if
if_clone_create() fails.
* tuncreate(): Handle if_alloc() failure to not leak the 'sc'.
* tun_clone_create(): Simplify bitmap unit conflict, which is an
out-of-sync and shouldn't happen; rollback changes if tuncreate()
fails.
* tunifioctl(): Use ksnprintf() to avoid possible ifs->ascii overrun.
* tunifoutput_serialized():
- Drop packets if the interface is not up, like FreeBSD.
- Handle short or fragmented packets from BPF writes.
- Fix ifq_classify() by moving it after the BPF handling.
- Add IFNET_STAT_INC() for obytes.
* tunioctl():
- Validate MTU range, similar to the check done in if.c.
- Clear the IFF_MULTICAST bit.
* tunwrite(): Simplify and optimize mbuf chain building by using
m_uiomove(), which uses mbuf clusters to save allocations.
[5 lines not shown]
if_tun: Support to delegate per-interface /dev/tunN to normal users
The tun(4) interface doesn't support a 'net.link.tap.user_open' like
sysctl to allow normal users to use an created /dev/tunN, even this
device node has been chown'ed for the user. This made it impossible for
a normal user to use a tun(4) interface, e.g., in 'ssh -w' as mentioned
in commit 06d94267609af69188f670c64af6dce7c7dd45c9.
To fix this limitation, remove the root privilege check on the
per-interface /dev/tunN device nodes, so their access is determined by
the file permissions. Therefore, an admin can create an tun(4)
interface and delegate it to a normal user by changing the ownership,
e.g.,
$ ifconfig tun0 create
$ chown <user> /dev/tun0
Note that the default ownership for /dev/tunN has been changed from uucp:
dialer to root:wheel, avoiding the uucp user implicitly gaining access
[4 lines not shown]
sshd(8): Fix sshd_config installation failure in 'make distribution'
The nrelease/Makefile runs etc's 'make distribution' with a temporary
MAKEOBJDIRPREFIX, so sshd/Makefile.etc cannot use the 'sshd_config'
built along with buildworld.
This fixes the failure introduced by my previous commit
d715c6bde30c404dde667d6642819526181ddc8b.
hammer(8): Fix check_period() to handle DST for daily period
Converting rounded local midnights with mktime() can leave only 23 hours
between consecutive dates when daylight saving time starts. Fix it by
using timegm() that ignores DST offsets.
Reported-by: pavalos
Bug: https://bugs.dragonflybsd.org/issues/2526
if_run: simplify the revision comparison
Revisions below 0x0201 are also below 0x0211. Remove the redundant
comparison without changing which revisions take this branch.
Note: FreeBSD's and OpenBSD's if_run.c still have this redundant
condition.
Reported-by: dcb
Bug: https://bugs.dragonflybsd.org/issues/3018
if_ath: use a single-bit mask for sync interrupt counters
Select bit i with 1U << i rather than i << i. The unsigned mask also
avoids signed left-shift overflow when selecting bit31.
Reported-by: dcb
Bug: https://bugs.dragonflybsd.org/issues/3022
libssh: Define SSH_TUN_COMPAT_AF to fix tun(4)-based tunnel feature
ssh supports to use tun(4) to create a layer-3 tunnel. Our tun(4) works
in the same way as FreeBSD's, so define SSH_TUN_COMPAT_AF and fix
if_tun.h inclusion to enable TUNSIFHEAD and AF header conversion.
However, this feature only works with logging as the root user, due to a
permission restriction in tun(4) that needs to be removed.
Also, this feature is disabled by default and requires manually setting
'PermitTunnel yes' in sshd_config.
nlist(3): Sync with FreeBSD
* Handle multiple symbol tables in ELF files.
(see FreeBSD commit 4617a6cb82a673b02257257c1f5f8a3c8d2bb943)
* Remove legacy a.out code.
* Update man page.
In particular, this fixes the forthcoming OpenSSH's using nlist(3) to
detect a required symbol in the PKCS#11 or FIDO/U2F providers (libraries).
sshd(8): Use sed to disable PasswordAuthentication in sshd_config
So we don't need to modifiy a vendor file for future upgrades.
Also remove the unused and duplicate files in libexec/sshd-session.
libssh: Fix crypt() misdetection to avoid custom auth passwd
The configure script failed to detect crypt() availability so xcrypt.c
chose DES_crypt() from OpenSSL/LibreSSL, which is incompatible.
Fix the misdetection by setting -DHAVE_CRYPT in CFLAGS. And this
reverts commit 4a1ac62bb5d7392fd6305e93850de57407b334e6.
make.conf: Delete the mislabeled ENABLE_SUID_SSH knob
This knob actually controlled the SUID bit of libexec/ssh-keysign, which
is needed for host-based authentication, and it actually requires the
SUID permission to work.
So just remove the ENABLE_SUID_SSH knob and always install ssh-keysign
with SUID. While there, explicitly set BINOWN=root and change BINMODE
to 4555, following both FreeBSD and OpenBSD.
Obtained-from: FreeBSD (commit 0041e47595fad8de5f6c3fd28522e4aa14eef32a)
socket: Implement getsockopt(SO_ACCEPTCONN)
SO_ACCEPTCONN is defined in <sys/socket.h>, but sogetopt() did not
handle it, so getsockopt(2) returned ENOPROTOOPT. FreeBSD, OpenBSD
and NetBSD all report it among the SOL_SOCKET options.
TigerVNC and similar servers probe this option to tell whether
their standard input is a connected socket or a listening socket
inherited from inetd "wait" mode. Without it, TigerVNC treats the
listening socket as connected, getpeername() fails with ENOTCONN,
and inetd respawns the server in a loop.
Add SO_ACCEPTCONN to the integer SOL_SOCKET option group, matching
FreeBSD (see commit dcb5fef5dbd4ca8488deff7a9074850d851bdc08).
Reported-by: Adrian Kieß
Bug: https://bugs.dragonflybsd.org/issues/3300
catopen(3): align returned errors with POSIX.1-2024
Return ENOENT instead of EFTYPE for invalid/empty names, non-existent
catalogue files, and bad catalogue headers. Require the complete header
and reject sizes that exceed mmap() limit.
Also save the errno in handling the open() failure.
Derived-from: FreeBSD (commit 1176390d2d2bbb1e207c840d1f7a66a6ac1096ff)
Reported-by: pmjdebruijn
Bug: https://bugs.dragonflybsd.org/issues/3393
catopen(3): Fix race condition
The current code uses a rwlock to protect the cached list, which
in turn holds a list of catentry objects, and increments reference
count while holding only read lock. Fix this by converting the
reference counter to use atomic operations.
Also improve the cleanups of memory allocations.
Obtained-from: FreeBSD (commit 4188ba1a3b65b4a55fc938b71d9091fafb57967d)
Reported-by: pmjdebruijn
Bug: https://bugs.dragonflybsd.org/issues/3393
drm: Balance dma-buf file references on get and fd export
dma_buf_get() drops its lookup reference before returning, but its callers
release the returned buffer with dma_buf_put(). Repeated imports can
therefore consume references owned by the descriptor and PRIME caches.
Retain an independent file reference before dropping the lookup reference.
dma_buf_fd() transfers the caller's reference to the new descriptor.
fsetfd() acquires another reference, so drop the caller's reference after
successful installation. Keep it on allocation failure.
FreeBSD's dma-buf implementation follows the same ownership rules: retain
the fget() reference on lookup and drop the extra reference taken by
finstall() after successful descriptor installation.
The comments were extracted from the patch bundle by servik and dillon:
https://apollo.backplane.com/DFlyMisc/drm98.patch
Reference: https://github.com/freebsd/drm-kmod/blob/f252a30f27d157d9c763cd408850775096a6263f/drivers/dma-buf/dma-buf.c#L498-L544
Bug: https://bugs.dragonflybsd.org/issues/3428
kdmsg: shut down the transport while waiting for reconnect workers
KILLRX and a wakeup on msg_ctl do not interrupt a reader blocked in
fp_read() on a quiet connection. Reconnect can then wait indefinitely
for the reader and writer to exit. HAMMER2's recluster ioctl holds the
root vnode during this wait, blocking other filesystem operations.
Shut down msg_fp before sleeping in the worker-wait loop. This wakes
blocked transport I/O and leaves the existing state cleanup and file
reference handling in place.
Keep the shutdown inside the loop: lksleep() releases msglk, so another
reconnect may replace the connection while this caller is asleep. A
one-time shutdown before the loop can leave this caller waiting on the
replacement workers.
Bug: https://bugs.dragonflybsd.org/issues/3434
drm: notify userspace of connector changes
Emit the DRM CONNECTOR HOTPLUG devctl event for the primary card. The
empty hotplug handler leaves libudev-devd clients unaware of connector
changes.
Use the event contract implemented in FreeBSD drm-kmod
drivers/gpu/drm/drm_sysfs.c.
Bug: https://bugs.dragonflybsd.org/issues/3440
bpf: add XOR and modulo instructions
libpcap can generate XOR and modulo instructions, but the kernel
interpreter and validator do not support them.
Add constant and register operands for both operations. Reject constant
modulo by zero and return zero for a register zero divisor, as for DIV.
Update the manual to match.
Patch-by: guy
Bug: https://bugs.dragonflybsd.org/issues/3387
drm: reject unload while core teardown is incomplete
Unloading drm.ko reaches ttm_exit(), which waits for device_released.
The callback which sets that flag is compiled out and device unregister
is a stub, so kldunload sleeps indefinitely while holding the linker
lock. The module event handler has already cleared the Linux task and
process cleanup callbacks by then.
DRM also retains worker threads and undrained RCU callouts, so removing
the TTM wait alone would not make unloading safe. Return EBUSY from
MOD_UNLOAD before changing callbacks or entering SYSUNINIT. Keep the
module usable until complete teardown is implemented.
Bug: https://bugs.dragonflybsd.org/issues/3443
vm: use normal COW inheritance for user-wired mappings
Forking an mlock()ed MAP_PRIVATE file mapping can panic with
"vm_fault_copy_wired: page missing". The wired-copy path expects the
page in the front object, but it may be in a backing object or have
been removed after the file was truncated.
Use normal COW inheritance for normal mappings with only a user wire.
The parent stays user-wired and the child remains unwired. The normal
fault path resolves backing pages and handles pager errors. Keep eager
copying for hard-wired and virtual-page-table mappings.
Reviewed-by: dillon
Bug: https://bugs.dragonflybsd.org/issues/3433