DragonFlyBSD/src a888571sys/sys param.h

Bump __DragonFly_version for merging libthread_xu into libc

There is no ABI/API change with this merge, but it's a general good idea
to bump the version.

Suggested-by: tuxillo
DeltaFile
+2-1sys/sys/param.h
+2-11 files

DragonFlyBSD/src 3e72cdesys/vfs/fifofs fifo_vnops.c

kernel - Fix lost wakeup in fifo_open()

* fifo_open() tests fi_readers, drops the fifo and vnode locks, then
  tsleeps.  A peer opening in that window bumps the counter and issues
  its wakeup before the sleeper is queued, so open(2) blocks forever
  with a peer already attached.  Both paths are affected.

* Queue with tsleep_interlock() before releasing the locks and sleep
  with PINTERLOCKED.

Reviewed-by: @dillon
DeltaFile
+4-2sys/vfs/fifofs/fifo_vnops.c
+4-21 files

DragonFlyBSD/src 697bd29stand/lib gets.c

libstand(3): Fix off-by-one bug and handle getchar() EOF in ngets()

Obtained-from: FreeBSD
DeltaFile
+11-11stand/lib/gets.c
+11-111 files

DragonFlyBSD/src 925ffae. Makefile.inc1, etc/defaults make.conf

Remove obsolete THREAD_LIB, LIBPTHREAD, and -lpthread
DeltaFile
+4-7Makefile.inc1
+1-6share/man/man5/make.conf.5
+2-2usr.sbin/nscd/Makefile
+2-2usr.bin/dsynth/Makefile
+2-2sbin/udevd/Makefile
+0-3etc/defaults/make.conf
+11-2224 files not shown
+18-7130 files

DragonFlyBSD/src 28e770flib/libc/gen _spinlock_stub.c _pthread_stubs.c, lib/libc/thread Symbol.map

libc: Merge libthread_xu into libc

* Build the pthread implementation in libthread_xu as part of libc.
  Keep libthread_xu and libpthread as empty compatibility shims so
  existing DT_NEEDED entries continue to load.

  Initialize pthread state lazily from public pthread entry points,
  so processes that never use pthread avoid startup work, signal
  handlers, extra mappings, and rtld lock activation.

  Preserve cold fork and cancellation-point syscall performance with a
  direct __fork() path when no pthread work is needed and raw
  read/write/readv/writev syscalls before pthread state exists.  Repair
  fork-child pid and tid state lazily.

  Keep existing libc symbol versions, publish the newly linkable
  pthread_create and pthread_cancel interfaces in DF606.0, and retain
  the historical pthread names as compatibility ABI.


    [51 lines not shown]
DeltaFile
+0-308lib/libc/gen/_pthread_stubs.c
+169-0lib/libc/thread/Symbol.map
+67-54lib/libthread_xu/thread/thr_init.c
+0-97lib/libc/gen/_spinlock_stub.c
+15-74lib/libpthread/pthread.3
+0-60lib/libthread_xu/thread/Makefile.inc
+251-59331 files not shown
+550-80137 files

DragonFlyBSD/src aaef297lib/libc/thread thr_mutex.c thr_syscalls.c, lib/libthread_xu/thread thr_mutex.c thr_syscalls.c

libc: Move libthread_xu source over to libc/thread
DeltaFile
+0-801lib/libthread_xu/thread/thr_private.h
+801-0lib/libc/thread/thr_private.h
+0-780lib/libthread_xu/thread/thr_syscalls.c
+780-0lib/libc/thread/thr_syscalls.c
+0-777lib/libthread_xu/thread/thr_mutex.c
+777-0lib/libc/thread/thr_mutex.c
+2,358-2,358115 files not shown
+11,029-11,451121 files

DragonFlyBSD/src 10c5c74lib/libc Makefile.inc Makefile, lib/libc/db Makefile.inc

libc: Clean up makefiles after unsharing with libc_rtld
DeltaFile
+67-10lib/libc/Makefile
+0-75lib/libc/Makefile.inc
+5-9lib/libc/gen/Makefile.inc
+6-6lib/libc/db/Makefile.inc
+4-6lib/libc/tre-regex/Makefile.inc
+4-4lib/libc/string/Makefile.inc
+86-11029 files not shown
+119-14935 files

DragonFlyBSD/src 997171dlib/libc Makefile.inc, lib/libc_rtld libc_private.h Makefile

libc_rtld: Tailor the source and don't share libc/Makefile.inc

Explicitly list the sources from libc that are required by
libexec/rtld-elf, so it no longer uses libc/Makefile.inc that may
include unnecessary sources, especially the threading code that must be
disabled for rtld-elf.

