Commit graph

1200 commits

Author SHA1 Message Date
Alan Somers
eccfee8330 fusefs: implement VOP_ALLOCATE
Now posix_fallocate will be correctly forwarded to fuse file system
servers, for those that support it.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33389

(cherry picked from commit 398c88c758)
2022-01-17 18:13:28 -07:00
Alan Somers
bfffd35108 fusefs: in the tests, always assume debug.try_reclaim_vnode is available
In an earlier version of the revision that created that sysctl (D20519)
the sysctl was gated by INVARIANTS, so the test had to check for it.
But in the committed version it is always available.

(cherry picked from commit 19ab361045)

fusefs: move common code from forget.cc to utils.cc

(cherry picked from commit 8d99a6b91b)

fusefs: fix .. lookups when the parent has been reclaimed.

By default, FUSE file systems are assumed not to support lookups for "."
and "..".  They must opt-in to that.  To cope with this limitation, the
fusefs kernel module caches every fuse vnode's parent's inode number,
and uses that during VOP_LOOKUP for "..".  But if the parent's vnode has
been reclaimed that won't be possible.  Previously we paniced in this
situation.  Now, we'll return ESTALE instead.  Or, if the file system
has opted into ".." lookups, we'll just do that instead.

This commit also fixes VOP_LOOKUP to respect the cache timeout for ".."
lookups, if the FUSE file system specified a finite timeout.

PR:		259974
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33239

(cherry picked from commit 1613087a81)
2022-01-17 18:08:25 -07:00
Alan Somers
449d02a12e fusefs: copy_file_range must update file timestamps
If FUSE_COPY_FILE_RANGE returns successfully, update the atime of the
source and the mtime and ctime of the destination.

Reviewers:	pfg
Differential Revision: https://reviews.freebsd.org/D33159

(cherry picked from commit 5169832c96)
2022-01-17 18:02:55 -07:00
Alan Somers
36ba360558 Fix a race in fusefs that can corrupt a file's size.
VOPs like VOP_SETATTR can change a file's size, with the vnode
exclusively locked.  But VOPs like VOP_LOOKUP look up the file size from
the server without the vnode locked.  So a race is possible.  For
example:

1) One thread calls VOP_SETATTR to truncate a file.  It locks the vnode
   and sends FUSE_SETATTR to the server.
2) A second thread calls VOP_LOOKUP and fetches the file's attributes from
   the server.  Then it blocks trying to acquire the vnode lock.
3) FUSE_SETATTR returns and the first thread releases the vnode lock.
4) The second thread acquires the vnode lock and caches the file's
   attributes, which are now out-of-date.

Fix this race by recording a timestamp in the vnode of the last time
that its filesize was modified.  Check that timestamp during VOP_LOOKUP
and VFS_VGET.  If it's newer than the time at which FUSE_LOOKUP was
issued to the server, ignore the attributes returned by FUSE_LOOKUP.

PR:		259071
Reported by:	Agata <chogata@moosefs.pro>
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33158

(cherry picked from commit 13d593a5b0)
2022-01-17 17:59:03 -07:00
Mark Johnston
845458a674 tests: Add some regression tests for a couple of KERN_PROC_* sysctls
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fff0ae77b9)
2022-01-16 10:40:39 -05:00
Stefan Eßer
379bfb2aa9 sys/bitset.h: reduce visibility of BIT_* macros
(cherry picked from commit 5e04571cf3)
2022-01-14 18:17:30 +02:00
Mark Johnston
16c60a70c9 posixshm tests: Fix occasional largepage_mprotect failures
largepage_mprotect maps a superpage and later extends the mapping.  This
occasionally fails with ASLR disabled.  To fix this, first try to
reserve a sufficiently large virtual address region.

Reported by:	Jenkins
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 321e586e46)
2022-01-10 09:05:12 -05:00
Lutz Donnerhacke
e5c7bbe627 tests/libalias: Portrange
Test ranges of allowed ports for aliasing.
 - Explicit default like ipfw(8) is doing
 - Regular range
 - Exhausting a very small range
 - Recovery

Includes a fix of an utility macro, which was not used before.

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

