FreeBSD/src dcae0f7sys/amd64/amd64 machdep.c, sys/amd64/include stack.h

sys: Consistently use ptoa() with td_kstack_pages

Suggested by:   kib
Reviewed by:    kib, andrew (arm changes)
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+1-1sys/amd64/include/stack.h
+1-1sys/arm/include/stack.h
+1-1sys/arm64/include/stack.h
+1-1sys/powerpc/include/stack.h
+1-1sys/riscv/include/stack.h
+1-1sys/amd64/amd64/machdep.c
+6-66 files

FreeBSD/src 4f876cesys/riscv/include stack.h, sys/riscv/riscv vm_machdep.c locore.S

riscv64: Move pcb out of kstack into a new UMA zone

Similar to arm64, riscv's pcb embeds a copy of the floating point
registers and is too large to store directly in struct mdthread as is
done on amd64.  Instead, use a separate UMA zone for pcbs.  riscv's
floating point state is not as large as arm64's, so its pcb is also
somewhat smaller and a single 4k page can hold 6 pcbs.

Reviewed by:    kib, jrtc27
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+15-5sys/riscv/riscv/vm_machdep.c
+2-4sys/riscv/include/stack.h
+2-2sys/riscv/riscv/locore.S
+2-1sys/riscv/riscv/machdep.c
+0-1sys/riscv/riscv/genassym.c
+21-135 files

FreeBSD/src 8b9023csys/amd64/include stack.h, sys/i386/i386 machdep.c vm_machdep.c

sys: Add td_kstack_top inline helper function

This function returns a pointer to the top of the kstack.

Reviewed by:    kib, andrew (arm changes)
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+6-0sys/sys/proc.h
+2-4sys/amd64/include/stack.h
+2-2sys/i386/i386/machdep.c
+2-2sys/powerpc/powerpc/machdep.c
+2-2sys/powerpc/powerpc/exec_machdep.c
+2-2sys/i386/i386/vm_machdep.c
+16-1213 files not shown
+29-3719 files

FreeBSD/src fce5953sys/arm64/arm64 swtch.S

arm64 locore: Fix a comment typo: Of -> If

Reviewed by:    kib, andrew
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+1-1sys/arm64/arm64/swtch.S
+1-11 files

FreeBSD/src d0b10dfsys/arm64/arm64 vm_machdep.c locore.S, sys/arm64/include stack.h

arm64: Move pcb out of kstack into a new UMA zone

This is similar to commit 5e921ff49ea8bb70506248a4675894729cdad8c2
which moved the pcb for amd64, but a bit different.  arm64's pcb is
much larger (over 1KB!) than amd64's since it still embeds FP
registers.  Moving the pcb out of the kstack frees up that much
additional kstack space.  Unlike amd64 however, embedding the pcb in
struct mdthread is not practical as the resulting struct thread would
grow such that UMA would now store 1 thread per 4k page instead of 2
threads per page.  By using a separate UMA zone for pcbs, 2 struct
threads can continue to fit in a single 4k page, and 3 pcbs can fit in
another 4k page.

Reviewed by:    kib, jrtc27, andrew
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+14-4sys/arm64/arm64/vm_machdep.c
+2-4sys/arm64/include/stack.h
+1-2sys/arm64/arm64/locore.S
+2-1sys/arm64/arm64/machdep.c
+0-2sys/arm64/arm64/genassym.c
+19-135 files

FreeBSD/src f7524d8sys/amd64/amd64 vm_machdep.c machdep.c, sys/amd64/include md_var.h

amd64: Inline set_top_of_stack_td into cpu_thread_new_kstack

Reviewed by:    kib
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+2-8sys/amd64/amd64/vm_machdep.c
+1-1sys/amd64/amd64/machdep.c
+0-1sys/amd64/include/md_var.h
+3-103 files

FreeBSD/src 2893bb7share/man/man9 cpu_machdep.9, sys/amd64/amd64 vm_machdep.c

cpu_thread_new_kstack: Introduce new MD callback

Previously, the cpu_thread_alloc callback was invoked each time a
kernel stack was allocated for a thread.  This included thread
creation, but it was also invoked if a recycled thread had to allocate
a new kstack.  This means that cpu_thread_alloc could be called
multiple times for a single thread, but cpu_thread_free is only called
once.  Not only that, but the cpu_thread_alloc callback can't tell if
it is being invoked on a new thread object, or a recycled thread.
Calling *_alloc multiple times on an object is also atypical for
kernel APIs.

As a result of this confusion, amd64 was potentially leaking an XSAVE
buffer each time a new kstack was allocated for an existing thread,
since cpu_thread_alloc for amd64 always allocated a new XSAVE buffer.
In practice, this edge case is probably rare.  A process object needs
to be recycled where either the new or old process is a kernel process
with a non-default kernel stack size.


    [11 lines not shown]
