HomeFreeBSD

FreeBSD: Fix RLIMIT_FSIZE handling for block cloning

Description

FreeBSD: Fix RLIMIT_FSIZE handling for block cloning

ZFS implements copy_file_range(2) using block cloning when possible.
This implementation must respect the RLIMIT_FSIZE limit.

zfs_clone_range() already checks the limit, so it is safe to remove this
check in zfs_freebsd_copy_file_range(). Moreover, the removed check
produces false positives: the length passed to copy_file_range(2) may be
larger than the input file size; as the man page notes, "for best
performance, call copy_file_range() with the largest len value
possible." In particular, some existing code passes SSIZE_MAX there.

The check in zfs_clone_range() clamps the length to the input file's
size before checking, but the removed check uses the caller supplied
length, so something like

$ echo a > /tmp/foo
$ limits -f 1024 cat /tmp/foo > /tmp/bar

fails because FreeBSD's cat(1) uses copy_file_range(2) in the manner
described above.

Reported-by: Philip Paeps <philip@FreeBSD.org>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>

Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>

Details

Provenance
markjAuthored on Jul 23 2024, 2:20 PM
Tony Hutter <hutter2@llnl.gov>Committed on Aug 8 2024, 5:43 PM
Parents
rG1f5bf91a85e9: Fix memory corruption during parallel zpool import with -o cachefile (#16419)
Branches
Unknown
Tags
Unknown