Commit graph

32 commits

Author SHA1 Message Date
Gordon Bergling 742f4b7758 tarfs(5): Grammar fix for a source code comment
- s/the the/of the/

MFC after:i	3 days
2024-04-20 11:21:54 +02:00
Mark Johnston a0895e394d tarfs: Implement VOP_BMAP
This lets tarfs provide readahead/behind hints to the VFS, which helps
memory-mapped I/O performance, important when running faulting in
executables out of a tarfs mount as one might if tarfs is used to back
the root filesystem, for example.  The improvement is particularly
noticeable when the backing tarball is zstd-compressed.

The implementation simply returns the extent of the virtual block
containing the target offset, clamped by the maximum I/O size.  This is
perhaps simplistic; it effectively just chooses values that would
correspond to a single VOP_READ call in tarfs_read_file().

Reviewed by:	des, kib
MFC after:	1 month
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D44626
2024-04-05 11:14:36 -04:00
Mark Johnston 91eca18551 tarfs: Inherit mnt_iosize_max from the lower vnode
There is no obvious reason to use a value smaller than that.

Reviewed by:	des, kib
MFC after:	1 week
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D44627
2024-04-04 10:54:06 -04:00
Dag-Erling Smørgrav 0238d3711d tarfs: Fix 32-bit build.
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D44613
2024-04-03 16:24:05 +02:00
Dag-Erling Smørgrav 584e1c355a tarfs: Ignore global extended headers.
Previously, we would error out if we encountered a global extended
header, because we don't know what it means.  This doesn't really
matter though, and traditionally, tar implementations have either
ignored them or treated them as plain files, so just ignore them.
This allows tarfs to mount tar files created by `git archive`.

MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44600
2024-04-03 11:55:06 +02:00
Dag-Erling Smørgrav b1fd95c9e2 tarfs: Support paths that spill into exthdrs.
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44599
2024-04-03 11:55:01 +02:00
Dag-Erling Smørgrav cbddb2f02c tarfs: Fix checksum on 32-bit platforms.
MFC after:	3 days
Fixes:		b56872332e47786afc09515a4daaf1388da4d73c
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D44261
2024-03-07 09:15:54 +01:00
Dag-Erling Smørgrav 0118b0c8e5 tarfs: Fix checksum calculation.
The checksum code assumed that struct ustar_header filled an entire
block and calculcated the checksum based on the size of the structure.
The header is in fact only 500 bytes long while the checksum covers
the entire block (“logical record” in POSIX terms).  Add padding and
an assertion, and clean up the checksum code.

MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44226
2024-03-06 17:14:01 +01:00
Dag-Erling Smørgrav e212f0c066 tarfs: Remove unnecessary hack and obsolete comment.
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D44203
2024-03-06 17:13:57 +01:00
Dag-Erling Smørgrav c291b7914e tarfs: Avoid overflow in exthdr calculation.
MFC after:	3 days
PR:		277420
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D44202
2024-03-06 17:13:54 +01:00
Dag-Erling Smørgrav 8427d94ce0 tarfs: Improve validation of numeric fields.
MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	sjg, allanjude
Differential Revision:	https://reviews.freebsd.org/D44166
2024-03-06 17:13:51 +01:00
Dag-Erling Smørgrav 38b3683592 tarfs: Fix two input validation issues.
* Reject hard or soft links with an empty target path.  Currently, a
  debugging kernel will hit an assertion in tarfs_lookup_path() while
  a non-debugging kernel will happily create a link to the mount root.

* Use a temporary variable to store the result of the link target path,
  and copy it to tnp->other only once we have found it to be valid.
  Otherwise we error out after creating a reference to the target but
  before incrementing the target's reference count, which results in a
  use-after-free situation in the cleanup code.

* Correctly return ENOENT from tarfs_lookup_path() if the requested
  path was not found and create_dirs is false.  Luckily, existing
  callers did not rely solely on the return value.

MFC after:	3 days
PR:		277360
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	sjg
Differential Revision:	https://reviews.freebsd.org/D44161
2024-03-06 17:13:42 +01:00
Mateusz Guzik ba8cc6d727 vfs: use __enum_uint8 for vtype and vstate
This whacks hackery around only reading v_type once.

Bump __FreeBSD_version to 1400093
2023-07-05 15:06:30 +00:00
Dag-Erling Smørgrav 91e03758de tarfs: Don't use IO_DIRECT when reading from tarball.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D40612
2023-06-20 10:02:10 +00:00
Zhenlei Huang c3c5e6c3e6 tarfs: Use the existing CTLFLAG_RWTUN flag definition
Use it when possible, instead of separated flags.

