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

Add CapbilityPtr and Add SuccessAddr and SuccessPtr syscall variants #4174

Merged
merged 47 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
12abe15
MetaPtr + usize/u32 changes
Aug 17, 2024
c32507d
Have MetaPtr wrap a pointer not usize
Oct 14, 2024
677183f
Link to CHERI tracking issue
Oct 14, 2024
6254b9e
Add explicit return codes for usize/ptr
Oct 14, 2024
a5ee396
Better comment for MetaPtr
Oct 14, 2024
fd51098
Fix typo
Oct 14, 2024
c97deea
Apply comment suggestions
LawrenceEsswood Oct 21, 2024
291c8f4
Rename MetaPtr -> CapabilityPtr
Oct 29, 2024
695af1b
Add comment saying into_compat is for legacy only
Oct 29, 2024
7ec6bdd
capability_ptr: update doc to reflect meaning
alevy Nov 4, 2024
d0fa5fc
Update kernel/src/syscall.rs
LawrenceEsswood Nov 8, 2024
be62a66
Update kernel/src/process.rs
LawrenceEsswood Nov 8, 2024
950deb2
Revert notes change
Nov 8, 2024
236a8ac
Remove extra cast step
Nov 8, 2024
a4e5936
Preface internal Google bug tracker
Nov 8, 2024
9ac666b
Remove as_checked_ptr until CHERI lands
Nov 8, 2024
010bf22
Change panic for assert and checked alignment too
Nov 8, 2024
604460c
Make the oddly chosen ANY permission a NONE permission
Nov 8, 2024
79b2b8d
Add provenance notes
Nov 8, 2024
6feb692
Refine CapabilityPtr description slightly
Nov 8, 2024
f800ddd
Minor changes to encode
Nov 8, 2024
2cd33d2
Move capability_ptr to utilities
Nov 8, 2024
bf24e72
Update kernel/src/process.rs
LawrenceEsswood Nov 11, 2024
d569776
Rename into_compat
Nov 11, 2024
743c8cd
Document what authority the CapabilityPtr from brk/sbrk should have
Nov 11, 2024
144269e
Do not pollute scope with Execute
Nov 11, 2024
cc0b53e
Add comment to construction of intial fn
Nov 11, 2024
45f8a44
Remove mention of CHERI
Nov 11, 2024
391dfc8
Use .cast_mut(), not as
Nov 11, 2024
8f8ce44
Document all methods on CapabilityPtr
Nov 11, 2024
a5e5a6d
More formatting/comments/name change for permissions
Nov 11, 2024
f3feec6
Style changes
Nov 11, 2024
a001b33
kernel/syscall: split out encode_syscall_return, create TRD104 subset
lschuermann Nov 8, 2024
7ea663f
kernel: fix rustdoc links
lschuermann Nov 12, 2024
9560125
Merge remote-tracking branch 'upstream/master' into meta_ptr
alevy Nov 13, 2024
670a5d0
kernel: handle_syscall: elaborate on NonNull change for CapabilityPtr
lschuermann Nov 13, 2024
3810ca8
kernel/capability_ptr: make new_with_metadata an unsafe method
lschuermann Nov 13, 2024
0709e6a
kernel/arch_helpers: remove 32bit infix from encode_syscall_return_tr…
lschuermann Nov 13, 2024
1ebf509
kernel: remove CapabilityPtr aliases for now
alevy Nov 14, 2024
d23676d
kernel: remove stale reference in upcall doc
alevy Nov 14, 2024
38a5188
kernel: remove unused syscall return variant
alevy Nov 14, 2024
08caaa5
kernel: rename capability_ptr constructor
alevy Nov 14, 2024
c6156c8
kernel: documentation nits
alevy Nov 14, 2024
a803e1e
kernel: remove SuccessUsize in favor of SuccessPtr
alevy Nov 14, 2024
096536c
kernel: fix import order nit
alevy Nov 14, 2024
3c1876b
kernel: memop: add provenance to memop returns
alevy Nov 14, 2024
37cb959
Merge remote-tracking branch 'upstream/master' into meta_ptr
lschuermann Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
kernel: rename capability_ptr constructor
  • Loading branch information
alevy committed Nov 14, 2024
commit 08caaa518e8cdc76f5f4a40bc87acb315a35a02b
6 changes: 3 additions & 3 deletions kernel/src/process_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ impl<C: Chip, D: 'static + ProcessStandardDebug> Process for ProcessStandard<'_,

