Commit Graph

1242 Commits

Author SHA1 Message Date
Alan Somers
79ec7ebf88 fusefs: fix a cached attributes bug during directory rename
When renaming a directory into a different parent directory, invalidate
the cached attributes of the new parent.  Otherwise, stat will show the
wrong st_nlink value.

Reviewed by:	ngie
Differential Revision: https://reviews.freebsd.org/D34336

(cherry picked from commit e8553be9bc)
2022-03-09 09:59:49 -07:00
Ed Maste
71f452d58c zfs: Update test format strings to match variable typtes
And drop stray 'd' from the end of some printed numbers.  I assume this
was the result of someone thinking u is a printf length modifier for d,
not a format specifier itself.

Reviewed by:	kevans, rew
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34387

(cherry picked from commit f27fb06cad)
2022-03-07 19:33:21 -05:00
Mark Johnston
45014f965e tests: Fix the test plan for closefrom_test
Fixes:	f3f3e3c44d ("fd: add close_range(..., CLOSE_RANGE_CLOEXEC)")
Reported by:	Jenkins

(cherry picked from commit 3a01dcc99f)
2022-03-07 12:15:47 +00:00
Mateusz Guzik
8891979494 fd: add close_range(..., CLOSE_RANGE_CLOEXEC)
For compatibility with Linux.

MFC after:	3 days
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D34424

(cherry picked from commit f3f3e3c44d)
2022-03-07 12:15:47 +00:00
Arka Sharma
6a73d96ac4 mmap map_at_zero test: handle W^X
Use kern.elfXX.allow_wx to decide whether to map W+X or W-only memory.

Future work could expand this test to add an "allow_wx" axis to the
test matrix, but I would argue that a separate test should be written,
since that's orthogonal to map_at_zero.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit 766c2466ff)
2022-03-03 08:20:07 -06:00
Alan Somers
837e2f537c [skip ci] fusefs: delete a stray comment from 91972cfcdd
(cherry picked from commit 0b6a34acda)
2022-03-02 16:37:25 -07:00
Eric van Gyzen
656de74c63 aio_md_test: label the md
Add a label to md devices created by this test.  The next time this
test leaks md devices, finding the culprit will be much easier.

Thanks to:	sobomax, for adding labels in r322969
MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit 9666cda976)
2022-03-02 15:56:30 -06:00
Eric van Gyzen
ac20fa249f aio_md_test: NUL-terminate result of readlink
readlink does not NUL-terminate the output buffer.  This led to spurious
failures to destroy the md device because the unit number was garbage.
NUL-terminate the output buffer.

Reported by:	ASLR
MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit ea0e1b19f2)
2022-03-02 15:56:30 -06:00
Eric van Gyzen
77f0c44e49 aio_md_test: fix cleanup
ATF cleanup functions cannot use functions such as ATF_REQUIRE
and atf_tc_fail.  These functions assert that a test case is
currently running, which is not true during cleanup, so the
process aborts.  Change the cleanup function to simply print
to stderr and return.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon

(cherry picked from commit c6f92e64b6)
2022-03-02 15:56:30 -06:00
Kristof Provost
e41b30c849 pf tests: Test per-anchor tables
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 7d3fc84b2d)
2022-02-28 16:38:05 +01:00
Kristof Provost
4802e21ac9 pf tests: remove a stray 'set -x'
'set -x' is very useful when debugging tests, but does not need to be
left in.

MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 7f55a9b490)
2022-02-28 16:38:05 +01:00
Andrew Turner
598e53b3d3 Stop single stepping in signal handers on arm64
We should clear the single step flag when entering a signal hander and
set it when returning. This fixes the ptrace__PT_STEP_with_signal test.

While here add support for userspace to set the single step bit as on
x86. This can be used by userspace for self tracing.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34170

(cherry picked from commit 31cf95cec7)
2022-02-22 16:23:07 +00:00
Kristof Provost
79a0d63986 pf tests: Test adding counters to an existing table
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D34132

(cherry picked from commit 1094189965)
2022-02-19 09:43:33 +01:00
Mark Johnston
e3b852f99b ktls: Disallow transmitting empty frames outside of TLS 1.0/CBC mode
There was nothing preventing one from sending an empty fragment on an
arbitrary KTLS TX-enabled socket, but ktls_frame() asserts that this
could not happen.  Though the transmit path handles this case for TLS
1.0 with AES-CBC, we should be strict and allow empty fragments only in
modes where it is explicitly allowed.

Modify sosend_generic() to reject writes to a KTLS-enabled socket if the
number of data bytes is zero, so that userspace cannot trigger the
aforementioned assertion.

Add regression tests to exercise this case.

Reported by:	syzkaller
Reviewed by:	gallatin, jhb
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 5de79eeddb)
2022-02-16 11:52:31 -05:00
Kyle Evans
d352fa2627 tests: add a basic test for argc == 0
The kernel should reject such exec()s now, early on. Instead of adding
the needed boilerplate to write a test in C, just add an -n argument for
"(n)ull argv" to the execve helper and exec this other helper that just
exits silently with argv count.

(cherry picked from commit e5b431fc0c)
2022-02-10 14:21:59 -06:00
Dimitry Andric
01cccd7048 Explicitly include semaphore.h for struct _sem in fusefs setattr test
In libc++'s __threading_support header the semaphore.h header was
implicitly included, but from version 14 onwards, this is no longer the
case, resulting in compile errors:

tests/sys/fs/fusefs/setattr.cc:740:8: error: variable has incomplete type 'sem_t' (aka '_sem')
        sem_t sem;
              ^
tests/sys/fs/fusefs/utils.hh:33:8: note: forward declaration of '_sem'
struct _sem;
       ^

MFC after:	3 days

(cherry picked from commit c9cabf9aa6)
2022-02-09 18:26:08 +01:00
Mark Johnston
a409ae5837 pf: Initialize pf_kpool mutexes earlier
There are some error paths in ioctl handlers that will call
pf_krule_free() before the rule's rpool.mtx field is initialized,
causing a panic with INVARIANTS enabled.

Fix the problem by introducing pf_krule_alloc() and initializing the
mutex there.  This does mean that the rule->krule and pool->kpool
conversion functions need to stop zeroing the input structure, but I
don't see a nicer way to handle this except perhaps by guarding the
mtx_destroy() with a mtx_initialized() check.

Constify some related functions while here and add a regression test
based on a syzkaller reproducer.

Reported by:	syzbot+77cd12872691d219c158@syzkaller.appspotmail.com
Reviewed by:	kp
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 773e3a71b2)
2022-02-07 09:10:16 -05:00
Kristof Provost
5f11f3cb1f pf tests: Provoke failure in pf_ioctl_addrule
MFC after:	3 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 4ca4193760)
2022-02-04 11:38:15 +01:00
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