Skip to content

Fix negative UFFDIO_COPY result handling - #91

Merged
hikalium merged 1 commit into
bytecodealliance:mainfrom
dgreid:topic/copy_partial_error
Oct 17, 2026
Merged

hikalium merged 1 commit into
bytecodealliance:mainfrom
dgreid:topic/copy_partial_error

Conversation

@dgreid

@dgreid dgreid commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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>

@hikalium hikalium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for catching this!

@hikalium
hikalium merged commit f74db17 into bytecodealliance:main Oct 17, 2026
3 checks passed
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.

2 participants