This helps the forthcoming commit that merges libthread_xu into libc.

GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/52
DeltaFile
+99-0lib/libc_rtld/rtld_libc.c
+55-23lib/libc_rtld/Makefile
+46-0lib/libc_rtld/libc_private.h
+0-13lib/libc/Makefile.inc
+200-364 files

DragonFlyBSD/src 6e68105stand/lib gets.c

libstand(3): Fix off-by-one bug and handle getchar() EOF in ngets()

Obtained-from: FreeBSD
DeltaFile
+11-11stand/lib/gets.c
+11-111 files

DragonFlyBSD/src d1bc137sys/vm vm_page.h

kernel - Update comments on PG_BUSY rules with page wirings

* Adjust code comments to reflect that a vm_page's wire_count can transition
  from 1->0 without being busied under certain circumstances.

* The pmap system is allowed to do this when removing pages because other
  references to the page are still present and there will be no race
  against a vm_page freeing operation.
DeltaFile
+6-2sys/vm/vm_page.h
+6-21 files

DragonFlyBSD/src ab80faasys/vm vm_fault.c

kernel - Fix cryptsetup bug / fix bug in mlockall()

* mlockall() uncovererd an old bug in the VM system that was previously
  masked by other code.  The VM system going way way back assumed that
  wired pages were already wired and that at worst only a zero-fill was
  needed, so the TRYPAGER() macro checked for the case.

  However, when issuing a mlockall(), the refactored VM system uses
  vm_fault() to bring in missing wired pages to satisfy the request,
  was hitting the old condition, and doing a zero-fill instead.

* This caused cryptsetup() (one of the few programs to actually use
  mlockall()) to seg-fault under typical conditions.

* Fix by removing that part of the conditional.  Regardless of the
  wiring flags, the pager is still tried for non-default VM objects.

Reported-by: mneumann, aly
DeltaFile
+8-7sys/vm/vm_fault.c
+8-71 files

DragonFlyBSD/src 3d7bc73sys/platform/pc64/x86_64 pmap.c

kernel - Fix pmap wiring bug

* Fix a pmap wiring accounting bug.  The refactored wiring and pmap code
  expects only a single increment for a pmap wiring when the "W" bit
  transitions from 0 to 1, plus a count on the vm_page.

Found-by: Claude Sonnet 5 (aly)
DeltaFile
+2-3sys/platform/pc64/x86_64/pmap.c
+2-31 files

DragonFlyBSD/src b5c7a41sys/vfs/fifofs fifo_vnops.c

kernel - Fix lost wakeup in fifo_open()

* fifo_open() tests fi_readers, drops the fifo and vnode locks, then
  tsleeps.  A peer opening in that window bumps the counter and issues
  its wakeup before the sleeper is queued, so open(2) blocks forever
  with a peer already attached.  Both paths are affected.

* Queue with tsleep_interlock() before releasing the locks and sleep
  with PINTERLOCKED.

Reviewed-by: @dillon
DeltaFile
+4-2sys/vfs/fifofs/fifo_vnops.c
+4-21 files

DragonFlyBSD/src 12b64b8sys/netinet if_ether.c

if_ether: Reject invalid ARP packets to avoid kernel memory leaking

The ARP ingress parser arpintr() validates ar_hrd and ar_pro but never
validates ar_hln (hardware address length) or ar_pln (protocol address
length). The ARP reply builder in_arpreply() then uses these
attacker-controlled byte values as memcpy lengths when copying from
kernel-internal buffers that hold only 6 bytes (IF_LLADDR) or 4 bytes
(&taddr on stack). The over-read bytes fill the ARP reply mbuf, which is
transmitted back to the attacker. A single crafted ARP request from any
host on the same L2 segment leaks up to ~249 bytes of kernel heap and
~251 bytes of kernel stack.

Fix the bug by rejecting ARP packets with invalid ar_hln or ar_pln.

This patch is derived from FreeBSD:
- https://github.com/freebsd/freebsd-src/commit/09d3f8953e47a33d298a13b77eed55f54ae5247b
- https://github.com/freebsd/freebsd-src/commit/414676ba31117f4ddda936d0035398eb7dfdfa34
- https://github.com/freebsd/freebsd-src/commit/deb6bda6e373d7d01f43d5cc2d724dcecbae2039


    [3 lines not shown]
DeltaFile
+22-0sys/netinet/if_ether.c
+22-01 files

DragonFlyBSD/src 0b709f6sys/vm device_pager.c

vm: fix cdev pager object lifecycle and allocation race