(cherry picked from commit 2c733b50c5)
2022-01-03 12:18:10 +01:00
Alan Somers
642399932d fusefs: invalidate the cache during copy_file_range
FUSE_COPY_FILE_RANGE instructs the server to write data to a file.
fusefs must invalidate any cached data within the written range.

PR:		260242
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33280

(cherry picked from commit 41ae9f9e64)
2022-01-02 20:03:54 -07:00
Alan Somers
139764c461 fusefs: correctly handle an inode that changes file types
Correctly handle the situation where a FUSE server unlinks a file, then
creates a new file of a different type but with the same inode number.
Previously fuse_vnop_lookup in this situation would return EAGAIN.  But
since it didn't call vgone(), the vnode couldn't be reused right away.
Fix this by immediately calling vgone() and reallocating a new vnode.

This problem can occur in three code paths, during VOP_LOOKUP,
VOP_SETATTR, or following FUSE_GETATTR, which usually happens during
VOP_GETATTR but can occur during other vops, too.  Note that the correct
response actually doesn't depend on whether the entry cache has expired.
In fact, during VOP_LOOKUP, we can't even tell.  Either it has expired
already, or else the vnode got reclaimed by vnlru.

Also, correct the error code during the VOP_SETATTR path.

PR:		258022
Reported by:	chogata@moosefs.pro
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33283

(cherry picked from commit 25927e068f)
2022-01-02 19:36:38 -07:00
Alan Somers
2472f84728 fusefs: better debugging for FUSE_RENAME in the tests
(cherry picked from commit c2d342c509)
2022-01-02 19:34:43 -07:00
Mark Johnston
5a3abce55e ktls: Add a regression test to exercise socket error handling
Prior to commit 916c61a5ed ("Fix handling of errors from
pru_send(PRUS_NOTREADY)") this test triggered a kernel panic due to an
mbuf double free.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit ee5686c614)
2021-12-31 09:25:45 -05:00
Dimitry Andric
cca67690ac tests/libalias: Make inline functions static inline
In C, plain inline functions should never be used: they should be
declared either static inline or extern inline. In this case, they are
clearly meant to be static inline.

MFC after:	3 days

(cherry picked from commit 46aec7fae4)
2021-12-27 11:19:31 +01:00
Konstantin Belousov
ed21083462 swapon(8): adapt to the new swapoff(2) interface
(cherry picked from commit b49b6e0f95)
2021-12-20 02:29:11 +02:00
Alan Somers
0bade34633 fusefs: update atime on reads when using cached attributes
When using cached attributes, whether or not the data cache is enabled,
fusefs must update a file's atime whenever it reads from it, so long as
it wasn't mounted with -o noatime.  Update it in-kernel, and flush it to
the server on close or during the next setattr operation.

The downside is that close() will now frequently trigger a FUSE_SETATTR
upcall.  But if you care about performance, you should be using
-o noatime anyway.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D33145

(cherry picked from commit 91972cfcdd)

fusefs: fix 32-bit build of the tests after 91972cfcdd

(cherry picked from commit d109559ddb)
2021-12-14 15:15:53 -07:00
Alan Somers
000ce6dee1 fusefs: fix copy_file_range when extending a file
When copy_file_range extends a file, it must update the cached file
size.

Reviewed by:	rmacklem, pfg
Differential Revision: https://reviews.freebsd.org/D33151

(cherry picked from commit 65d70b3bae)
2021-12-14 14:49:56 -07:00
Alan Somers
0a44675ba5 fusefs: fix intermittency in the dev_fuse_poll test
The DevFusePoll::access/select test would occasionally segfault.  The
cause was a file descriptor that was shared between two threads.  The
first thread would kill the second and close the file descriptor.  But
it was possible that the second would read the file descriptor before it
shut down.  That did not cause problems for kqueue, poll, or blocking
operation, but it triggered segfaults in select's macros.

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

(cherry picked from commit f44a448709)
2021-12-14 14:47:32 -07:00
Kristof Provost
d5dd159b15 pf tests: more thorough pfsync defer test
Add a somewhat more extensive pfsync defer mode test. Ensure that pfsync
actually delays the state creating packet until after it has sent the
pfsync update and given the peer time to create the state.