DeltaFile
+22-6share/man/man9/cpu_machdep.9
+7-2sys/amd64/amd64/vm_machdep.c
+5-1sys/arm64/arm64/vm_machdep.c
+2-3sys/riscv/riscv/vm_machdep.c
+5-0sys/arm/arm/vm_machdep.c
+5-0sys/i386/i386/vm_machdep.c
+46-124 files not shown
+55-1310 files

FreeBSD/src 59d67f2sys/amd64/amd64 vm_machdep.c, sys/i386/i386 vm_machdep.c

amd64/i386: Remove dead code to clear XSAVE header

If XSAVE is being used, the XSAVE header will be overwritten either by
copying it from the parent thread in copy_thread for user threads, or
by a fresh copy from fpu/npx_initialstate on the first use of the FPU
for kernel threads.

Reviewed by:    kib
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+0-6sys/amd64/amd64/vm_machdep.c
+0-6sys/i386/i386/vm_machdep.c
+0-122 files

FreeBSD/src 187b46esys/amd64/amd64 vm_machdep.c, sys/arm/arm vm_machdep.c

cpu_fork: Remove redundant assignments to td_pcb and td_frame

cpu_thread_alloc() already sets these fields anytime td_kstack changes.

Reviewed by:    kib, andrew (arm changes)
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+5-7sys/i386/i386/vm_machdep.c
+2-7sys/arm64/arm64/vm_machdep.c
+2-6sys/arm/arm/vm_machdep.c
+2-6sys/powerpc/powerpc/vm_machdep.c
+1-5sys/amd64/amd64/vm_machdep.c
+0-2sys/riscv/riscv/vm_machdep.c
+12-336 files

FreeBSD/src 860aaecsys/amd64/amd64 machdep.c

amd64: Don't set an initial FPU state save size

This used to be needed to initialize the pcb pointer when the pcb was
allocated on the kstack.

Reviewed by:    kib
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+0-1sys/amd64/amd64/machdep.c
+0-11 files

FreeBSD/src d01e5afsys/arm64/include pcpu.h

arm64: Remove unneeded declaration from <machine/pcpu.h>

Reviewed by:    kib, andrew
Sponsored by:   AFRL, DARPA
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+0-1sys/arm64/include/pcpu.h
+0-11 files

FreeBSD/src a1e07f2sys/arm64/arm64 swtch.S

arm64: Adjust the kernel stack pointer at the end of fork_trampoline

All other paths that return from the kernel to userspace pop the user
trapframe off of the kernel stack pointer before returning to
userspace in restore_registers.  fork_trampoline was missing this, so
all of the user faults after fork pushed another trapframe leaving a
trapframe's worth of wasted space on the kstack.

This would be fatal after a future change to remove duplicate
initialization of td_frame in cpu_fork() as without this fix each time
a thread was recycled it would "lose" another trapframe's worth of
space.

Reviewed by:    kib, andrew
Pull Request:   https://ron-dev.freebsd.org/FreeBSD/src/pulls/23
DeltaFile
+2-0sys/arm64/arm64/swtch.S
+2-01 files

FreeBSD/src 36ab14dsys/netpfil/ipfilter/netinet ip_state.c

ipfilter: Fix NULL dereferences in ipf_checkicmp6matchingstate()

Add NULL checks for ic6 (the ICMPv6 header pointer from fin->fin_dp)
and oic (the inner ICMPv6 header from ofin.fin_dp after ipf_makefrip).
These pointers can be NULL when processing malformed ICMPv6 error
packets with extension headers.

Also fix the length validation: the original check (fin->fin_plen <
sizeof(ip6_t)) could never trigger because an earlier check already
ensures fin->fin_plen >= ICMP6ERR_MINPKTLEN (48). Replace with a proper
check that fin->fin_dlen contains at least ICMPERR_ICMPHLEN +
sizeof(ip6_t) bytes to ensure sufficient data exists for both the
ICMPv6 error header and the embedded IPv6 header.

PR:             288333
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2214
Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>

(cherry picked from commit c028080749c09e68c555155df0e9f681ba63c6ae)
DeltaFile
+9-1sys/netpfil/ipfilter/netinet/ip_state.c
+9-11 files

FreeBSD/src f296b1fsys/netpfil/ipfilter/netinet fil.c

ipfilter: Validate length before checksum

Validate the length of the packet listed in the mbuf is the same as
the calculated packet length. If not reject the packet and bump the
bad packet stat.

PR:             295198
Differential Revision:  https://reviews.freebsd.org/D57095

