Commit graph

296 commits

Author SHA1 Message Date
Konstantin Belousov
ca3222c4fc ptrace_test: add test for expanded reporting of syscall args
(cherry picked from commit 526becbf6e42331e3680d55fe1e9a82e1b56a735)
2025-04-07 04:28:23 +03:00
Gleb Smirnoff
e4e6423ef3 tests/sigsys: initialize parameter passed to sysctlbyname()
(cherry picked from commit e53b83a849e3a34772d0a0ed26eb0cb4aeeec71d)
2025-02-10 00:36:24 +08:00
Mark Johnston
872da05f8c SO_SPLICE tests: Fix a comment typo
MFC after:	1 week
Sponsored by:	Klara, Inc.

(cherry picked from commit 9743e9efdf5f0d2338d7cfeed8f09d89d889bac4)
2025-01-14 14:14:24 +00:00
Mark Johnston
da44138dc2 unix: Add support for atomically setting the socket mode
With this patch, it is possible to call fchmod() on a unix socket prior
to binding it to the filesystem namespace, so that the mode is set
atomically.  Without this, one has to call chmod() after bind(), leaving
a window where threads can connect to the socket with the default mode.
After bind(), fchmod() reverts to failing with EINVAL.

This interface is copied from Linux.

The behaviour of fstat() is unmodified, i.e., it continues to return the
mode as set by soo_stat().

PR:		282393
Reviewed by:	kib
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D47361

(cherry picked from commit bfd03046d18776ea70785ca1ef36dfc60822de3b)
2024-12-03 01:03:26 +00:00
Mark Johnston
794fd74ab8 tests: Add some test cases for SO_SPLICE
Reviewed by:	gallatin
MFC after:	3 months
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D46412

(cherry picked from commit 877cf210c08b99aa532107e176b372de58579493)
2024-10-17 15:48:37 +00:00
Mark Johnston
58f9c14235 ktrace tests: Add a test case for handling of exec+setuid binaries
MFC after:	1 week

(cherry picked from commit 3852a5a226509551e72c13bce443707f80e863ce)
2024-08-15 14:29:49 +00:00
Ed Maste
f06d322e9d Remove "All Rights Reserved" from FreeBSD Foundation copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 5c2bc3db201a4fe8d7911cf816bea104d5dc2138)
2024-08-06 15:39:53 -04:00
Mark Johnston
014b6c341d ktrace tests: Add a missing mode in open(O_CREAT)
MFC after:	1 week

(cherry picked from commit 9cc67e43610e34a692398a65adcc5e8846e84250)
2024-08-06 16:40:51 +00:00
Mark Johnston
bed96ef09d socket tests: Serialize sonewconn_overflow
It relies on being able inspect the dmesg buffer to see whether the
kernel logged certain messages.  If it's interleaved with tests that
generate large amounts of console output (e.g., GELI tests), then it can
fail spuriously.

MFC after:	2 weeks

(cherry picked from commit ab27e232b14c07317642a2e4c546c9b71bd9c00b)
2024-07-30 15:55:32 +00:00
Mark Johnston
b14a491283 ktls: Fix races that can lead to double initialization
ktls_enable_rx() and ktls_enable_tx() have checks to return EALREADY if
the socket already has KTLS enabled.  However, these are done without
any locks held and nothing blocks concurrent attempts to set the socket
option.  I believe the worst outcome of the race is leaked memory.

Fix the problem by rechecking under the sockbuf lock.  While here, unify
the locking protocol for sb_tls_info: require both the sockbuf and
socket I/O locks in order to enable KTLS.  This means that either lock
is sufficient for checking whether KTLS is enabled in a given sockbuf,
which simplifies some refactoring further down the road.

Note that the SOLISTENING() check can go away because
SOCK_IO_RECV_LOCK() atomically locks the socket buffer and checks
whether the socket is a listening socket.  This changes the returned
errno value, so update a test which checks it.

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