No functional change intended.

Reviewed by:	hselasky, erj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D39466
2023-04-12 12:20:38 +08:00
Simon J. Gerraty a02d9cad77 tarfs_mount allow control of vfs_mountedfrom
We default to passing the path of the tar file to vfs_mountedfrom
so we can tell where a filesystem was mounted from.
However this can make the output of mount(8) hard to read.

Allow things like:

	mount -t tarfs -o as=`basename $tar` $tar /mnt

so "as" is recorded instead of $tar

Reviewed by:	des
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org/D39273
2023-03-28 10:57:26 -07:00
Dag-Erling Smørgrav ef184e989b tarfs: Fix backtracking during node creation.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D39082
2023-03-16 11:31:22 +00:00
Dag-Erling Smørgrav e81d55b439 tarfs: Support tar files which include file modes with permissions.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D39020
2023-03-16 11:31:22 +00:00
Dag-Erling Smørgrav fd8c98a52f tarfs: Correctly track link count.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D39019
2023-03-16 11:31:22 +00:00
Dag-Erling Smørgrav b1218349ed tarfs: Set mountedfrom correctly.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	sjg, kib
Differential Revision:	https://reviews.freebsd.org/D38930
2023-03-07 17:20:49 +00:00
Dag-Erling Smørgrav d481dcee72 tarfs: Really prevent descending into a non-directory.
The previous fix was incorrect: we need to verify that the current node, if it exists, is not a directory, but we were checking the parent node instead.  Address this, add more tests, and fix the test cleanup routines.

PR:		269519, 269561
Fixes:		ae6cff8973
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38645
2023-02-20 21:29:19 +00:00
Dag-Erling Smørgrav bf84156b24 tarfs: Use a separate debug bit for bounce buffer usage.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38588
2023-02-16 00:40:45 +00:00
Dag-Erling Smørgrav ae6cff8973 tarfs: Don't panic if the parent of a new node is not a directory.
PR:		269519
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38587
2023-02-15 02:13:11 +00:00
Dag-Erling Smørgrav af0435e16b tarfs: Fix deadlock between descent and ascent in tarfs_lookup().
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38486
2023-02-10 17:19:45 +00:00
Dag-Erling Smørgrav ce6a0c776b tarfs: Fix issues revealed by static analysis and testing.
* tarfs_alloc_mount(): Remove an unnecessary null check (CID 1504505) and an unused variable.

* tarfs_alloc_one(): Verify that the file size is not negative (CID 1504506).  While there, also validate the mode, owner and group.

* tarfs_vget(), tarfs_zio_init(): Explicitly ignore return value from getnewvnode(), which cannot fail (CID 1504508)

* tarfs_lookup_path(): Fix a case where a specially-crafted tarball could trigger a null pointer dereference by first descending into, and then backing out of, a previously unknown directory. (CID 1504515)

* mktar: Construct a tarball that triggers the aforementioned null pointer dereference.

Reported by:	Coverity
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D38463
2023-02-09 17:35:47 +00:00
Dag-Erling Smørgrav 146d9da6c2 tarfs: Silence warnings when no supported compression is enabled.
Some of the code in sys/fs/tarfs/tarfs_io.c is not specific to zstd, but is still only used when some form of decompression is enabled.  Put it behind #ifdef TARFS_ZIO to silence warnings.

Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38415
2023-02-07 18:31:25 +01:00
Dag-Erling Smørgrav a8fc2fe3af tarfs: Remove unnecessary code.
Reported by:	kib
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38401
2023-02-06 17:24:32 +01:00
Dag-Erling Smørgrav c9ff56ce2d tarfs: Terminate dirents before copying them out.
Reported by:	markj
Sponsored by:	Juniper Networks, Inc.
Sponsored bu:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D38400
2023-02-06 17:24:27 +01:00
Dag-Erling Smørgrav 57aa630220 tarfs: Remove unused code.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
2023-02-02 23:16:17 +00:00
Dag-Erling Smørgrav cf93505e8d tarfs: Fix non-ZSTDIO build.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
2023-02-02 23:25:34 +01:00
Dag-Erling Smørgrav fb53e7adaf tarfs: Fix 32-bit build.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
2023-02-02 21:39:10 +01:00
Dag-Erling Smørgrav 69d94f4c76 Add tarfs, a filesystem backed by tarballs.
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Reviewed by:	pauamma, imp
Differential Revision:	https://reviews.freebsd.org/D37753
2023-02-02 18:19:29 +01:00