cdev_pager_allocate() previously called cdev_pg_ctor before looking up
the object.  Repeated allocations therefore called a non-idempotent
constructor multiple times for one allocated vm_object, while the
destructor ran only once.

In addition, cdev_pager_allocate() could race with other threads
allocating an object.

This commit fixes both problems.  Reserve a newly allocated object in
the pager list with a NULL ops pointer while its constructor runs
outside dev_pager_mtx.  Concurrent lookup and allocation callers wait
for construction to finish.  Publish the ops pointer and wake them on
success; remove and mark the object dead before waking them on failure.
Use ops rather than dev as the construction sentinel because DragonFly
has valid NULL-handle pager users.

Derived-from: FreeBSD (commit e93404065177d6c909cd64bf7d74fe0d8df35edf)
GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/49
DeltaFile
+92-34sys/vm/device_pager.c
+92-341 files

DragonFlyBSD/src 67824a9sys/vm device_pager.c

vm: Clean up cdev_pager_allocate() a bit

* Introduce 'pindex' variable to clean up the code.
* Add KASSERT() to ensure the object type matches (obtained from FreeBSD)
DeltaFile
+7-4sys/vm/device_pager.c
+7-41 files

DragonFlyBSD/src 2c4f9absys/netinet tcp_input.c

tcp: Accept a RST whose sequence number is exactly RCV.NXT

An incoming RST is validated against a window anchored on last_ack_sent:
[last_ack_sent, last_ack_sent + rcv_wnd].  When the receiver has
delayed-ACKed data (rcv_nxt > last_ack_sent) and its receive window has
shrunk below that gap (rcv_nxt - last_ack_sent > rcv_wnd), a RST at
rcv_nxt, sits beyond the right edge last_ack_sent + rcv_wnd and is
silently dropped.  The caused the connection to stay ESTABLISHED
(half-open), leaving the application to time out and close.

Accept a RST whose sequence number is exactly rcv_nxt, matching the
long-deployed OpenBSD [1] and NetBSD [2] behaviour.

This does not weaken existing RST acceptance: DragonFly already accepts
any in-window RST (RFC 793, no challenge ACK), so an off-path attacker
gains nothing -- the change only stops legitimate RSTs at rcv_nxt from
being dropped.  The new behavior also conforms to RFC 793 and RFC 5961
(section 3.2).


    [6 lines not shown]
DeltaFile
+3-2sys/netinet/tcp_input.c
+3-21 files

DragonFlyBSD/src 4bb22ffsys/netinet if_ether.c

if_ether: Reject invalid ARP packets to avoid kernel memory leaking

The ARP ingress parser arpintr() validates ar_hrd and ar_pro but never
validates ar_hln (hardware address length) or ar_pln (protocol address
length). The ARP reply builder in_arpreply() then uses these
attacker-controlled byte values as memcpy lengths when copying from
kernel-internal buffers that hold only 6 bytes (IF_LLADDR) or 4 bytes
(&taddr on stack). The over-read bytes fill the ARP reply mbuf, which is
transmitted back to the attacker. A single crafted ARP request from any
host on the same L2 segment leaks up to ~249 bytes of kernel heap and
~251 bytes of kernel stack.

Fix the bug by rejecting ARP packets with invalid ar_hln or ar_pln.

This patch is derived from FreeBSD:
- https://github.com/freebsd/freebsd-src/commit/09d3f8953e47a33d298a13b77eed55f54ae5247b
- https://github.com/freebsd/freebsd-src/commit/414676ba31117f4ddda936d0035398eb7dfdfa34
- https://github.com/freebsd/freebsd-src/commit/deb6bda6e373d7d01f43d5cc2d724dcecbae2039


    [3 lines not shown]
DeltaFile
+22-0sys/netinet/if_ether.c
+22-01 files

DragonFlyBSD/src 7119b8asys/vm device_pager.c

vm: fix cdev pager object lifecycle and allocation race

cdev_pager_allocate() previously called cdev_pg_ctor before looking up
the object.  Repeated allocations therefore called a non-idempotent
constructor multiple times for one allocated vm_object, while the
destructor ran only once.

In addition, cdev_pager_allocate() could race with other threads
allocating an object.

This commit fixes both problems.  Reserve a newly allocated object in
the pager list with a NULL ops pointer while its constructor runs
outside dev_pager_mtx.  Concurrent lookup and allocation callers wait
for construction to finish.  Publish the ops pointer and wake them on
success; remove and mark the object dead before waking them on failure.
Use ops rather than dev as the construction sentinel because DragonFly
has valid NULL-handle pager users.