(cherry picked from commit 163cdf6a32b9a0f84226a70101d143c10707336f)
2024-07-23 09:01:30 -04:00
Mark Johnston
c1dd895406 sched tests: Avoid underflow when maxcpuid == 0
MFC after:	1 week

(cherry picked from commit 5b98bd30686a358b2a20728a4a6b5cecb7e28dc9)
2024-07-21 20:55:27 -04:00
Jake Freeland
a94eacb139 tests: Add ktrace regression test for shm_open
Verify that a capability violation is recorded when shm_open(2) is called
with a non-anonymous path.

Approved by:	markj (mentor)
Reviewed by:	markj
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D44733

(cherry picked from commit 054a4720591f0c98579bccef2751fd458ee4f71f)
2024-05-11 18:57:44 -05:00
Jake Freeland
44952722a0 tests: Add ktrace capability violation test cases
Introduce regression tests for ktrace(2) that target capability
violations.

These test cases ensure that ktrace(2) records these violations:
- CAPFAIL_NOTCAPABLE
- CAPFAIL_INCREASE
- CAPFAIL_SYSCALL
- CAPFAIL_SIGNAL
- CAPFAIL_PROTO
- CAPFAIL_SOCKADDR
- CAPFAIL_NAMEI
- CAPFAIL_CPUSET

A portion of these test cases create processes that do NOT enter
capability mode, but raise violations. This is intended behavior.
Users may run `ktrace -t p` on non-Capsicumized programs to detect
violations that would occur if the process were in capability mode.

Reviewed by:	markj
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D40682

(cherry picked from commit 2f39a986641ecebaa9080ca28118903bd9707a1f)
2024-05-11 18:57:44 -05:00
Mark Johnston
615bd9d0a0 ptrace tests: Fix a signed/unsigned integer comparison
Reported by:	Jenkins
Fixes:	43b4da44118e ("ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee")

(cherry picked from commit 77c3e564b4b65443a9d3298e0aec4c1387acd55e)
2024-04-15 10:05:13 -04:00
Mark Johnston
16f6ce3f82 ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee
This exercises the bug fix in commit 9241ebc796c1
("thread_single(9): decline external requests for traced or debugger-stopped procs").

Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D44564

(cherry picked from commit 43b4da44118e4fe29e9d7456db4390c9cbb53636)
2024-04-15 10:05:13 -04:00
Konstantin Belousov
acb407522c sigsys test: correct count of delivered signals
(cherry picked from commit 09dd7240acf1fc50061246013ce318404d70c4e0)
2024-03-01 06:12:02 +02:00
Kyle Evans
aebaa32c31 kern: pts: do not special case closed slave side
This would previously return 1 if the slave side of the pts was closed
to force an application to read() from it and observe the EOF, but it's
not clear why and this is inconsistent both with how we handle devices
with similar mechanics (like pipes) and also with other kernels, such as
OpenBSD/NetBSD and Linux.

PR:             239604
Reviewed by:	kib

(cherry picked from commit 30189156d325fbcc9d1997d791daedc9fa3bed20)
2024-01-30 11:11:24 -06:00
Mark Johnston
34c7691f53 ktls tests: Relax error checking for shutdown(2) a bit
In my test suite runs I occasionally see shutdown(2) fail with
ECONNRESET rather than ENOTCONN.  soshutdown(2) will return ENOTCONN if
the socket has been disconnected (synchronized by the socket lock), and
tcp_usr_shutdown() will return ECONNRESET if the inpcb has been dropped
(synchronized by the inpcb lock).  I think it's possible to pass the
first check in soshutdown() but fail the second check in
tcp_usr_shutdown(), so modify the KTLS tests to permit this.

Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42277

(cherry picked from commit b08a9b86f581edf09c5a2729d877a0204499685b)
2023-11-24 11:37:46 -05:00
Mark Johnston
21a9924086 socket tests: Build fix
Fixes:	d8735eb7acc0 ("socket tests: Add a regression test for ktrace+recv(MSG_TRUNC)")
Reported by:	Jenkins

