Commit graph

24537 commits

Author SHA1 Message Date
Gleb Smirnoff
1bda3fae78 tcp: don't ever return ECONNRESET on close(2)
The SUS doesn't mention this error code as a possible one [1]. The FreeBSD
manual page specifies a possible ECONNRESET for close(2):

[ECONNRESET]	The underlying object was a stream socket that was
		shut down by the peer before all pending data was
		delivered.

In the past it had been EINVAL (see 21367f630d), and this EINVAL was
added as a safety measure in 623dce13c6.  After conversion to
ECONNRESET it had been documented in the manual page in 78e3a7fdd5, but
I bet wasn't ever tested to actually be ever returned, cause the
tcp-testsuite[2] didn't exist back then.  So documentation is incorrect
since 2006, if my bet wins.  Anyway, in the modern FreeBSD the condition
described above doesn't end up with ECONNRESET error code from close(2).
The error condition is reported via SO_ERROR socket option, though.  This
can be checked using the tcp-testsuite, temporarily disabling the
getsockopt(SO_ERROR) lines using sed command [3].  Most of these
getsockopt(2)s are followed by '+0.00 close(3) = 0', which will confirm
that close(2) doesn't return ECONNRESET even on a socket that has the
error stored, neither it is returned in the case described in the manual
page.  The latter case is covered by multiple tests residing in tcp-
testsuite/state-event-engine/rcv-rst-*.

However, the deleted block of code could be entered in a race condition
between close(2) and processing of incoming packet, when connection had
already been half-closed with shutdown(SHUT_WR) and sits in TCPS_LAST_ACK.
This was reported in the bug 146845.  With the block deleted, we will
continue into tcp_disconnect() which has proper handling of INP_DROPPED.

The race explanation follows.  The connection is in TCPS_LAST_ACK.  The
network input thread acquires the tcpcb lock first, sets INP_DROPPED,
acquires the socket lock in soisdisconnected() and clears SS_ISCONNECTED.
Meanwhile, the syscall thread goes through sodisconnect() which checks for
SS_ISCONNECTED locklessly(!).  The check passes and the thread blocks on
the tcpcb lock in tcp_usr_disconnect().  Once input thread releases the
lock, the syscall thread observes INP_DROPPED and returns ECONNRESET.

- Thread 1: tcp_do_segment()->tcp_close()->in_pcbdrop(),soisdisconnected()
- Thread 2: sys_close()...->soclose()->sodisconnect()->tcp_usr_disconnect()

Note that the lockless operation in sodisconnect() isn't correct, but
enforcing the socket lock there will not fix the problem.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/
[2] https://github.com/freebsd-net/tcp-testsuite
[3] sed -i "" -Ee '/\+0\.00 getsockopt\(3, SOL_SOCKET, SO_ERROR, \[ECONNRESET\]/d' $(grep -lr ECONNRESET tcp-testsuite)

PR:			146845
Reviewed by:		tuexen, rrs, imp
Differential Revision:	https://reviews.freebsd.org/D48148

(cherry picked from commit 053a988497342a6fd0a717cc097d09c23f83e103)
2025-03-31 10:31:21 -07:00
Konstantin Belousov
192aae0a9f libprocstat: constify psc_type_info[]
(cherry picked from commit debcd4c05701be0ff48c6b350ed6b3a80e5f0b1f)
2025-03-31 05:41:32 +03:00
Konstantin Belousov
8056c96491 libprocstat: change psc_type_info array to use designated initializers
(cherry picked from commit ba2fb6b367fd513ea5812a496254d3a05ec380b8)
2025-03-31 05:41:32 +03:00
Enji Cooper
c08ec13bcc lib/libsbuf/tests: reformat with clang-format
This change is being done first so any functional changes from the tests
will be clearer to reviewers.

No functional change intended.

MFC after:	2 weeks
Ref:	 https://reviews.freebsd.org/D47826

(cherry picked from commit 991bd461625a2c521d5be4fd6938deed57f60972)
2025-03-26 14:13:54 -07:00
Ahmad Khalifa
2ce4f02182 libc/stdio: Increase BUF in vfprintf.c and vfwprintf.c
With the %b format specifier we need enough space to write a uintmax_t
in binary.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1400

(cherry picked from commit d4f9e326393e3298062a58338e2c94ef6baff8b5)
2025-03-25 19:28:39 -06:00
Andrew Gallatin
b429d50df9 ifconfig: fix reporting optics on most 100g interfaces
This fixes a bug where optics on 100G and faster NICs
were not properly reported.