Derived-from: FreeBSD (commit e93404065177d6c909cd64bf7d74fe0d8df35edf)
GitHub-PR: https://github.com/DragonFlyBSD/DragonFlyBSD/pull/49
DeltaFile
+92-34sys/vm/device_pager.c
+92-341 files

DragonFlyBSD/src fb61005tools/regression/sockets/rst_rcvnxt_window_drop Makefile rst_rcvnxt_window_drop.c

regression: Add TCP RST receive window test

Note: root is required it it uses BPF to observe the client's final data
segment and a raw IPv4 socket to inject the RST at exactly RCV.NXT.

Before the fix in the last commit:
```
$ ./rst_rcvnxt_window_drop
net.inet.tcp.rfc1323: 1 -> 0
net.inet.tcp.delayed_ack: 1 -> 1
net.inet.tcp.recvbuf_auto: 1 -> 0
FAIL: connection still ESTABLISHED (RST at rcv_nxt was dropped), expected ECONNRESET
net.inet.tcp.rfc1323: 0 -> 1
net.inet.tcp.delayed_ack: 1 -> 1
net.inet.tcp.recvbuf_auto: 0 -> 1
```

After the fix:
```

    [12 lines not shown]
DeltaFile
+491-0tools/regression/sockets/rst_rcvnxt_window_drop/rst_rcvnxt_window_drop.c
+5-0tools/regression/sockets/rst_rcvnxt_window_drop/Makefile
+496-02 files

DragonFlyBSD/src f4823e0sys/netinet tcp_input.c

tcp: Accept a RST whose sequence number is exactly RCV.NXT

An incoming RST is validated against a window anchored on last_ack_sent:
[last_ack_sent, last_ack_sent + rcv_wnd].  When the receiver has
delayed-ACKed data (rcv_nxt > last_ack_sent) and its receive window has
shrunk below that gap (rcv_nxt - last_ack_sent > rcv_wnd), a RST at
rcv_nxt, sits beyond the right edge last_ack_sent + rcv_wnd and is
silently dropped.  The caused the connection to stay ESTABLISHED
(half-open), leaving the application to time out and close.

Accept a RST whose sequence number is exactly rcv_nxt, matching the
long-deployed OpenBSD [1] and NetBSD [2] behaviour.

This does not weaken existing RST acceptance: DragonFly already accepts
any in-window RST (RFC 793, no challenge ACK), so an off-path attacker
gains nothing -- the change only stops legitimate RSTs at rcv_nxt from
being dropped.  The new behavior also conforms to RFC 793 and RFC 5961
(section 3.2).


    [6 lines not shown]
DeltaFile
+3-2sys/netinet/tcp_input.c
+3-21 files

DragonFlyBSD/src b4510a6lib/libc/stdlib nmalloc.c

libc - Remove optimization that breaks malloc_usable_size() use cases

* The malloc implementation had an optimization meant to aid realloc()s
  whereby unused portions of large memory blocks could be munmap()d.

  However, lots of code uses the space returned by malloc_usable_size()
  without calling realloc() to notify libc that additional space is being
  used.  Leading to segmentation faults.

* Original proposed solution to make malloc_usable_size() aware of a
  prior munmap optimization does not completely fix the problem as excess
  space may be unmapped after such calls as well as before.

* Removing the optimization and letting the pager deal with any actually-dead
  excess space is the only option.  So that is what we do.

Reported-by: Several people
DeltaFile
+38-2lib/libc/stdlib/nmalloc.c
+38-21 files

DragonFlyBSD/src 6856d6bshare/mk bsd.crunchgen.mk

bsd.crunchgen.mk: Minor cleanups
DeltaFile
+13-15share/mk/bsd.crunchgen.mk
+13-151 files

DragonFlyBSD/src 52ff205initrd/rescue Makefile, share/mk bsd.crunchgen.mk

bsd.crunchgen.mk: Add CRUNCH_HOSTPROGS_${P} and fix awk in rescue

The usr.bin/awk consists of two subdirs: (1) 'awk' the actual program;
(2) 'maketab' a host program to help generate additional source.
Previously, the initrd/rescue/Makefile pointed the awk source to
'usr.bin/awk', and that caused the following warning:

```
crunchgen: rescue.conf: awk: warning: could not find any .o files
```

And pointing the source to 'usr.bin/awk/awk' couldn't fix it because the
required 'maketab' program would be unavailable.

To fix the problem as well as to extend the crunchgen framework, add the
CRUNCH_HOSTPROGS_${P} variable to specify the host programs required by
the build.  Implement the rules and specify the dependencies to build
the host programs.


    [2 lines not shown]
DeltaFile
+20-0share/mk/bsd.crunchgen.mk
+3-0initrd/rescue/Makefile
+23-02 files

DragonFlyBSD/src 250a8b4. Makefile_upgrade.inc, initrd Makefile

initrd: Merge rescue.libcrypto into rescue

After the last commit fixed the 'crc32' symbol conflict between
libhammer and libz, the merge of rescue.libcrypto and rescue only had
one conflict symbol: tilde_expand() from libprivate_ssh and
libprivate_edit.  Work around this symbol conflict by setting
libprivate_ssh an internal library for ssh/scp.

This merge reduces the rescue binaries size by ~1.1MB, from 12.1MB
(rescue 5.3MB + rescue.libcrypto 6.8MB) to 11MB.
DeltaFile
+106-53initrd/rescue/Makefile
+0-80initrd/rescue.libcrypto/Makefile
+1-1initrd/Makefile
+1-0Makefile_upgrade.inc
+108-1344 files

DragonFlyBSD/src 8cb3695lib/libhammer Makefile

libhammer(3): Exclude crc32.c and icrc32.c from sys/libkern

The user hammer(8) already includes these sources from sys/libkern, so
don't need to provide them in this library. More importantly, this
avoids the 'crc32' symbol conflict with libz.
DeltaFile
+4-7lib/libhammer/Makefile
+4-71 files

DragonFlyBSD/src addc09einitrd/rescue Makefile, initrd/rescue.libcrypto Makefile

crunchgen(1): Improve the handling of internal libraries

Previously, the `libs_int` and `special lib_int` commands specified the
internal libraries by their full paths, following the way of handling of
the shared libraries by `libs_so` and `special lib_so`. However, this
was actually a mistake because the internal libraries require building.
So it was lucky/hacky that rescue/rescue.libcrypto specified the
internal libraries with a combination of source directory and the
library name, e.g.,

```
CRUNCH_INTLIB_grep= ${CRUNCH_PATH_grep}/grep/libgreputils/libgreputils.a
CRUNCH_INTLIB_telnet= ${.CURDIR}/../../lib/libtelnet/libtelnet.a
```

To actually properly support internal libraries, we must explicitly the
source directories, as well as support build options.  To this end,
change the `libs_int` and `special lib_int` commands to only specify the
libraries names, and then extend the `special srcdir` to explicitly the

    [10 lines not shown]
DeltaFile
+153-51usr.bin/crunch/crunchgen/crunchgen.c
+69-18usr.bin/crunch/crunchgen/crunchgen.1
+40-28share/mk/bsd.crunchgen.mk
+2-1initrd/rescue/Makefile
+2-1initrd/rescue.libcrypto/Makefile
+266-995 files

DragonFlyBSD/src cc3bf8ashare/mk bsd.crunchgen.mk

bsd.crunchgen.mk: Minor cleanups
DeltaFile
+13-15share/mk/bsd.crunchgen.mk
+13-151 files

DragonFlyBSD/src 6e9501binitrd/rescue Makefile, share/mk bsd.crunchgen.mk

bsd.crunchgen.mk: Add CRUNCH_HOSTPROGS_${P} and fix awk in rescue

The usr.bin/awk consists of two subdirs: (1) 'awk' the actual program;
(2) 'maketab' a host program to help generate additional source.
Previously, the initrd/rescue/Makefile pointed the awk source to
'usr.bin/awk', and that caused the following warning:

```
crunchgen: rescue.conf: awk: warning: could not find any .o files
```

And pointing the source to 'usr.bin/awk/awk' couldn't fix it because the
required 'maketab' program would be unavailable.

To fix the problem as well as to extend the crunchgen framework, add the
CRUNCH_HOSTPROGS_${P} variable to specify the host programs required by
the build.  Implement the rules and specify the dependencies to build
the host programs.


    [2 lines not shown]
DeltaFile
+20-0share/mk/bsd.crunchgen.mk
+3-0initrd/rescue/Makefile
+23-02 files

DragonFlyBSD/src 8410ea0usr.bin/crunch/crunchgen crunchgen.c, usr.bin/crunch/crunchide crunchide.c

crunchgen(1): Remove the unneeded '-dc' linker flag

crunchide(1) does not hide symbols by making them local for many years.
We've also been using '-fno-common' compiler flag for a long time. So
the '-dc' linker flag is obsolete. Just remove it.

Obtained-from: FreeBSD (https://reviews.freebsd.org/D34215)
DeltaFile
+2-4usr.bin/crunch/crunchide/crunchide.c
+1-2usr.bin/crunch/crunchgen/crunchgen.c
+3-62 files