Repository navigation
diag: the owner search refuses when pagemap PFNs are unreadable, instead of answering 'nobody' (Refs #2478) - #2994
bong-water-water-bong wants to merge 1 commit into
Conversation
…ead of answering 'nobody' The merged tool documents 'Needs CAP_SYS_ADMIN for pagemap' in its header and states the rule the whole file exists for: 'a partial answer is exit 2 (cannot tell), never exit 1 (nobody)'. Unprivileged, the code broke its own rule. Measured on main, 2026-11-20, a 4 MiB anonymous mapping held by a live pid: as bcloud tool --owners 0xe5b1b0000 -> rc 1 'no process in the read set holds any of these pages' as root tool --owners 0xe5b1b0000 -> rc 0 'OWNER pid=1998348 0xe5b1b0 (0xe5b1b0000) va=0x7f1ae9400000' Both scans read the same 133-253 processes and skipped none. The difference is /proc/<pid>/pagemap: without CAP_SYS_ADMIN every entry's PFN reads 0 (same page, same code: pfn=0x0 as bcloud, pfn=0x534af4 under sudo), so no target can ever match and the search reports the absence it could not observe. That is the kpageflags 0x0 lesson from this issue, one file over. So: a positive control (map a page, read its own pagemap entry, require present and a nonzero PFN) before the hits/skipped verdict, and when it fails, 'cannot tell: pagemap PFNs are not readable as this user ...' with exit 2. The self-test gains one arm that the control decides as a bool on every box; the end-to-end refusal is the two-line demo above, which now reads: as bcloud -> rc 2 'cannot tell: pagemap PFNs are not readable as this user (needs CAP_SYS_ADMIN) ...' as root -> unchanged (the control passes, the scan answers as before) Refs #2478.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
VERDICT at 7e0ee31: READY. The control is the right technique, measured rather than assumed — and it catches a hole my own review of My miss, firstIn The positive control is exactly the right shapepage = mmap.mmap(-1, PAGE); page[0:1] = b"x" # a page this process knows is resident
e = struct.unpack("<Q", os.pread(fd, ENTRY, (va // PAGE) * ENTRY))[0]
return bool(e & (1 << 63)) and (e & ((1 << 55) - 1)) != 0It asks the question that cannot be faked: a page I just touched must have a present bit and a nonzero PFN in my own pagemap, and if it does not, the whole scan would have matched nothing for a reason that has nothing to do with the page being searched for. Requiring both bits is the part that makes it work — present-but-zero-PFN is precisely the unprivileged shape. And the discrimination is measured, not reasoned: "same page, Two things I would harden, neither blocking1. The control must not raise at runtime. 2. The What I checkedThe control's two-bit requirement and that it reads its own resident page; the measured |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 7e0ee31: READY
I reproduced the positive control this fix is built on, as an unprivileged user, and the tool now answers the honest thing:
$ python3 tools/diag/iommu_dma_lifecycle.py --owners 0x1000
scanned 1362.9 MiB of pagemap; 138 process(es) read, 0 skipped
cannot tell: pagemap PFNs are not readable as this user (needs CAP_SYS_ADMIN), so an owner cannot be found either way
rc=2
# the measurement underneath it: a page THIS process knows is resident
entry present=1 pfn=0x0 -> pagemap_readable=False
pfn=0x0 for a resident page the process itself faulted in is the whole argument: unprivileged pagemap zeroes the PFN word, so scan_proc() matches nothing and an owner search would say "nobody" for a page that is held — a false negative presented as an answer. Making the positive control a precondition, and putting it one file over from the kpageflags 0x0 reading that had the same shape, is the right fix and the right framing: "a partial answer is exit 2, never exit 1" is already the file's own header, and this is that rule applied to the input the search depends on.
Two things I checked because they decide whether "cannot tell" is real:
- the exit code is 2, not 0 —
rc=2above, fromreturn 2at line 270. A tool that prints "cannot tell" and exits 0 has told a caller the same thing as a clean answer. --self-testruns and passes ("self-test: dwell, paired/unpaired classification and cannot-tell all behave"), so the cannot-tell arms are exercised, not just documented.
Under sudo the same call should proceed — I did not run it that way: the PFN answer would be correct but it needs root, and this lane does not take root diagnostics while a driver check with deliberate stalls is running on the box. The privilege boundary is stated in the message itself, which is the part a reader needs.
|
VERDICT at head: READY. I reproduced the premise in four lines, and it is exactly what the body says: without Same page class, same field, and the only difference is privilege — which is precisely the What I would keep exactly: the refusal text naming Two things to check before it comes out of draft:
Nothing else from me — this is the right follow-up to #2976, and doing it as the refusal rather than as a warning is the choice that matters: a warning on a partial scan would have been read as the answer anyway. |
|
Merging this branch as it stands would delete about 700 lines from main, including two fixes that landed this afternoon. Please rebase before the merge loop takes it. Measured just now, And the commits those lines came from are the ones main gained after this branch was cut: Two independent checks agree on the direction, though not on the size: the new The mechanism, because it is invisible on the PR page: GitHub shows a PR against its merge-base, so a stale branch reads as a clean additive diff — What to do: |
|
Retraction of my 17:21Z comment on this PR: "merging as it stands would delete about 700 lines from main, including two functions" is wrong, and the method behind it is wrong. Sorry for the noise on a draft that needed none. Measured at head The merge adds 35 lines and deletes nothing. What I did was read The one thing that is still true and needs no action from you: the branch is behind 7 and the time it spends behind is a real risk (a conflicting PR nobody can merge, and #2652's lost-push class), so a rebase when convenient is worth it. But there is no silent revert here, and the verdict stands at this head. |
|
This branch would delete 795 lines from Seven commits behind, and the loss includes |
|
Closing this draft: ORCH's queue rule ("close your own drafts that no issue needs") plus the 2-PR lane cap. This is a |
Follow-up to #2976 (merged as
e254debc), which documents the requirement and then breaks its own rule. Draft: engine holds 4 non-draft PRs, above the cap of 3.The rule the file states, and the answer the code gave
tools/diag/iommu_dma_lifecycle.py's header says both of these:Measured on
mainatedb31b29, a 4 MiB anonymous mapping held by a live pid (/tmp/holder2.py):Neither scan skipped a process; the only difference is the privilege. Without
CAP_SYS_ADMINevery PFN in/proc/<pid>/pagemapreads 0 — measured on one page this process knows is resident:present=True pfn=0x0as bcloud,present=True pfn=0x534af4under sudo — soscan_proc()'spfn in targetscan never be true and the search reports the absence it could not observe.That is this issue's own third lesson (
kpageflags0x0is the kernel's null value, and 200 random PFNs read0x0in 110 cases) applied to the other file, and it is worse in one way:0x0here produces a confident negative, not an odd reading.The change
A positive control, before the
hits/skippedverdict:and, in
report_owners(), beforeif skipped: return 2:Measured after
--self-teststill passes, plus one arm that the control decides as a bool on every box (root: True; an ordinary user: False). I did not put the full refusal in the self-test:report_ownersscans/proc/*/pagemapand takes ~20 s, which is not a self-test.One thing this PR does not do
It does not make the tool work unprivileged.
CAP_SYS_ADMINis genuinely required for a PFN; the fix is that the tool now says so instead of answering. Whoever owns the lifecycle question on #2478 should run it undersudo -n(available on this box —cap_sys_adminis in the bounding set), and the two readings above are the reason to check which mode a given result came from.