let base = self.mem_start() as usize;
let break_result = unsafe {
CapabilityPtr::new_with_metadata(
CapabilityPtr::new_with_authority(
old_break as *const (),
base,
(new_break as usize) - base,
Expand Down Expand Up @@ -1978,7 +1978,7 @@ impl<C: 'static + Chip, D: 'static + ProcessStandardDebug> ProcessStandard<'_, C
// We need to construct a capability with sufficient authority to cover all of a user's
// code, with permissions to execute it. The entirety of flash is sufficient.

let init_fn = CapabilityPtr::new_with_metadata(
let init_fn = CapabilityPtr::new_with_authority(
init_addr as *const (),
fn_base,
fn_len,
Expand Down Expand Up @@ -2150,7 +2150,7 @@ impl<C: 'static + Chip, D: 'static + ProcessStandardDebug> ProcessStandard<'_, C
// code, with permissions to execute it. The entirety of flash is sufficient.

let init_fn = unsafe {
CapabilityPtr::new_with_metadata(
CapabilityPtr::new_with_authority(
init_addr as *const (),
flash_start as usize,
(self.flash_end() as usize) - (flash_start as usize),
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/utilities/capability_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ impl CapabilityPtr {
/// can thus break Tock's isolation model. As semi-trusted kernel code can
/// name this type and method, it is thus marked as `unsafe`.
///
/// TODO: Once Tock supports hardware that uses the [`CapabilityPtr`]'s
/// metdata to convey authority, this comment should incorporate the exact
/// safety conditions of this function.
// TODO: Once Tock supports hardware that uses the [`CapabilityPtr`]'s
// metdata to convey authority, this comment should incorporate the exact
// safety conditions of this function.
Copy link
Contributor

Choose a reason for hiding this comment

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

This will happen soon, correct? We already have three calls to this function with no safety justification.

It's unclear to me what the safety conditions will look like (i.e. how we will prevent capsules from breaking isolation by copying CapabilityPtrs into userspace memory).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, there are no safety requirements from rust's perspective (I would have voted "no" to making this interface unsafe) for the use of this type within the kernel. This type does not implement Deref, and is no more unsafe than the MPU configuration interfaces, which are not unsafe at present.

If we did decide that any of these might eventually be passed to the user, and there was a library invariant they should never be allowed access to kernel memory, I suppose it might say "This should never create an alias with any objects accessible by the kernel, apart from those accessed through the grant interface".

Copy link
Member

@lschuermann lschuermann Nov 14, 2024

Choose a reason for hiding this comment

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

It's unclear to me what the safety conditions will look like (i.e. how we will prevent capsules from breaking isolation by copying CapabilityPtrs into userspace memory).

Part of the reason of why I added this comment is exactly because these and other details are unclear to me. There will be safety considerations, and this is a public API, and as such this is to serve as a deterrent for anyone to rely on any stable safety conditions at this point.

Technically, there are no safety requirements from rust's perspective (I would have voted "no" to making this interface unsafe) for the use of this type within the kernel.

In a system where capabilities serve as the only memory isolation mechanism, we must ensure that any untrusted code we're invoking (such as a process) cannot violate any of Rust's safety invariants. If arbitrary capabilities can flow across this boundary on a type-level (such as ones pointing into kernel memory, originating from capsules) either the boundary would need to be unsafe, or creating these capabilities must be.

Put differently, even though these types might be safe in isolation, this doesn't mean they're safe in the presence of other interfaces that rely on certain invariants holding for these types (such as Tock's userspace-kernel boundary). One such invariant should probably be that a CapabilityPtr must not have authority over kernel memory, although we might want even stronger invariants in practice.

My argument for them being unsafe relies on the premise that there might be an API that would allow capsules to smuggle capabilities into userspace. Will this API never exist?

This type does not implement Deref, and is no more unsafe than the MPU configuration interfaces, which are not unsafe at present.

I think this is the crux: I strongly believe that the MPU configuration interfaces ought to be unsafe, following this same reasoning. We have some much weaker argument for why it might be okay for them not to be unsafe: capsules shouldn't be able to get a hold of a reference the chip's MPU type, and as such they wouldn't be able to use those "safe" interfaces (similar to "capsules will never be able to pass a CapabilityPtr into userspace"). I disagree with this line of reasoning, and there likely is a way for capsules to get a reference like this. However, that is a different discussion, orthogonal to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely agree with your premise that we have a library invariant whenever MPUs / CHERI are used that we do not allow the user access to kernel, and this very much can become language UB if the user trashes the kernel.

My objections were mostly that CHERI suddenly seems special as other MPU accesses are not considered unsafe, and on the practiically of marking the interface unsafe.

If we do mark the interface unsafe, we should surely justify at the call sites that we have enforced insolation, or else propagate unsafety requirements upwards. My suspicion is that isolation probably can't be locally argued and is likely a property of broad kernel correctness. Possibly, the scope of the entire core kernel, so we would either just have to admit defeat and say every function is unsafe, or instead lie at call sites and say we we can be certain we are not breaking safety here, even though the scope is far too broad to ever do so in full spirit.

TL;DR - this can be unsafe, but then a whole lot more should be too.

Copy link
Member

@lschuermann lschuermann Nov 14, 2024

Choose a reason for hiding this comment

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

I think I agree to the above in spirit, although I believe we will be able to end up precisely drawing the line around unsafe interfaces, and hence don't agree with the generalization in the third paragraph.

In any case, let's wait on the follow-up PR that will introduce the reality of a real capability-hardware platform where these abstract concerns will manifest into tangible isolation properties / violations. Then we can revisit these call-sites and add appropriate documentation.

#[inline]
pub unsafe fn new_with_metadata(
pub unsafe fn new_with_authority(
ptr: *const (),
_base: usize,
_length: usize,
Expand Down
Loading