Commit 1255416
committed
fix(uffd): treat UFFDIO_COPY EAGAIN and partial copies as soft, let kernel redeliver
Folds audit findings #1 and #7 into one commit since they share the same
error arm in faultPage. The kernel surfaces concurrent mm churn (e.g.
balloon-driven madvise(MADV_DONTNEED), mremap, fork against the same mm)
through UFFDIO_COPY in two distinct ways: as an EAGAIN errno from the
syscall, or — once UFFD_FEATURE_EVENT_REMOVE is enabled — through the
partial-copy convention where the syscall returns 0 and cpy.copy carries
either -EAGAIN or 0..pagesize. Hugetlb pages can also surface a positive
short copy if a fault preempts the operation mid-page (#7).
Pre-#2520 the latter path went through fmt.Errorf("UFFDIO_COPY copied N
bytes...") and fell into the catch-all writeErr != nil arm — which calls
onFailure() / fdExit.SignalExit(), tears the uffd serve loop down, and
crashes the sandbox the moment the guest touches an unmapped page. The
pre-existing errno-EAGAIN soft handler covered only the syscall errno
path.
Move the partial-copy classification into a small helper so both surfaces
collapse onto the existing EAGAIN-returning-(false, nil) branch in
faultPage. No retry budget — matches Firecracker's reference handler in
src/firecracker/examples/uffd/uffd_utils.rs (Err(PartiallyCopied(n)) if
n == 0 || n == -EAGAIN ⇒ return false). Add a uffd.copy_eagain span
attribute for observability.
Tests: unit-test classifyCopyResult directly. faultPage doesn't expose
an Fd seam to mock UFFDIO_COPY without an interface refactor that would
materially expand the diff; per the audit's "smallest pragmatic test"
guidance the classifier covers the new branching and the existing
cross-process matrix tests cover the integration path.1 parent efa01a5 commit 1255416
3 files changed
Lines changed: 106 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
159 | | - | |
160 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
161 | 178 | | |
162 | 179 | | |
163 | 180 | | |
| |||
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
530 | | - | |
531 | | - | |
532 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
533 | 537 | | |
534 | 538 | | |
535 | 539 | | |
| |||
0 commit comments