Ideally the test should validate the pfsync state update and generate an
ack message, but to keep the test simple we rely on the timeout of the
deferred packet instead.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33245

(cherry picked from commit 60a3a371af)
2021-12-13 14:49:27 +01:00
Kristof Provost
74156bb47c net tests: fix if_stf:6to4
This test needs to have the loopback interface enabled, or route lookups
for our own IP addresses will fail.

MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D33041

(cherry picked from commit 67573b7a39)
2021-12-11 10:39:15 +01:00
Alan Somers
7adb46c70f fusefs: Fix a bug during VOP_STRATEGY when the server changes file size
If the FUSE server tells the kernel that a file's size has changed, then
the kernel must invalidate any portion of that file in cache.  But the
kernel can't do that during VOP_STRATEGY, because the file's buffers are
already locked.  Instead, proceed with the write.

PR:		256937
Reported by:	Agata <chogata@moosefs.pro>
Tested by:	Agata <chogata@moosefs.pro>
Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D32332

(cherry picked from commit 032a5bd55b)
2021-12-06 22:14:10 -07:00
Alan Somers
bdd7a3f2a1 fusefs: fix a recurse-on-non-recursive lockmgr panic
fuse_vnop_bmap needs to know the file's size in order to calculate the
optimum amount of readahead.  If the file's size is unknown, it must ask
the FUSE server.  But if the file's data was previously cached and the
server reports that its size has shrunk, fusefs must invalidate the
cached data.  That's not possible during VOP_BMAP because the buffer
object is already locked.

Fix the panic by not querying the FUSE server for the file's size during
VOP_BMAP if we don't need it.  That's also a a slight performance
optimization.

PR:		256937
Reported by:	Agata <chogata@moosefs.pro>
Tested by:	Agata <chogata@moosefs.pro>

(cherry picked from commit 7430017b99)
2021-12-06 22:08:32 -07:00
Alan Somers
dfb3365aa1 fusefs: implement FUSE_NO_OPEN_SUPPORT and FUSE_NO_OPENDIR_SUPPORT
For file systems that allow it, fusefs will skip FUSE_OPEN,
FUSE_RELEASE, FUSE_OPENDIR, and FUSE_RELEASEDIR operations, a minor
optimization.

Reviewed by:	pfg
Differential Revision: https://reviews.freebsd.org/D32141

(cherry picked from commit 7124d2bc3a)
2021-12-06 21:51:55 -07:00
Warner Losh
fb732c57f1 Fix copyright to be like all my others in the tree
(cherry picked from commit 09f1ead230)
2021-12-06 08:55:57 -07:00
Warner Losh
359f5cf29f Basic signal tests: Can we deliver a signal?
Basic signal tests that tests can we deliver a signal via raise() and
can we deliver one via SIGALARM asynchronously.

In addition, tests whether or not on ARM T32 (Thumb) code can interrupt
A32 (normal) and vice versa.

While this test is aimed at ensuring basic qemu signals are working,
it's good to have in the base.

Sponsored by:		Netflix
Discussed with:		kevans, cognet
Differential Revision:	https://reviews.freebsd.org/D33078

(cherry picked from commit afc5ab870d)
2021-12-06 08:55:57 -07:00
Kristof Provost
1019910199 pf tests: Test PR259689
We didn't populate dyncnt/tblcnt, so `pfctl -sr -vv` might not have the
table element count.

PR:		259689
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D32893

(cherry picked from commit 2de49deeca)
2021-12-01 16:53:20 +01:00
Kristof Provost
a40b765118 net tests: basic if_stf test
Test the 6to4 code.

MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D32850

(cherry picked from commit eb5e0755f7)
2021-12-01 16:53:19 +01:00
Kristof Provost
9bb3c824f5 net tests: basic if_gif(4) test case
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D32836

