kernel: Refactor newvers.sh script
* Require and directly use 'KERN_IDENT' from the environment. This
avoids the 'make -V KERN_IDENT' command and thus fix the following
warning from bmake since the last upgrade to 20260619:
```
make[3]: warning: Invalid internal option "-J" in "/usr/obj/usr/src/sys/ALY"; see the manual page
```
* Leverage the new tools/gencopyright.sh script to generate the
copyright header.
* Simplify the awk command that extracts '__DragonFly_version' from
<sys/param.h> (referred to FreeBSD).
* Clean up code and styles.
include: Rewrite generation of <osreldate.h>
* Add the new tools/gencopyright.sh script to generate the copyright
header. Prefer the copyright year extracted from top-level COPYRIGHT,
similar to FreeBSD's.
* Directly extract the __DragonFly_version from <sys/param.h> as RELDATE
instead of calling newvers.sh. As a result, no need to clean up the
extra-generated files: version, vers.c and vers.txt.
By the way, this also avoids a few bmake warnings appeared after the
recent bmake upgrade (to 20260619):
```
make[2]: warning: Invalid internal option "-J" in "/usr/src"; see the manual page
make[2]: warning: Invalid internal option "-J" in "/usr/src"; see the manual page
make[2]: warning: Invalid internal option "-J" in "/usr/src"; see the manual page
make[5]: warning: Invalid internal option "-J" in "/usr/obj/usr/src/world_x86_64/usr/src/include"; see the manual page
make[2]: warning: Invalid internal option "-J" in "/usr/src"; see the manual page
make[2]: warning: Invalid internal option "-J" in "/usr/src"; see the manual page
[4 lines not shown]
kernel: Change ip6_sprintf() not to use static buffers
Now the caller must pass a buffer of size at least INET6_ADDRSTRLEN.
Derived-from: FreeBSD (commit 1d54aa3ba94f4d9883b0746ce45123d5b5be773b)
jail: Fix potential buffer overflow in sysctl_jail_list()
sysctl_jail_list() allocates a buffer of size = count*1024, and then
uses ksnprintf() to format the jail information and advance the write
position. However, ksnprintf() returns the would-be length (i.e., the
number of bytes would be written if the buffer is big enough). So a jail
that has a very long path and/or many IPs would overflow the allocated
buffer.
Fix the bug by correctly handling the return value of ksnprintf().
GitHub-PR: #45
Reported-by: Nathan Sapwell (jewbird)
kernel: Add WARNS_AUDIT for the kernel.
Analogous to world. If specified, any warning options that we normally
disable in buildkernel using -Wno-* will be active.
While here, move -Wold-style-declaration from CFLAGS to CWARNFLAGS.
libtcplay,cryptdisks: Fix GCC 12's -Wmaybe-uninitialized false positive
This reverts commit b77d373551e67a9ce62d8063b8dd7bafd6f9e360 and
correctly fix/silence the GCC 12's -Wmaybe-uninitialized warning, which
is actually a false positive.
GCC's rationale is: the memory 'mem' refers to was not initialized and
may be used in mlock(). The 'mem' parameter is passed as 'const void *',
so mlock() is impossible to initialize the memory.
Discussed-with: swildner
See-also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118588#c1
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)
vm: Remove duplicate reference in cdev_pager_allocate()
The code was updated in 2013 [1] to bring in various changes from
FreeBSD, but left this duplicate reference. Remove the erroneous
vm_object_reference_locked() call.
[1] kernel: Port new device_pager interface from FreeBSD
commit f2c2051ee473577d22178d55f782ceebbd88d58f
GitHub-PR: #49
Credit: LI Leding
wg: Destroy newly created peers on failure
Previously, a newly created peer was not destroyed even if there were
errors in configuring it, e.g., invalid AllowedIPs. The rationale was
that the user could correct the error by issuing another 'ifconfig'
command with the fixed arguments.
Now destroy the new peer if an error occurs, making a complex 'ifconfig'
command that adds a peer atomic. This matches the behavior of FreeBSD.
As part of this change, refactor wg_ioctl_set() by extracting
wg_ioctl_set_peer() to handle a single peer, and add 'const' qualifiers
where appropriate.
kernel: Disable build-ID for vkernel(7) and fix build
Vkernel(7) doesn't use a linker script, so it's not easy to define
__build_id_{start,end} for it.
A solution would be to locate the ELF in memory, parse and walk the
program headers to find the ".note.gnu.build-id" section.
Reported-by: Michael Neumann
wg: Return ENETUNREACH when transmitting to a non-existent peer
Do the same thing as FreeBSD and OpenBSD.
Obtained-from: FreeBSD (https://reviews.freebsd.org/D44582)