(cherry picked from commit 4bd1e19684945aa1fd3397b58613f5210fda9091)
2023-10-24 10:28:11 -04:00
Mark Johnston
f79b01d323 socket tests: Add a regression test for ktrace+recv(MSG_TRUNC)
MFC after:	1 week

(cherry picked from commit d8735eb7acc0613fd19f74a49d3bdcb7ed0e9b0e)
2023-10-24 09:18:39 -04:00
Mark Johnston
6b107108b1 socket tests: Clean up the MSG_TRUNC regression tests a bit
- Fix style.
- Move test case-specific code out of the shared function and into the
  individual test cases.
- Remove unneeded setting of SO_REUSEPORT.
- Avoid unnecessary copying.
- Use ATF_REQUIRE* instead of ATF_CHECK*.  The former cause test
  execution to stop after a failed assertion, which is what we want.
- Add a test case for AF_LOCAL/SOCK_SEQPACKET sockets.

MFC after:	1 week

(cherry picked from commit b5e7dbac756afb49c58315c7081737b34a1d2dfd)
2023-10-24 09:18:23 -04:00
Dmitry Chagin
761d9162d2 tests: Test that SIGSYS is not delivered if kern.signosys knob is off
Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D41979
MFC after:		1 week

(cherry picked from commit b67c0ba4613861f8245ce835081311aef1c19bae)
2023-10-10 08:12:12 +03:00
Konstantin Belousov
e19be5b01e SIGSYS: add tests
(cherry picked from commit 0afcac3e37e911f7e387ebeb2aae19b2b00ca4cc)
2023-10-09 06:24:31 +03:00
Mark Johnston
811b3d0f0f socket tests: Add a regression test for MSG_WAITALL
PR:		212716
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 38426b32e106cf251520259b29779372eda7a5f8)
2023-09-27 08:33:24 -04:00
Mark Johnston
66b87decbf unix tests: Use the right type for sendmsg(2) return values
MFC after:	1 week

(cherry picked from commit d643925a79caab5c6de62b066e374935b60bcaf1)
2023-09-27 08:32:49 -04:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Mark Johnston
383d51d592 unix tests: Add a regression test for getpeername(2)
Ensure that it works as expected when applied to a self-connected
socket.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2023-06-21 14:39:36 -04:00
John Baldwin
6dd202ce93 unix_seqpacket_test: Consistently use datalen as length to send.
This matches the other tests in this file and quiets a set but unused
warning from GCC.
2023-06-20 09:29:00 -07:00
Mark Johnston
da8c3d2149 tests: Fix format strings
Reported by:	Jenkins
Fixes:		844942888f ("tests: Add a simple regression test for ptrace(PT_SC_REMOTE)")
2023-05-26 17:38:06 -04:00
Mark Johnston
844942888f tests: Add a simple regression test for ptrace(PT_SC_REMOTE)
MFC after:	1 week
2023-05-26 15:38:08 -04:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Pierre Pronchery
74192f9b2d ktls_test: specify OpenSSL 1.1 API
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
2023-05-11 10:30:51 -04:00
Mark Johnston
889b5662ce fdgrowtable tests: Address a set-but-not-used warning
MFC after:	1 week
2023-03-30 13:55:06 -04:00
Mark Johnston
5ea1e35d7d ktls tests: Populate sockaddr fields before binding
Reported by:	Jenkins
Fixes:		b4b33821fa ("ktls: Fix interlocking between ktls_enable_rx() and listen(2)")
2023-03-30 13:52:04 -04:00
Mark Johnston
b4b33821fa ktls: Fix interlocking between ktls_enable_rx() and listen(2)
The TCP_TXTLS_ENABLE and TCP_RXTLS_ENABLE socket option handlers check
whether the socket is listening socket and fail if so, but this check is
racy.  Since we have to lock the socket buffer later anyway, defer the
check to that point.

ktls_enable_tx() locks the send buffer's I/O lock, which will fail if
the socket is a listening socket, so no explicit checks are needed.  In
ktls_enable_rx(), which does not acquire the I/O lock (see the review
for some discussion on this), use an explicit SOLISTENING() check after
locking the recv socket buffer.