(cherry picked from commit 6e0755b37b)
2021-11-29 15:44:40 +01:00
Ed Maste
ee2e925603 Fix coredump_phnum test with ASLR enabled
coredump_phnum intends to generate a core file with many PT_LOAD
segments.  Previously it called mmap() in a loop with alternating
protections, relying on each mapping following the previous, to produce
a core file with many page-sized PT_LOAD segments.  With ASLR on we no
longer have this property of each mmap() following the previous.

Instead, perform a single allocation, and then use mprotect() to set
alternating pages to PROT_READ.

PR:		259970
Reported by:	lwhsu, mw
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33070

(cherry picked from commit 8ec4c5dae3)
2021-11-27 19:27:03 -05:00
Kristof Provost
07b8f5dca1 pf tests: basic test for ridentifier
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D32751

(cherry picked from commit 508161111d)
2021-11-26 04:39:33 +01:00
Kristof Provost
094b79ea73 pf tests: route_to:icmp_nat_head requires scapy
Document the requirement so the test is skipped if scapy is not
installed.

MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 11703705c2)
2021-11-24 17:45:51 +01:00
John Baldwin
abb212fe13 ktls tests: Check the return values of close().
Suggested by:	markj
Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33004

(cherry picked from commit 694c708d6a)
2021-11-23 15:11:54 -08:00
John Baldwin
b2d704ea88 ktls: Use ATF_REQUIRE instead of assert() for validating TLS header lengths.
The TLS header length field is set by the kernel, so if it is
incorrect that is an indication of a kernel bug, not an internal error
in the tests.

Prompted by:	markj (comment in an earlier review)
Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33003

(cherry picked from commit d71830cdf0)
2021-11-23 15:11:54 -08:00
John Baldwin
6987f78ea1 ktls: Add tests ensuring unsupported receive cipher suites are rejected.
Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32982

(cherry picked from commit 83a54b582f)
2021-11-23 15:11:54 -08:00
John Baldwin
e91446cd84 ktls: Add tests ensuring invalid receive cipher suites are rejected.
Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32981

(cherry picked from commit 233ce578a4)
2021-11-23 15:11:54 -08:00
John Baldwin
38b44748ab ktls: Add simple receive tests of kernel TLS.
Similar to the simple transmit tests added in
a10482ea74, these tests test the kernel
TLS functionality directly by manually encrypting TLS records using
randomly generated keys and writing them to a socket to be processed
by the kernel.

Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32980

(cherry picked from commit 3e7f8a8da2)
2021-11-23 15:11:53 -08:00
John Baldwin
32993b8e58 ktls: Add tests ensuring various invalid cipher suites are rejected.
Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32843

(cherry picked from commit d1c369f926)
2021-11-23 15:11:53 -08:00
John Baldwin
27d29db0fa ktls: Add tests for sending empty fragments for TLS 1.0 connections.
Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32841

(cherry picked from commit 0ff2a12ae3)
2021-11-23 15:11:53 -08:00
John Baldwin
9b6f4b35d2 ktls: Add padding tests for AES-CBC MTE cipher suites.
For each AES-CBC MTE cipher suite, test sending records with 1 to 16
bytes of payload.  This ensures that all of the potential padding
values are covered.

Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32840

(cherry picked from commit 44265dc3da)
2021-11-23 15:11:53 -08:00
Ed Maste
64ecbc0cd3 tests: do not build ktls_test if WITHOUT_OPENSSL
ktls_test requires libcrypto to build, and fails if it is not available
(which is the case when building WITHOUT_OPENSSL).

Reported by:	Michael Dexter, Build Option Survey
Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32895

(cherry picked from commit e818178e3a)
2021-11-23 15:11:45 -08:00
John Baldwin
71e6792cbe ktls: Add simple transmit tests of kernel TLS.
Note that these tests test the kernel TLS functionality directly.
Rather than using OpenSSL to perform negotiation and generate keys,
these tests generate random keys send data over a pair of TCP sockets
manually decrypting the TLS records generated by the kernel.

Reviewed by:	markj
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D32652

(cherry picked from commit a10482ea74)
2021-11-23 15:11:45 -08:00
Marius Halden
b6237b8089 carp tests: negative demotion
PR:		259528
Reviewed by:	donner
MFC after:	3 weeks
Sponsored by:	Modirum MDPay
Differential Revision:	https://reviews.freebsd.org/D32760

