Bug 266611 - copy_file_range does not copy all the way to RLIMIT_FSIZE
Summary: copy_file_range does not copy all the way to RLIMIT_FSIZE
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Alan Somers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-25 17:40 UTC by Alan Somers
Modified: 2023-04-07 20:44 UTC (History)
3 users (show)

See Also:
asomers: mfc-stable13+
asomers: mfc-stable12-


Attachments
Test program (1.03 KB, text/plain)
2022-09-25 23:15 UTC, Alan Somers
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2022-09-25 17:40:33 UTC
Bug #164793 addressed the problem that VOP_WRITE, with a range that crossed the RLIMIT_FSIZE limit, did not write all the way up to that limit, as required by POSIX.  Rather, it would write nothing and return EFBIG.

VOP_COPY_FILE_RANGE has the same problem.  While POSIX does not specify copy_file_range, I think its behavior should match.

Do you all agree?
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2022-09-25 17:53:32 UTC
I think yes it should be done.  Would you handle this?
Comment 2 Alan Somers freebsd_committer freebsd_triage 2022-09-25 18:15:18 UTC
Sure, I can take it.
Comment 3 Alan Somers freebsd_committer freebsd_triage 2022-09-25 23:15:52 UTC
Created attachment 236825 [details]
Test program

Attached test program.  To use, cd to the file system under test and run.  It will call copy_file_range across the RLIMIT_FSIZE boundary and verify that the write gets truncated rather than failing.
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-09-26 21:23:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=52360ca32ff90b605ac7481fd79e6a251e8b5116

commit 52360ca32ff90b605ac7481fd79e6a251e8b5116
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2022-09-25 22:53:36 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2022-09-26 21:22:29 +0000

    copy_file_range: truncate write if it would exceed RLIMIT_FSIZE

    PR:             266611
    MFC after:      2 weeks
    Reviewed by:    kib
    Differential Revision: https://reviews.freebsd.org/D36706

 sys/fs/fuse/fuse_vnops.c               |  15 +++--
 sys/fs/nfsclient/nfs_clvnops.c         |   8 ++-
 sys/kern/vfs_vnops.c                   |  14 ++--
 tests/sys/fs/fusefs/copy_file_range.cc | 113 +++++++++++++++++++++++++--------
 4 files changed, 115 insertions(+), 35 deletions(-)
Comment 5 Alan Somers freebsd_committer freebsd_triage 2022-09-26 21:25:06 UTC
Fixed in main.  No MFC to stable/12 , because stable/12 lacks copy_file_range.
Comment 6 commit-hook freebsd_committer freebsd_triage 2022-10-12 04:50:33 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0733dd8a9353a1b9796ffeca0120c5c3642df48b

commit 0733dd8a9353a1b9796ffeca0120c5c3642df48b
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2022-09-25 22:53:36 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2022-10-12 04:49:39 +0000

    copy_file_range: truncate write if it would exceed RLIMIT_FSIZE

    PR:             266611
    Reviewed by:    kib
    Differential Revision: https://reviews.freebsd.org/D36706

    (cherry picked from commit 52360ca32ff90b605ac7481fd79e6a251e8b5116)

 sys/fs/fuse/fuse_vnops.c               |  15 +++--
 sys/fs/nfsclient/nfs_clvnops.c         |   8 ++-
 sys/kern/vfs_vnops.c                   |  14 ++--
 tests/sys/fs/fusefs/copy_file_range.cc | 113 +++++++++++++++++++++++++--------
 4 files changed, 115 insertions(+), 35 deletions(-)