(cherry picked from commit 709348c21351a783ff0025519d1f7cf884771077)
2025-03-20 11:27:08 -04:00
Konstantin Belousov
dc1467c68d amd64 csu: microoptimize startup
(cherry picked from commit cb991a228179639cc0568fdd5d4b4b07b6f47b5a)
2025-03-11 02:59:11 +02:00
Konstantin Belousov
0f78d64334 open.2: minor editing
(cherry picked from commit e2dd73cf45a6a8d97131bdbe512ab1ff63121d85)
2025-03-07 07:23:08 +02:00
artembunichev
3416ed9d07 open.2: add separate paragraph for O_CREAT
PR:	284353

(cherry picked from commit 8cebb0630046a8eb10c551a856397ed230e73833)
2025-03-07 07:23:08 +02:00
Christos Margiolis
311b84540e mixer(3): Do not skip devices with no volume control
Some devices might not have a software volume control, but still be
able to be set as recording sources.

PR:		279787
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D48730

(cherry picked from commit f121de8fbcbc8aa82f9fb59039c502406b7c88b6)
2025-03-04 16:46:07 +01:00
Stefan Eßer
2d1b1c1aaa libc/gen/fts.c: fix assignment
Fixes:		e59991206b fts(3): be less strict when automount does its job under us walking autofs mount

(cherry picked from commit ab6a311c720e93c860d3dd4a335264d725db7a0d)
2025-03-04 06:19:08 +02:00
Konstantin Belousov
9460df3573 fts(3): be less strict when automount does its job under us walking autofs mount
PR:	284914

(cherry picked from commit e59991206b1463b7e85cc8aafde7f1dc03fcedcf)
2025-03-04 06:19:08 +02:00
Konstantin Belousov
69b6dc0b92 libc/gen: split user-visible opendir()-like functions into separate source files
(cherry picked from commit d40daefca64750c1076822bdbd3c409a9519f513)
2025-03-04 06:19:08 +02:00
John Baldwin
f31e3922bd open.2: Editorial pass
- Use a typical tagged list for the open flags instead of a literal
  block.  This permits using markup in the flag descriptions.  Also,
  drop the offset to avoid indenting the entire list.

- Note that O_RESOLVE_BENEATH only applies to openat(2)

- Use a clearer description of O_CLOEXEC (what it means, not the
  internal flag it sets)

- Note that exactly one permission flag is required.

- Split up a paragraph on various flags so that each flag gets its own
  paragraph.  Some flags already had their own paragraph, so this is
  more consistent.  It also makes it clearer which flag a sentence is
  talking about when a flag has more than one sentence.

- Appease some errors from igor and man2ps

- In the discussion about a returned directory descriptor opened with
  O_SEARCH, avoid the use of Fa fd since the descriptor in question is
  a return value and not an argument to open or openat.

- Various and sundry markup and language tweaks

Reviewed by:	kib, emaste
Differential Revision:	https://reviews.freebsd.org/D48253

(cherry picked from commit 826509a3c3642db6a110f8f43ae8860c40c72ad2)
2025-03-03 11:56:20 -05:00
John Baldwin
8e8058b737 kqueue.2: Editorial pass
- Use consistent language to describe user values unchanged by the
  kernel.

- Replace passive language with active in a few places.

- Add a history note for kqueuex() and kqueue1().

- Add an MLINK and synopsis for kqueue1().

- Various wording and markup tweaks.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D48203

(cherry picked from commit 9b1585384d53d0f9cc4585a6efd8cc95116407d7)
2025-03-03 11:56:20 -05:00
Isaac Freund
f183965bb8 pkgbase: fix inclusion of tests in ssh, bsnmp, clibs-dev
Currently, files that belong in the tests package are included in the
ssh, bsnmp, and clibs-dev packages:

ssh.plist
24:@dir(root,wheel,0755,) /usr/tests/secure/libexec
25:@(root,wheel,0444,) /usr/tests/secure/libexec/Kyuafile

bsnmp.plist
82:@dir(root,wheel,0755,) /usr/tests/lib/libbsnmp
83:@(root,wheel,0444,) /usr/tests/lib/libbsnmp/Kyuafile
84:@(root,wheel,0555,) /usr/tests/lib/libbsnmp/bsnmpd_test

clibs-dev.plist
2518:@dir(root,wheel,0755,) /usr/tests/lib/csu
2519:@(root,wheel,0444,) /usr/tests/lib/csu/Kyuafile

This is caused by the PACKAGE=foo assignment in foo/Makefile.inc which
overrides the default PACKAGE?=tests in bsd.test.mk.