Otherwise, a concurrent solisten_proto() call can trigger crashes and
memory leaks by wiping out socket buffers as ktls_enable_*() is
modifying them.

Also make sure that a KTLS-enabled socket can't be converted to a
listening socket, and use SOCK_(SEND|RECV)BUF_LOCK macros instead of the
old ones while here.

Add some simple regression tests involving listen(2).

Reported by:	syzkaller
MFC after:	2 weeks
Reviewed by:	gallatin, glebius, jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38504
2023-03-21 16:04:00 -04:00
Mark Johnston
683853a924 sendfile tests: Mount filesystems under the test workdir
Otherwise they can't be run in parallel as they share a mount point.

MFC after:	1 week
2023-03-13 10:45:35 -04:00
Gleb Smirnoff
a170657108 unix/dgram tests: match the kernel behavior
In CURRENT for some time an overflowed unix/dgram socket would
return EAGAIN if it has O_NONBLOCK set.  This proved to be
undesired.  See 71e70c25c0 for details.  Update tests to match
the "new" behavior, which actually is the historical behavior.
2023-02-22 20:44:46 -08:00
Dmitry Chagin
02f7670ed2 sched.h: Fix _S macros for better compatibility with glibc.
In e2650af157 was added "_S" macros for compatibility with glibc, but it's still
incompatible as under glibc the macros whose names end with "_S" operate on the
dynamically allocated CPU set(s) whose size is in bytes, not in bits.

While here remove limiting ifdef to non-kernel case.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D38110
MFC after:		1 week
2023-01-29 15:34:10 +03:00
John Baldwin
3845cce70d ktls_tests: Ignore errors from close for receive error tests.
For tests that send invalid data to a TLS socket to trigger read
errors the kernel may end up dropping the connection before close is
called at the conclusion of the test resulting in spurious ECONNRESET
errors from close.  Ignore any errors from close for these tests.

PR:		268390
Reported by:	olivier, Michal Gulbicki <michalx.gulbicki@intel.com>
Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37717
2022-12-20 11:38:28 -08:00
John Baldwin
f0c143b356 ktls_tests: Ignore spurious errors from shutdown(2).
For some of the "bad size" tests, the remote end can notice the error
and drop the connection before the test program returns from write to
call shutdown.  In that case, shutdown fails with ENOTCONN.  Permit
these ENOTCONN errors without failing the test.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37693
2022-12-20 11:38:07 -08:00
John Baldwin
883d1742d3 ktls_tests: Log more details when a test fails.
- Make use of ATF_REQUIRE_INTEQ to log the values of integers for
  unexpected mismatches.

- Use ATF_REQUIRE_MSG in a few more places to log values when a
  requirement fails.

- Consistently use ATF_REQUIRE_ERRNO when checking for an expected
  errno value.

Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37691
2022-12-15 12:06:09 -08:00
John Baldwin
1656007e4c ptrace_test: Remove another MIPS remnant. 2022-12-13 14:51:52 -08:00
John Baldwin
70bb22868d ktls_test: Add debug option to hexdump keys, nonces, and buffers.
Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37509
2022-12-07 16:57:28 -08:00
John Baldwin
65bd3adbed ktls: Add tests for receiving corrupted or invalid records.
These should all trigger errors when reading from the socket.

Tests include truncated records (socket closed early on the other
side), corrupted records (bits flipped in explicit IVs, ciphertext, or
MAC), invalid header fields, and various invalid record lengths.

Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37373
2022-11-15 12:03:19 -08:00
John Baldwin
64811651aa ktls: Add tests for software AES-CBC decryption for TLS 1.1+.
Reviewed by:	markj
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D37371
2022-11-15 12:02:28 -08:00
Ed Maste
185efcc376 tests: also remove sparc64 case
Followup to commit d6273acf56, which removed MIPS.

Reported by:	mhorne
2022-11-08 18:55:00 -05:00
Ed Maste
d6273acf56 tests: retire now-unused MIPS case 2022-11-08 09:17:53 -05:00