Skip to content

Fix negative UFFDIO_COPY result handling - #91

Open
dgreid wants to merge 1 commit into
bytecodealliance:mainfrom
dgreid:topic/copy_partial_error
Open

Fix negative UFFDIO_COPY result handling#91
dgreid wants to merge 1 commit into
bytecodealliance:mainfrom
dgreid:topic/copy_partial_error

Conversation

@dgreid

@dgreid dgreid commented Aug 25, 2026

Copy link
Copy Markdown

The kernel can return EAGAIN with uffdio_copy.copy set to -EAGAIN when a non-cooperative memory-map change races with UFFDIO_COPY. Casting that value to usize incorrectly reports a huge partial copy.

Only construct PartiallyCopied when copy is positive. Return CopyFailed for zero or negative results.

Kernel source:
https://github.com/torvalds/linux/blob/95567729173e62e0e60a1f8ad9eb2e1320a8ccac/fs/userfaultfd.c#L1587-L1591

The kernel can return EAGAIN with uffdio_copy.copy set to -EAGAIN
when a non-cooperative memory-map change races with UFFDIO_COPY.
Casting that value to usize incorrectly reports a huge partial copy.

Only construct PartiallyCopied when copy is positive. Return
CopyFailed for zero or negative results.

Kernel source:
https://github.com/torvalds/linux/blob/95567729173e62e0e60a1f8ad9eb2e1320a8ccac/fs/userfaultfd.c#L1587-L1591

Signed-off-by: Dylan Reid <dgreid@fb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant