Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(arch): translate the testcase buffer one page at a time - #507

Open
Wenzel wants to merge 1 commit into
intel:mainfrom
Wenzel:fix/testcase-buffer-page-cross-487
Open

Wenzel wants to merge 1 commit into
intel:mainfrom
Wenzel:fix/testcase-buffer-page-cross-487

Conversation

@Wenzel

@Wenzel Wenzel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

At the start harness only the first byte of the testcase buffer was translated to a physical address. Every later read and write used physical + i. A buffer that crosses a page boundary is not physically contiguous unless the guest is identity-mapped, so its tail was written into an unrelated physical page and the target never saw it.

 StartInfo                                  (src/lib.rs)
-  address: one physical address
+  pieces:  [(physical address, length)]    # one translation per 4 KiB page, adjacent ones merged

 start harness / manual start               (src/arch/mod.rs)
-  translate buffer[0]
-  read contents at physical + i
+  translate each page of the buffer
+  read contents piece by piece

 write_start
-  write testcase at physical + i
+  write testcase piece by piece

The three magic start variants and the manual start now share translate_range and start_info, which is why the diff of src/arch/mod.rs removes more than it adds.

A size variable that crosses into a page that is not physically adjacent is rejected with an error at start, not split.

One integration test, x86_64_magic_page_cross_latest, with a new target tests/rsrc/x86_64-uefi/test-page-cross.c.

Fixes #487

Evidence

UEFI is identity-mapped, so the target builds its own page tables: a two-page window whose pages map to physical frames 0 and 2 of a static array. The buffer starts 8 bytes before the end of the first page. Frame 1, which follows the first page in physical memory but is not part of the buffer, holds a canary.

tables[3][0] = (uint64_t)frames[0] | PRESENT_WRITABLE;
tables[3][1] = (uint64_t)frames[2] | PRESENT_WRITABLE;
...
uint8_t *buffer = (uint8_t *)WINDOW + PAGE_SIZE - 8;
HARNESS_START(buffer, &size);

It prints NEIGHBOUR_CLOBBERED when the canary changed and TAIL_WRITTEN when testcase bytes reached frame 2. Linux, QSP x86-64, 20 iterations, number of lines in the output:

main (ed67e1c) this branch
Simics 7.70.0 NEIGHBOUR_CLOBBERED 16, TAIL_WRITTEN 0 (test FAILED) NEIGHBOUR_CLOBBERED 0, TAIL_WRITTEN 14 (test ok)
Simics 6.0.185 NEIGHBOUR_CLOBBERED 16, TAIL_WRITTEN 0 NEIGHBOUR_CLOBBERED 0, TAIL_WRITTEN 14

Iterations that print neither had a testcase of 8 bytes or less.

On Simics 7 the test runs through cargo test. On Simics 6 the same test script was run by hand in a project with the module built with SIMICS_BASE=simics-6.0.185, as the test harness here only knows the Simics 7 install.

On this branch: lib unit tests 48 passed, 1 ignored. cargo clippy -r is clean.

Not run: the manual start path, architectures other than x86-64, a Linux or Windows guest, the rest of the integration suite.

Merge Danger

Door: two-way

Blast Radius: moderate

Every start harness and manual start goes through the rewritten code, on all architectures. For an identity-mapped buffer the result is one piece, the same addresses as before.

The page step is fixed at 4 KiB, the smallest page size of the supported architectures. Larger pages cost extra translations at start, not correctness.

A buffer whose later pages are not mapped is now an error at start. Before, the bytes were written to whatever followed the first page.

🤖 Generated with Claude Code

Only the first byte of the buffer was translated and the rest was
accessed at physical + i. A buffer crossing a page boundary is not
physically contiguous unless the guest is identity-mapped, so its tail
was written into an unrelated physical page.

StartInfo now holds (physical address, length) pieces. A size variable
that crosses into a non-contiguous page is rejected at start.

Fixes intel#487
@Wenzel
Wenzel force-pushed the fix/testcase-buffer-page-cross-487 branch from 8bf5ba1 to ee23a31 Compare November 24, 2026 21:38

This branch has not been deployed

No deployments
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.

Testcase buffer is assumed physically contiguous: inputs crossing a page boundary corrupt guest memory

1 participant