HomeFreeBSD

vfs_vnops.c: Fix vn_generic_copy_file_range() for truncation

Description

vfs_vnops.c: Fix vn_generic_copy_file_range() for truncation

When copy_file_range(2) was first being developed,
*inoffp + len had to be <= infile_size or an error was
returned. This semantic (as defined by Linux) changed
to allow *inoffp + len to be greater than infile_size and
the copy would end at *inoffp + infile_size.

Unfortunately, the code that decided if the outfd should
be truncated in length did not get updated for this
semantics change.
As such, if a copy_file_range(2) is done, where infile_size - *inoffp
is less that outfile_size but len is large, the outfd file is truncated
when it should not be. (The semantics for this for Linux is to not
truncate outfd in this case.)

This patch fixes the problem. I believe the calculation is safe
for all non-negative values of outsize, *outoffp, *inoffp and insize,
which should be ok, since they are all guaranteed to be non-negative.

Note that this bug is not observed over NFSv4.2, since it truncates
len to infile_size - *inoffp.

PR: 276045

(cherry picked from commit 2319ca6a01816f7fc85d623097c639f239e18c6a)

Details

Provenance
rmacklemAuthored on Dec 31 2023, 11:55 PM
Parents
rG7bad06cd0d8b: tcp: always set tcp_tun_port to a correct value
Branches
Unknown
Tags
Unknown