(cherry picked from commit 847b0d07c4)
2021-11-22 02:55:07 +01:00
Kristof Provost
b0010a4931 pf tests: test NAT-ed ICMP errors
Ensure that the ICMP error is returned with the correct
source and destination addresses.

MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D32572

(cherry picked from commit 30276ef12c)
2021-11-14 00:15:37 +01:00
Mark Johnston
c5bd130deb bitset: Reimplement BIT_FOREACH_IS(SET|CLR)
Eliminate the nested loops and re-implement following a suggestion from
rlibby.

Add some simple regression tests.

Reviewed by:	rlibby, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 51425cb210)
2021-11-01 09:20:11 -04:00
Kristof Provost
9365113e89 pf tests: ensure that $nr expansion is correct
Test the $nr expansion in labels is correct, even if the optimiser
reduces the rule count.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32489

(cherry picked from commit 914ec9c78d)
2021-10-22 09:34:33 +02:00
John Baldwin
dffa7f13db crypto: Test all of the AES-CCM KAT vectors.
Previously, only test vectors which used the default nonce and tag
sizes (12 and 16, respectively) were tested.  This now tests all of
the vectors.  This exposed some additional issues around requests with
an empty payload (which wasn't supported) and an empty AAD (which
falls back to CIOCCRYPT instead of CIOCCRYPTAEAD).

- Make use of the 'ivlen' and 'maclen' fields for CIOGSESSION2 to
  test AES-CCM vectors with non-default nonce and tag lengths.

- Permit requests with an empty payload.

- Permit an input MAC for requests without AAD.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32121

(cherry picked from commit 668770dc7d)
2021-10-21 14:19:24 -07:00
Mark Johnston
54a01b5326 vfs: Permit unix sockets to be opened with O_PATH
As with FIFOs, a path descriptor for a unix socket cannot be used with
kevent().

In principle connectat(2) and bindat(2) could be modified to support an
AT_EMPTY_PATH-like mode which operates on the socket referenced by an
O_PATH fd referencing a unix socket.  That would eliminate the path
length limit imposed by sockaddr_un.

Update O_PATH tests.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 2bd9826995)
2021-10-17 17:15:44 -04:00
Mitchell Horne
d925085dcd riscv: fix VM_MAXUSER_ADDRESS checks in asm routines
There are two issues with the checks against VM_MAXUSER_ADDRESS. First,
the comparison should consider the values as unsigned, otherwise
addresses with the high bit set will fail to branch. Second, the value
of VM_MAXUSER_ADDRESS is, by convention, one larger than the maximum
mappable user address and invalid itself. Thus, use the bgeu instruction
for these comparisons.

Add a regression test case for copyin(9).

PR:		257193
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D31209

(cherry picked from commit 8babb5582e)
2021-10-15 12:22:13 -03:00
Konstantin Belousov
5018dfb90f tests/sys/fs/fusefs/read.cc: fix build on powerpc64
There sig_atomic_t is shorter than void *.
As result, it cannot keep pointer.

Assigning to void * is actually safe for us in a signal handler.

(cherry picked from commit 3fcbde5e88)
2021-10-08 00:15:05 -05:00
Alan Somers
5dc6fedeb4 fusefs: don't panic if FUSE_GETATTR fails durint VOP_GETPAGES
During VOP_GETPAGES, fusefs needs to determine the file's length, which
could require a FUSE_GETATTR operation.  If that fails, it's better to
SIGBUS than panic.

Sponsored by:	Axcient
Reviewed by: 	markj, kib
Differential Revision: https://reviews.freebsd.org/D31994

(cherry picked from commit 4f917847c9)
2021-10-07 15:43:45 -06:00
Alan Somers
4bfd530cca aio: revert the workaround for bug 251828 in the tests
This bug is no longer reproducible in 14.0-CURRENT and 13.0-RELEASE

PR:		251828
Reported by:	markj
Reviewed by:	markj
Sponsored by:	Axcient
Differential Revision: https://reviews.freebsd.org/D31535

(cherry picked from commit 825fb07c55)
2021-10-07 15:38:25 -06:00