(cherry picked from commit 8dfb0805fc31cd78940429ab0560dae7e8ab6536)
DeltaFile
+13-4sys/netpfil/ipfilter/netinet/fil.c
+13-41 files

FreeBSD/src fb0729bsys/netpfil/ipfilter/netinet fil.c

ipfilter: Add NULL check for fin_dp in ICMP packet handlers

Add NULL checks for fin->fin_dp in ipf_pr_icmp6() and ipf_pr_icmp()
before dereferencing. When processing packets with IPv6 extension
headers, ipf_pr_pullup() can succeed but fin->fin_dp may still be NULL
due to extension header processing leaving insufficient data for the
protocol header.

PR:             288333
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2214
Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>

(cherry picked from commit 68ed81631afa20c07883f7f60343f6da8397ee41)
DeltaFile
+4-0sys/netpfil/ipfilter/netinet/fil.c
+4-01 files

FreeBSD/src a98f5fasys/netpfil/ipfilter/netinet fil.c

ipfilter: Add NULL check for fin_m in ipf_pr_icmp6()

Add NULL check for fin->fin_m before calling M_LEN() in the ICMPv6
error handling code path. When ipf_checkicmp6matchingstate() calls
ipf_makefrip() with a synthesized fr_info_t that has fin_m set to
NULL, the subsequent call to ipf_pr_ipv6hdr() can reach ipf_pr_icmp6()
which would crash when trying to access the mbuf via M_LEN().

PR:             288333
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2214
Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>

(cherry picked from commit cdc40489a7a617b742e295cf9005b3569b45e823)
DeltaFile
+3-0sys/netpfil/ipfilter/netinet/fil.c
+3-01 files

FreeBSD/src 2349f5asys/netpfil/ipfilter/netinet ip_state.c

ipfilter: Fix NULL dereferences in ipf_checkicmp6matchingstate()

Add NULL checks for ic6 (the ICMPv6 header pointer from fin->fin_dp)
and oic (the inner ICMPv6 header from ofin.fin_dp after ipf_makefrip).
These pointers can be NULL when processing malformed ICMPv6 error
packets with extension headers.

Also fix the length validation: the original check (fin->fin_plen <
sizeof(ip6_t)) could never trigger because an earlier check already
ensures fin->fin_plen >= ICMP6ERR_MINPKTLEN (48). Replace with a proper
check that fin->fin_dlen contains at least ICMPERR_ICMPHLEN +
sizeof(ip6_t) bytes to ensure sufficient data exists for both the
ICMPv6 error header and the embedded IPv6 header.

PR:             288333
MFC after:      1 week
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2214
Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>

(cherry picked from commit c028080749c09e68c555155df0e9f681ba63c6ae)
DeltaFile
+9-1sys/netpfil/ipfilter/netinet/ip_state.c
+9-11 files

FreeBSD/src 77dd10bsys/netpfil/ipfilter/netinet fil.c

ipfilter: Validate length before checksum

Validate the length of the packet listed in the mbuf is the same as
the calculated packet length. If not reject the packet and bump the
bad packet stat.

PR:             295198
Differential Revision:  https://reviews.freebsd.org/D57095

(cherry picked from commit 8dfb0805fc31cd78940429ab0560dae7e8ab6536)
DeltaFile
+13-4sys/netpfil/ipfilter/netinet/fil.c
+13-41 files

FreeBSD/src fefcd49sys/netpfil/ipfilter/netinet fil.c

ipfilter: Add NULL check for fin_m in ipf_pr_icmp6()

Add NULL check for fin->fin_m before calling M_LEN() in the ICMPv6
error handling code path. When ipf_checkicmp6matchingstate() calls
ipf_makefrip() with a synthesized fr_info_t that has fin_m set to
NULL, the subsequent call to ipf_pr_ipv6hdr() can reach ipf_pr_icmp6()
which would crash when trying to access the mbuf via M_LEN().

PR:             288333
MFC after:      1 week
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2214
Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>

(cherry picked from commit cdc40489a7a617b742e295cf9005b3569b45e823)
DeltaFile
+3-0sys/netpfil/ipfilter/netinet/fil.c
+3-01 files

FreeBSD/src b2076f3sys/netpfil/ipfilter/netinet fil.c

ipfilter: Add NULL check for fin_dp in ICMP packet handlers

Add NULL checks for fin->fin_dp in ipf_pr_icmp6() and ipf_pr_icmp()
before dereferencing. When processing packets with IPv6 extension
headers, ipf_pr_pullup() can succeed but fin->fin_dp may still be NULL
due to extension header processing leaving insufficient data for the
protocol header.

PR:             288333
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2214
Signed-off-by:  Teddy Engel <engel.teddy at gmail.com>