To fix this, instead use PACKAGE?=foo in foo/Makefile.inc and set
PACKAGE=tests in foo/tests/Makefile.

PR:		249144
Reviewed by:	bapt, emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47025

(cherry picked from commit 3a56015a2f5d630910177fa79a522bb95511ccf7)
2025-02-27 14:45:40 -05:00
Alexander Ziaee
6875767cf2
recv.2: Improve style in RETURN VALUES
Reported by:		des
MFC after:		3 days
Fixes:			571df2c64a3c1 (Explain how recv functions can)
Reviewed by:		mhorne, des
Approved by:		mhorne (mentor)
Differential Revision:	https://reviews.freebsd.org/D48995

(cherry picked from commit 7c3c8605d62f5d27a5228a3787aae6e573f77d59)
2025-02-26 20:44:37 -05:00
Felix Johnson
2200da5fe0
recv.2: Explain how recv functions can return 0
Clarify the RETURN VALUES section with improved structure,
the condition of the return value 0, and the setting of errno.

PR:			174581
Reviewed by:		jhb, ziaee
Approved by:		mhorne (mentor)
Differential Revision:	https://reviews.freebsd.org/D48955

(cherry picked from commit 571df2c64a3c1af1fe011303ec08e391e887ecbc)
2025-02-26 20:44:28 -05:00
Konstantin Belousov
b69399170b statfs.2: document missing user-visible MNT flags
(cherry picked from commit e951247a983daf7814d06e9e49bdd503ceaa0b68)
2025-02-23 02:30:51 +02:00
Konstantin Belousov
28b1a5a6cd statfs.2: order MNT flags alphabetically
(cherry picked from commit 0738cd9766a570e085831f6241387baa35cd64a3)
2025-02-23 02:30:51 +02:00
Konstantin Belousov
743cd4c1af statfs.2: remove dead comment
(cherry picked from commit 13b92ae9655deb22c3ad89f1e90e26f2f1da9961)
2025-02-23 02:30:51 +02:00
Konstantin Belousov
efa0994821 statfs.2: uncomment and describe MNT_IGNORE
(cherry picked from commit 270542d95d0d931ebdd369f4f78871828502d486)
2025-02-23 02:30:50 +02:00
Mark Johnston
b0f2df45e7 socket: Add an option to retrieve a socket's FIB number
The SO_SETFIB option can be used to set a socket's FIB number, but there
is no way to retrieve it.  Rename SO_SETFIB to SO_FIB and implement a
handler for it for getsockopt(2).

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48834

(cherry picked from commit ee951eb59f2136a604e3fbb12abf8d8344da0c99)
2025-02-21 01:04:50 +00:00
Ed Maste
6789b9f630 libc: Fix getentropy POSIX 2024 conformance issues
GETENTROPY_MAX should be defined in limits.h.  EINVAL is the return
value for buflen > GETENTROPY_MAX.

PR:		282783
Reviewed by:	markj, asomers, jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47689
2025-02-20 09:13:25 -05:00
Li-Wen Hsu
ef3ed0726f Canonicalize the name of the FreeBSD Foundation
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit dab59af3bcc7cb7ba01569d3044894b3e860ad56)
2025-02-19 09:58:47 -05:00
Huwyler
0ea2924f81 libsecureboot: Report failure for unsupported hash algorithm
Reviewed by:	sjg
Pull request:	https://github.com/freebsd/freebsd-src/pull/1574

(cherry picked from commit caaeab697bf98bf96e2fa8cb4a1e22240511fbcc)
2025-02-18 13:41:07 -05:00
Jose Luis Duran
f9e98800af
libopencsd: Remove extra slashes
Remove extra slashes that end up in the metalog.  These double slashes
can produce an invalid specification file if there are subdirectories
down the hierarchy when sorted.

For example, consider the following metalog excerpt:

    ./base/aaa type=dir
    ./base//aaa/bbb type=dir

If sorted, would turn out:

    ./base//aaa/bbb type=dir
    ./base/aaa type=dir

Apparently missing the ./base/aaa directory in the specification.

Luckily here are no subdirectories.

