Commit graph

322 commits

Author SHA1 Message Date
Warner Losh 0c00c3d75b test: Change bug number
There was already a bug on this, so change to old bug

PR: 279354
Sponsored by:		Netflix
2024-06-26 09:18:50 -06:00
Warner Losh b2351a4ba5 test: disable sys.kern.unix_seqpacket_test.random_eor_and_waitall
It's been failing for a while, at least some of the time.

PR: 279994
Sponsored by:		Netflix
2024-06-25 19:35:13 -06:00
Mark Johnston ac52fa1f1b sendfile tests: Fix an error check in tcp_socketpair()
Fixes:	c368d3f20f ("tests/sendfile: factor out tcp_socketpair()")
Differential Revision:	https://reviews.freebsd.org/D45598
2024-06-21 14:18:22 -04:00
Gleb Smirnoff 0c0146c309 tests/sendfile: test operation on unix/stream socket
Although there are already multiple tests in the tests collection
that utilize sendfile(2) support over unix/stream socket, they all
don't exercise the asynchronous part of the operation.  This test
framework, however, uses a trick to toggle true async operation and
guarantee that pr_ready method of unix/stream is also tested.

Reviewed by:		chs
Differential Revision:	https://reviews.freebsd.org/D45055
2024-05-03 07:45:07 -07:00
Gleb Smirnoff c368d3f20f tests/sendfile: factor out tcp_socketpair()
It creates a pair of connected TCP sockets for later testing.  No
functional change.

Reviewed by:		chs
Differential Revision:	https://reviews.freebsd.org/D45054
2024-05-03 07:45:06 -07:00
Gleb Smirnoff 19307b86d3 accept_filter: return different errors for non-listener and a busy socket
The fact that an accept filter needs to be cleared first before setting to
a different one isn't properly documented.  The requirement that the
socket needs already be listening, although trivial, isn't documented
either.  At least return a more meaningful error than EINVAL for an
existing filter.  Cover this with a test case.
2024-04-24 21:55:58 -07:00
Gleb Smirnoff c68eed82a3 accf_tls: accept filter that waits for TLS handshake header 2024-04-24 17:53:10 -07:00
Gleb Smirnoff 6655bec4e2 tests/unix_stream: test that send(2) of zero bytes is successful
Put this simple test into an existing file.  We don't have a designated
file for all unix/stream tests.  There is extensive unix_seqpacket_test,
but (at least right now) unix/seqpacket is not a superset of unix/stream,
but a different implementation.  We have one file that does one test for
unix/stream - unix_socketpair_test.  So rename it to unix_stream and start
collecting all unix/stream tests in it.
2024-04-14 10:19:20 -07:00
Jake Freeland 054a472059 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
2024-04-09 21:19:03 -05:00
Gleb Smirnoff 0b49929762 tests/unix_seqpacket: remove workaround for a kernel bug that is no longer 2024-04-08 13:16:51 -07:00
Gleb Smirnoff f992782124 tests/unix_seqpacket: test send(2) to a closed or aborted peer socket
In both cases the kernel returns EPIPE and delivers SIGPIPE, unless
blocked or disabled.  The test isn't specific to SOCK_SEQPACKET, it is the
same for SOCK_STREAM.  Put the test into this file, since it has all
primitives to write this test tersely.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D44146
2024-04-08 13:16:50 -07:00
Gleb Smirnoff eb338e2370 tests/unix_seqpacket: provide random data pumping test with MSG_EOR
Allocate a big chunk of randomly initialized memory.  Send it to the peer
in random sized chunks, throwing MSG_EOR at randomly initialized offsets.
Receive into random sized chunks setting MSG_WAITALL randomly.  Check that
MSG_EORs where they should be, check that MSG_WAITALL is abode, but
overriden by MSG_EOR.  And finally memcmp() what we receive.