(cherry picked from commit 68ed81631afa20c07883f7f60343f6da8397ee41)
DeltaFile
+4-0sys/netpfil/ipfilter/netinet/fil.c
+4-01 files

FreeBSD/src bd15d6econtrib/libarchive/libarchive archive_string.c

libarchive: Force GNU iconv compatibility on FreeBSD

When libarchive is compiled with FreeBSD's native iconv instead of
libiconv, as happens with libarchive in the base system, we need to
configure iconv(3) to handle invalid sequences by returning -1, as
iconv_strncat_in_locale() assumes GNU iconv semantics.

This corresponds to upstream PR 3056.

PR:             294577
MFC after:      1 week
DeltaFile
+11-1contrib/libarchive/libarchive/archive_string.c
+11-11 files

FreeBSD/src e9346d1lib/libutil login.conf.5

login.conf(5): Add missing resource limits

While here, reorder the table.

PR:             295618
MFC after:      1 week
Reviewed by:    olce
Differential Revision:  https://reviews.freebsd.org/D57258
DeltaFile
+6-5lib/libutil/login.conf.5
+6-51 files

FreeBSD/src 210bee0libexec/tftpd tftp-io.c

tftpd: Simplify packet drop macro

The first argument is always the function name, for which we can simply
use __func__.  This leaves only the optional return value, so we can use
a single variadic macro instead of two nearly-identical copies.

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57076

(cherry picked from commit 76c3387024b40c2e28ed2d1bb64b3a14371c3c0b)
DeltaFile
+23-28libexec/tftpd/tftp-io.c
+23-281 files

FreeBSD/src 2d9d040libexec/tftpd tftp-io.c

tftpd: Add missing bounds checks

In send_[rw]rq(), we were using strlcpy() to avoid overflowing our
packet buffer, then failing to check the result and blithely advancing
our pointer by the full length.

Luckily, this code is only ever used by tftp(1), not tftpd(8).

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57075

(cherry picked from commit 933893771344e1647eeda152016b938fdc30ccdc)
DeltaFile
+32-26libexec/tftpd/tftp-io.c
+32-261 files

FreeBSD/src 6764267usr.bin/tftp/tests tftp_test.sh

tftp: Add test case with over-long URL

This adds a test case that passes a very long URL on the command line,
which would previously have resulted in a benign buffer overflow in
urihandling(), detectable only by compiling tftp with ASAN enabled.

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57074

(cherry picked from commit b94689d036c5f5bdc04d080ff7dd5d0e9df9b8d4)
DeltaFile
+24-0usr.bin/tftp/tests/tftp_test.sh
+24-01 files

FreeBSD/src 12e8c16usr.bin/tftp tftp.c main.c

tftp: Fix handling of port name or number

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57105

(cherry picked from commit 47e4571df15804fe2b010a3c82b22691d80ee680)
DeltaFile
+22-18usr.bin/tftp/tftp.c
+4-3usr.bin/tftp/main.c
+26-212 files

FreeBSD/src ddd16aeusr.bin/tftp main.c

tftp: Close files when we're done with them

Also, delete the file we created if receiving it failed.

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57071

(cherry picked from commit 29351335704e39ce3ca09c528d534c7898bbdc2c)
DeltaFile
+8-2usr.bin/tftp/main.c
+8-21 files

FreeBSD/src e1703e1usr.bin/tftp main.c tftp.c

tftp: Style cleanup

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57073

(cherry picked from commit 29aaaa5e6660310311fe443d8792b31181e1dd3c)
DeltaFile
+20-36usr.bin/tftp/main.c
+20-20usr.bin/tftp/tftp.c
+40-562 files

FreeBSD/src 13f6bf4usr.bin/tftp main.c

tftp: Replace fgets with getline

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57072

(cherry picked from commit 5fd928cf1cef21e0fc20ab7c2be156a0eeecdf40)
DeltaFile
+45-45usr.bin/tftp/main.c
+45-451 files

FreeBSD/src 2d0b4eeusr.bin/tftp main.c

tftp: Simplify URI handling

* No need to copy our argument into a new buffer; it is writeable and
  will not be reused after we return.

* Instead of constructing the string "get path" and then splitting it
  into an argument vector, just construct the vector directly.  This
  avoid potentially overrunning the buffer.

* Call settftpmode() just once, with either the default mode or the
  user-provided value we already validated.

* Use errx() instead of fprintf(stderr) + exit().

Reported by:    Moyao, Minghao Fu
MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57070

(cherry picked from commit a4b17594181502cea38ab0d8b2a9a10782286334)
DeltaFile
+12-20usr.bin/tftp/main.c
+12-201 files