Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address caprevoke consistency check failures #2221

Merged
merged 10 commits into from
Oct 23, 2024

Conversation

markjdb
Copy link
Contributor

@markjdb markjdb commented Sep 13, 2024

The main changes here are the commits which modify pmap_caploadgen_update() to avoid skipping superpages. With these, I can run a desktop session with the assert_consistent_clg checks enabled.

The patches are a bit incomplete:

  • I haven't updated the riscv pmap accordingly, though that should be straightforward.
  • L1 superpages are still not handled properly.

I have some plans to further improve superpage handling, but present the PR as-is since it should be sufficient to address the panics observed in syzkaller.

Copy link
Member

@nwf nwf left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@markjdb markjdb force-pushed the dev-caprevoke-superpage branch from 6afefbc to 7665985 Compare October 9, 2024 12:39
@markjdb
Copy link
Contributor Author

markjdb commented Oct 9, 2024

The latest push updates riscv as well.

@markjdb
Copy link
Contributor Author

markjdb commented Oct 16, 2024

Could anyone with easy VPN access tell me what the riscv failures are? cheribsdtest passes for me in QEMU.

@jrtc27
Copy link
Member

jrtc27 commented Oct 16, 2024

image

--cheribsd/build-bench-kernels to include the -NODEBUG kernels locally (somewhat poorly named option thanks to what the kernel configs were called for CHERI-MIPS).

@jrtc27
Copy link
Member

jrtc27 commented Oct 16, 2024

Though I don't know why only the -NODEBUG kernels see that error, the shadowing happens regardless...

Print the PTE as well, since the debugger isn't able to retrieve it.

While here, remove an XXX comment in the arm64 implementation:
pmap_pte() returns NULL if the address is not mapped, which is a
perfectly ordinary state of affairs.
If any entry in a L3C mapping has ATTR_SC set (i.e., it is cap-dirty),
the flag must be propagated to all other entries when demoting.
We don't need to check each PTE: we already verify that the first PTE in
the run does not have CDBM set and SC clear, and in the loop we check
that the PTEs are identical in virtually all attributes.

No functional change intended.
As in pmap_promote_l2(), we should avoid promotion if the mapping allows
capability stores but is not yet capability-dirty.
Previously, pmap_caploadgen_update() would return PMAP_CAPLOADGEN_UNABLE,
which is overloaded to cover the case where no mapping exists at all.  In this
case, the MI machinery will look up the page via the VM object and scan it.  If
the 4KB page contains capabilities, vm_fault() is called upon to scan the page
and update the pmap, which breaks the large mapping as a side effect.

However, if the page is capability-clean, the large mapping will not be demoted,
and during a background scan the subsequent pmap_caploadgen_update() will fail
to update the CLG in the L2 or L3C PTE.  Thus, the scan will end with some PTEs
carrying the wrong CLG.  When the GCLG is incremented during a subsequent scan,
the kernel may fail to interpose load-cap operations from that mapping, which
could potentially allow revoked capabilities to be leaked.

Fix the problem by demoting the mapping as soon as it is encountered.  This is
not optimal (we end up demoting clean superpage mappings), but it fixes the
problem of overloading PMAP_CAPLOADGEN_UNABLE and removes an assumption about
pmap_enter()'s behaviour (i.e., that it'll demote L2 and L3C mappings), and
pmap_caploadgen_update() already reconstructs superpage mappings when possible.

L1 largepage mappings are left unhandled for now.
The background scan opportunistically rebuilds L2 superpage mappings.
Do the same for L3C mappings.

Re-enable creation of read-only L3C mappings in pmap_enter_l3c().  Since
that commit appeared, upstream has implemented L3C promotion, and
pmap_caploadgen_update() now handles L3C mappings by demoting rather
than going through the fault handler.
- Use a sysctl to enable it, rather than requiring it be configured at
  compile-time
- Skip over map entries that definitely do not contain capabilities, including
  the quarantine bitmap (OBJ_NOCAP)
When forking, the GCLG and LCLGs may be out of sync if a new revocation epoch
was opened (bumping the GCLG) but the background scan has not yet started
(background scans block fork()).  This can arise if a cheri_revoke() is called
without either of the CHERI_REVOKE_LAST_PASS and CHERI_REVOKE_ASYNC flags.
vm_cheri_assert_consistent_clg() must be called with the VM map lock
held.  Also make sure to only call it after the epoch is closed, i.e.,
we have set the revocation state to CHERI_REVOKE_ST_NONE.
This is required when promoting or demoting superpages, both of which may be
done here.
@markjdb markjdb force-pushed the dev-caprevoke-superpage branch from 88254ab to 9e7f370 Compare October 16, 2024 15:53
@markjdb
Copy link
Contributor Author

markjdb commented Oct 16, 2024

Though I don't know why only the -NODEBUG kernels see that error, the shadowing happens regardless...

Thank you. Indeed, I'm quite surprised that I didn't get a warning when building locally.

@bsdjhb bsdjhb merged commit 938846c into CTSRD-CHERI:dev Oct 23, 2024
29 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.

4 participants