Reviewed by:		asomers, tuexen
Differential Revision:	https://reviews.freebsd.org/D43775
2024-04-08 13:16:50 -07:00
Jake Freeland 2f39a98664 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
2024-04-07 18:52:51 -05:00
Mark Johnston 77c3e564b4 ptrace tests: Fix a signed/unsigned integer comparison
Reported by:	Jenkins
Fixes:	43b4da4411 ("ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee")
2024-04-01 19:12:50 -04:00
Mark Johnston 43b4da4411 ptrace tests: Add a test using PROC_REAP_KILL to kill a traced debuggee
This exercises the bug fix in commit 9241ebc796
("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
2024-03-31 14:11:47 -04:00
Gleb Smirnoff 55951611e4 tests/unix_seqpacket: mk_pair_of_sockets() requires a valid argument
All callers do it right.  Don't be overprotective against a stupid
caller and thus don't look like a code that leaks a resource.

Reported by:	Coverity Scan
CID:		1539210
2024-03-11 07:50:29 -07:00
Gleb Smirnoff 253d8a1f8a tests/unix_seqpacket: test that implied connect doesn't work
Applies both to SOCK_STREAM and SOCK_SEQPACKET.  Put the test in this file
as it is most advanced one.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D43854
2024-02-28 14:32:47 -08:00
Gleb Smirnoff 3bc122d270 tests/unix_seqpacket: test that data can be sent before accept(2)
This is undocumented feature of PF_UNIX/SOCK_STREAM and thus of
PF_UNIX/SOCK_SEQPACKET, too.  Put the test into this file, since this file
is most advanced and has all primitives to write this test in minimum
number of lines.

Differential Revision:	https://reviews.freebsd.org/D43853
2024-02-28 14:32:46 -08:00
Gleb Smirnoff 1f46c32c1f tests/unix_seqpacket: provide function that returns bound & listening sock
Use the function in mk_pair_of_sockets(), and in four existing tests -
'listen_bound', 'connect', 'shutdown_send' and 'shutdown_send_sigpipe'.
While here make mk_pair_of_sockets() return pointer to sockaddr_un instead
of path.  This also fixes bug of returning pointer to stack memory of
returning function.  However, the only caller that cares about this return
is temporarily ifdefed out.  No functional change intended.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D43852
2024-02-28 14:32:46 -08:00
Gleb Smirnoff d6ef9649dd tests/unix_seqpacket: remove EMSGSIZE tests
These tests were not testing conformance to the specification, rather than
the limitation of our implementation.  The specification doesn't say that
a SOCK_SEQPACKET shall ever return EMSGSIZE.  It says:

  The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type,
  and is also connection-oriented. The only difference between these
  types is that record boundaries are maintained using the
  SOCK_SEQPACKET type. A record can be sent using one or more output
  operations and received using one or more input operations, but a
  single operation never transfers parts of more than one record.
  Record boundaries are visible to the receiver via the MSG_EOR flag
  in the received message flags returned by the recvmsg() function. It
  is protocol-specific whether a maximum record size is imposed.

The EMSGSIZE is specified as 'message is too large to be sent all at once,
as the socket requires'.  Indeed existing implementation that has
unix/seqpacket marked as PR_ATOMIC has such a limitation.  But future
implementation won't have, thus remove the tests.

Reviewed by:		tuexen, asomers
Differential Revision:	https://reviews.freebsd.org/D43756
2024-02-28 14:32:46 -08:00
Gleb Smirnoff 152a6d410e socket tests: remove MSG_TRUNC test for unix/seqpacket
The PF_UNIX/SOCK_SEQPACKET was marked as PR_ATOMIC and that made
soreceive_generic() to treat it pretty much as a datagram socket.
However, POSIX says:

  The SOCK_SEQPACKET socket type is similar to the SOCK_STREAM type,
  and is also connection-oriented. The only difference between these
  types is that record boundaries are maintained using the
  SOCK_SEQPACKET type. A record can be sent using one or more output
  operations and received using one or more input operations, but a
  single operation never transfers parts of more than one record.
  Record boundaries are visible to the receiver via the MSG_EOR flag
  in the received message flags returned by the recvmsg() function. It
  is protocol-specific whether a maximum record size is imposed.

What the test was doing is checking if MSG_TRUNC would report the space
required to return up the end of next mbuf record in the socket buffer.
Apparently the test assumed that this boundary is defined by the write(2)
size on the peer socket.  This was true in test conditions, but I'm not
sure it would always be true - sbcompress() may merge mbufs. Anyway, the
mbuf boundaries are internal socket buffer implementation, they are not
SOCK_SEQPACKET records.  The records need to be explicitly marked with
MSG_EOR by sender, and the test definitely wasn't doing that.

Reviewed by:		tuexen, markj
Differential Revision:	https://reviews.freebsd.org/D43707
2024-02-28 14:32:46 -08:00
Konstantin Belousov 09dd7240ac sigsys test: correct count of delivered signals
When knob is zero, intent is that no SIGSYS signals are delivered.
Comparing zero to zero does not test much, we should compare the count
of delivered SIGSYSs to zero.

Reviewed by:	dchagin, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44077
2024-02-25 10:11:49 +02:00
Gleb Smirnoff 4c6ceca9cc tests/fdgrowtable: perform the threaded test in a child process
The test needs to be performed in a new process that was forked with
RFCFDG flag.  The will guarantee that the table will start to grow from 20
file descriptors, no matter what kyua(1) or a bare shell was doing before
executing this test.  This should fix  repetitive test runs from a shell
as well as failures with kyua(1) in some environments.
2024-02-23 17:49:53 -08:00
Gleb Smirnoff 98ef51d549 Revert "tests/fdgrowtable: open more files in the threaded case"
This reverts commit fa6a02f50e.

It makes the test less probable to fail, but it doesn't fix the
root issue - that on entry the parent process may have already
a large file descriptor table.
2024-02-23 17:47:29 -08:00
Gleb Smirnoff e53b83a849 tests/sigsys: initialize parameter passed to sysctlbyname() 2024-02-20 14:37:45 -08:00
Gleb Smirnoff 3ac001620e tests/fdgrowtable: remove always true check
We are always the parent in this code path.
2024-02-20 14:31:06 -08:00
Gleb Smirnoff fa6a02f50e tests/fdgrowtable: open more files in the threaded case
This should fix the test failing on some machines/conditions/runs.  This
won't fix failures in standalone run, but should fix kyua(1) runs.
Currently with standalone run it will usually fail because the 40-sized
allocation is skipped (see details below).

This matches what forking test does: open 128 files in the parent and 128
in the child.  There should actually be no difference where and when the
files are open, but let's mimic the forking test, and open more files in
the spawned thread.  Also opening from two different contexts adds a bit
more entropy to the test.

What the test does it checks that fdgrowtable() has been called at least
three tmes for the test process, and the old tables are still on the free
list as long as other execution contexts exist.  Under kyua(1) control the
first call grows the table from 20 to 40, but the original table of 20 is
an embedded one, thus is not put on the free list.  Passing 40 open files
the table grows to 128 and first old table lands on the free list. Passing
128 open file the table grows to 256 and a second old table lands on the
free list.  After that the test would pass.  The threaded test was one
open file off before this fix sometimes.
2024-02-20 14:31:06 -08:00
Gleb Smirnoff bc9107f8c4 socket tests: add listener_wakeup
This test runs several scenarios when sleep(9) on a listen(2)ing socket is
interrupted by shutdown(2) or by close(2).  What should happen in that
case is not specified, neither is documented.  However, there is certain
behavior that we have and this test makes sure it is preserved.  There is
software that relies on it, see bug 227259.  This test is based on
submission with this bug, bugzilla attachment 192260.

The test checks TCP and unix(4) stream socket behavior and SCTP can be
added easily if needed.

The test passes on FreeBSD 11 to 15.  It won't pass on FreeBSD 10,
although the wakeup behavior of shutdown(2) is the same, but it doesn't
return error.

PR:	227259
2024-02-15 10:48:44 -08:00
Gleb Smirnoff 3ad0f9a584 tests/unix_passfd: add a comment for send_a_lot
Explain why SOCK_DGRAM and SOCK_STREAM differ in this edge case.  While
here improve output in case of a failure.
2024-02-08 09:00:41 -08:00
Gleb Smirnoff 1e68b8d9a9 tests/unix_passfd: test that control mixed with data creates records
If socket has data interleaved with control it would never allow to read
two pieces of data, neither two pieces of control with one recvmsg(2).  In
other words, presence of control makes a SOCK_STREAM socket behave like
SOCK_SEQPACKET, where control marks the records. This is not a documented
or specified behavior, but this is how it worked always for BSD sockets.
If you look closer at it, this actually makes a lot of sense, as if it
were the opposite both the kernel code and an application code would
become way more complex.

The change made recvfd_payload() to return received length and requires
caller to do ATF_REQUIRE() itself.  This required a small change to
existing test rights_creds_payload.  It also refactors a bit f28532a0f3,
pushing two identical calls out of TEST_PROTO ifdef.

Reviwed by:		markj
Differential Revision:	https://reviews.freebsd.org/D43724
2024-02-08 09:00:41 -08:00
Gleb Smirnoff 45eae45d91 tests/unix_passfd: fix typos - assignment instead of comparison
This typos were actually hiding a kernel bug, see 541e6a989c.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D43734
2024-02-08 09:00:37 -08:00
Gleb Smirnoff 702c481847 socket tests: improve error message 2024-02-01 13:37:26 -08:00
Jamie Gritton ab0841bdbe jail: expose children.max and children.cur via sysctl
Submitted by:	Igor Ostapenko <igor.ostapenko_pm.me>
Differential Revision:	<https://reviews.freebsd.org/D43565>
2024-01-26 09:45:40 -08:00
Gleb Smirnoff b32d49cfba tests: fix typo in a comment 2024-01-25 22:19:59 -08:00
Kyle Evans 30189156d3 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
Differential Revision:	https://reviews.freebsd.org/D43457
2024-01-15 20:55:59 -06:00
Gleb Smirnoff e007b89e9d tests: add a test for shutdown(2) on a datagram socket 2024-01-12 02:04:04 -08:00
Brooks Davis 8e2c2992da socket_msg_trunc: allocate a large enough buffer
Allocate 9000 bytes to match the largest requsted size.  Add a check to
prevent the list of sizes and buffer size from getting out of sync
again.

Reviewed by:	markj
Found with:	CheriBSD
Differential Revision:	https://reviews.freebsd.org/D43340
2024-01-09 22:59:29 +00:00
Gleb Smirnoff cfb1e92912 sockets: don't malloc/free sockaddr memory on accept(2)
Let the accept functions provide stack memory for protocols to fill it in.
Generic code should provide sockaddr_storage, specialized code may provide
smaller structure.

While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting
required length in case if provided length was insufficient.  Our manual
page accept(2) and POSIX don't explicitly require that, but one can read
the text as they do.  Linux also does that. Update tests accordingly.

Reviewed by:		rscheff, tuexen, zlei, dchagin
Differential Revision:	https://reviews.freebsd.org/D42635
2023-11-30 08:30:55 -08:00
Gleb Smirnoff 96950419f1 tests: don't run atf_* in a subshell
Shell limitation is that a classic function call via $() is a subshell
and atf-sh(3) commands won't work as epxected there.  Subsequently,
atf_skip inside a function won't skip a test.  The test will fail later.

A working approach is to pass desired variable name as argument to
a function and don't run subshell.

Reviewed by:		ngie
Differential Revision:	https://reviews.freebsd.org/D42646
Fixes:			ea82362219
2023-11-27 13:15:59 -08:00
Warner Losh 6dced2c635 tests: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:01 -07:00
Mark Johnston b08a9b86f5 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
2023-11-17 09:31:21 -05:00
Gleb Smirnoff 070d9e3540 socket tests: add socket_accept
Start with most basic functionality on a TCP socket.
2023-11-16 08:23:48 -08:00
Mark Johnston 4bd1e19684 socket tests: Build fix
Fixes:	d8735eb7ac ("socket tests: Add a regression test for ktrace+recv(MSG_TRUNC)")
Reported by:	Jenkins
2023-10-17 10:22:11 -04:00
Mark Johnston d8735eb7ac socket tests: Add a regression test for ktrace+recv(MSG_TRUNC)
MFC after:	1 week
2023-10-17 09:12:57 -04:00
Mark Johnston b5e7dbac75 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
2023-10-17 09:12:36 -04:00
Dmitry Chagin b67c0ba461 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
2023-10-03 10:38:02 +03:00
Konstantin Belousov 0afcac3e37 SIGSYS: add tests
Reviewed by:	dchagin, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41976
2023-10-03 01:30:53 +03:00
Mark Johnston a3074ff212 socket tests: Avoid a buffer leak
Reported by:	Coverity
Fixes:		38426b32e1 ("socket tests: Add a regression test for MSG_WAITALL")
2023-09-27 08:30:50 -04:00
Mark Johnston d643925a79 unix tests: Use the right type for sendmsg(2) return values
MFC after:	1 week
2023-09-15 13:04:15 -04:00
Mark Johnston 38426b32e1 socket tests: Add a regression test for MSG_WAITALL
PR:		212716
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2023-09-15 12:59:46 -04:00