bug-coreutils@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: 60489@debbugs.gnu.org
Subject: bug#60489: Programs should exit after EIO from FICLONE or copy_file_range()
Date: Sun, 1 Jan 2023 22:36:20 -0800	[thread overview]
Message-ID: <20230102063620.GA1629213@rfd.leadboat.com> (raw)

Because Debian coreutils 9.1-1 "cp" silently falls back to copy_file_range()
after FICLONE reports EIO, "cp" can transfer incorrect bytes.  Linux syscalls
having a file descriptor parameter report EIO after a fault in the underlying
device.  The affected file is not recoverable in the general case, but syscall
outcomes after the EIO don't reflect that.  For example, consider FICLONE
returning EIO for a fault during source file writeback.  The kernel will mark
"clean" the affected page cache entries and clear the EIO state.  If the page
cache evicts those pages, their file offsets revert to the last written-back
values if any, else zeros.  If userspace issues a syscall that bypasses the
page cache, like copy_file_range() or another FICLONE, that syscall clones the
last written-back state or zeroes.  See
https://lore.kernel.org/linux-xfs/20221108172436.GA3613139@rfd.leadboat.com
for a "cp" and "cat" test script, background, and discussion.

I recommend instead reporting the EIO and terminating when FICLONE or
copy_file_range() fails with EIO.  One could argue that ENOSPC also warrants
termination, since no fallback reduces space usage.  For other errno values,
fallback to the next transfer strategy, like today.  An alternative would be
to fallback from FICLONE to copy_file_range() only after known-appropriate
errors EBADF, EINVAL, EOPNOTSUPP, ETXTBSY, and EXDEV.  That alternative wins
if future FICLONE reports an additional termination-deserving errno value.
Since just EIO needs termination today, I bet new errno values are more likely
than not to deserve fallback.  What do you think?

Thanks,
nm




             reply	other threads:[~2023-01-02  8:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-02  6:36 Noah Misch [this message]
2023-01-02 13:19 ` bug#60489: Programs should exit after EIO from FICLONE or copy_file_range() Pádraig Brady
2023-01-02 13:28   ` Andreas Schwab
2023-01-02 16:22     ` Pádraig Brady
2023-01-06 14:47       ` Pádraig Brady

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-coreutils

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230102063620.GA1629213@rfd.leadboat.com \
    --to=noah@leadboat.com \
    --cc=60489@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).