Reviewed by:	imp, emaste
Approved by:	emaste (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D48779

(cherry picked from commit bccaf0262dcab84be49c42cc6b7a81c279c44b62)
2025-02-12 01:33:35 +00:00
Jose Luis Duran
ac74f9a654
csu tests: Remove extra slash
Remove an extra slash that ends up in the metalog.  This double slash
can produce an invalid specification file if there are subdirectories
down the hierarchy when sorted.

For example, consider the following metalog excerpt:

    ./base/aaa type=dir
    ./base//aaa/bbb type=dir

If sorted, would turn out:

    ./base//aaa/bbb type=dir
    ./base/aaa type=dir

Apparently missing the ./base/aaa directory in the specification.

Luckily here are no subdirectories.

Reviewed by:	imp, emaste
Approved by:	emaste (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D48778

(cherry picked from commit 841856570e7b623c4f1283939936ffa005d2fcf4)
2025-02-12 01:33:15 +00:00
Bjoern A. Zeeb
9bb63440a2 lib80211: regdomain: add the two other 160MHz bands
ETSI had one 160Mhz band in regdomain but the other two were missing.
Add them.  I am always confused that the bands use the center frequency
of the 20Mhz edge channels rather than the actual edges so it seems we
are only configuring 140Mhz instead of 160Mhz.

We will have to go through the entire regdomain file one
day and make sure to verify all the power levels.

Sponsored by:	The FreeSBD Foundation
Reviewed by:	adrian
Differential Revision: https://reviews.freebsd.org/D48356

(cherry picked from commit a3a308f0f29b14d522c56dd88231e27fdf206104)
2025-02-10 14:52:12 +00:00
Mark Johnston
028323d616 setfib.2: Note that the number of FIBs can be adjusted after boot
Reviewed by:	zlei, imp
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48545

(cherry picked from commit 010ee8215f5c899e23250828402af5b7bb354328)
2025-02-07 14:46:53 +00:00
Kirk McKusick
5572827428 Defer the January 19, 2038 date limit in UFS1 filesystems to February 7, 2106
Standardize the definition of a UFS dinode

Differential Revision: https://reviews.freebsd.org/D48472

(cherry picked from commit 1111a44301da39d7b7459c784230e1405e8980f8)
(cherry picked from commit aa90fbed151de512ab6e59f75df009533a15751f)
(cherry picked from commit 256389eaf158acaf67f0530764be8af68edee78c)
(cherry picked from commit 6cd973d903c8f214d84daf91eb75047631bf1618)
(cherry picked from commit e1ebda4458bbaf7d85fb803e20f3afc5441f24d9)
2025-02-06 11:25:09 -08:00
Konstantin Belousov
40fb3c401e crtend: accurately check for the start of .ctors
(cherry picked from commit 21502f9a926c7e0c24ce230bb029fde4bf570a14)
2025-02-04 02:28:37 +02:00
Konstantin Belousov
07324ed409 crtbegin: accurately check for the end of .dtors
(cherry picked from commit 6ee34bca48a9e0867d46b24a78855e225d46ddda)
2025-02-04 02:28:37 +02:00
Konstantin Belousov
af699d9666 csu: add the "Retain" flag to notes sections flag
(cherry picked from commit 6700e2d963ff0475cc5cd444e92ce40855643084)
2025-01-30 11:12:05 +02:00
Konstantin Belousov
1a085ee973 pthread_create(): style
(cherry picked from commit 02703de8bcae3b45e6d96e8467d5fa512d62cc3d)
2025-01-21 02:24:55 +02:00
Konstantin Belousov
e2268518df libpthread_init(): ensure curthread == NULL until set explicitly
(cherry picked from commit 676be27133fa3296f3d9083732d8837a3eaa5ea4)
2025-01-21 02:24:55 +02:00
Konstantin Belousov
2050430609 libthr: switch thread and sleepq memory allocator to crt from libc malloc
(cherry picked from commit 9a2ae72421cd75c741984f63b8c9ee89346a188d)
2025-01-21 02:24:55 +02:00
Konstantin Belousov
d6a896c3c8 pthread_mutex_trylock(): init libthr if needed
(cherry picked from commit 9718f18471f700b271eb898c764e02b7fcd3766f)
2025-01-21 02:24:55 +02:00
Konstantin Belousov
0961e16b36 libthr: use atomic_add_int() instead of atomic_fetchadd_int()
(cherry picked from commit 4804cb433dbec2555695dc2bf391f286f2172621)
2025-01-21 02:24:55 +02:00
Alan Somers
3dc01440a0 Fix lib/libc/nss/getgr_test with large numbers of groups
These tests create a linked list with one entry for every group on the
running system.  On a system with about 30,000 groups, the test took 69
seconds to run, and crashed Kyua with the below error:

kyua: E: string or blob too big (sqlite op: sqlite3_bind_blob) (sqlite db: /root/.kyua/store/results.usr_tests.20241231-203317-570235.db).

Fix the test by limiting it to operating on the first 1024 groups.
Apply the same change to getpw_test and getserv_test too, which are
vulnerable to the same problem.

Sponsored by:	ConnectWise
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D48275

(cherry picked from commit d11904b350214943dedb64c7121d4602799d7afd)
2025-01-20 09:54:45 -07:00
Ed Maste
e2cbfa1f50 munmap.2: Remove EINVAL for negative len
len is unsigned (it is size_t), so cannot be negative.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fab411c4fd5224e3dd44e0eb288d60b27480e2d1)
2025-01-20 09:25:14 -05:00
Ed Maste
61c5090935 munmap.2: Unaligned addresses do not return error
We previously claimed that non-page-aligned addresses would return
EINVAL, but the address is in fact rounded down to the page boundary.

Reported by:	Harald Eilertsen <haraldei@anduin.net>
Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
Fixes: dabee6fecc ("kern_descrip.c: add fdshare()/fdcopy()")
Differential Revision: https://reviews.freebsd.org/D48465

(cherry picked from commit 9e36aaf0c24cf158e83c69c1d2312c000c3c36f3)
2025-01-20 09:25:14 -05:00
Dimitry Andric
dc3f24ea8a Merge llvm-project release/19.x llvmorg-19.1.7-0-gcd708029e0b2
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvm-project release/19.x llvmorg-19.1.7-0-gcd708029e0b2,
a.k.a. 19.1.7 release.

PR:		280562
MFC after:	3 days

(cherry picked from commit 6c05f3a74f30934ee60919cc97e16ec69b542b06)
2025-01-19 12:05:53 +01:00
Olivier Certner
76d0aed164
libprocstat: ZFS support: Makefile: Tidy up a bit
Regroup assignments tweaking preprocessor defines/undefs, and separately
those about include directories.

Re-order include directories a bit more logically, and remove redundant
ones.

Separate logical groups by blank lines.

Build artifacts have been verified to stay the same when produced with
an external LLVM 18 toolchain.

MFC after:      1 month
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D48070

(cherry picked from commit 618c97b87b7124cdfb10d2f33a213c3302c8a98b)
2025-01-16 19:07:02 +01:00
Xin LI
e6de39be80 MFC: libmagic: Unbreak for older FreeBSD releases.
PR:		bin/273736
Reported by:	philip

(cherry picked from commit 7f8f120439b77e60a1070d87f4dc6cb9a43d0335)
2025-01-12 20:24:19 -08:00
Kyle Evans
c876932bba lib: hook libder up to the build
libder will be used in upcoming ECC support in the pkg(7) bootstrap to
read DER-encoded keys and signatures.

(cherry picked from commit f59bb61e1eb4d1e4fc3c60cc14779d0668267cb2)
2025-01-10 20:48:22 -06:00
Baptiste Daroussin
58734b1879 libusb: fix hotplug sigbus
When a hotplug callback has been registered, and the program using
libusb is calling libusb_exit then the thread handler is set to
NO_THREAD which result in the variable controlling the loop the be set
to 0, it does a last pass through device available without having done
a scan, which result in a sigbus after it tried to unregister all the
devices.

directly break the loop instead and cleanup the list of devices

this fixes the tests with LGPLed libusb's hotplugtest program

MFC After:	3 days
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D48298

(cherry picked from commit ba5834b8e11fd002a663d083a464e397e76cb3a9)
2025-01-07 10:02:57 +01:00
Dimitry Andric
589cf0f3e2 Revert "Export additional __aeabi_ symbols from arm's libgcc_s"
This reverts commit caab831338f4eeaa7455e981478be9fd414b7969, because
some new unresolved issues came up in bug 271087:

  Some programs depend on these symbols, when they are compiled for armv6
  or armv7. Closes #1560 (slightly changed due to sorting of the symbols).

PR:		271087
Reported by:	mmel
MFC after:	immediately

(cherry picked from commit b662ca1d6cd82044c6cb79075e1830b97594bef3)
2025-01-04 19:13:25 +01:00
Konstantin Belousov
85671cefd9 check_cancel: when in_sigsuspend, send SIGCANCEL unconditionally
PR:	283101

(cherry picked from commit 9f78c837d94f73f1485e2ce012a8e64197dae9d5)
2025-01-04 05:57:24 +02:00
Konstantin Belousov
2f645d539c pthread_setcancelstate(3): make it async-signal-safe
(cherry picked from commit 030f48f78f96e0cdb30c960e1a11e5ae01d0eee8)
2025-01-04 05:57:24 +02:00