Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

alistair23
Copy link
Contributor

@alistair23 alistair23 commented Oct 23, 2020

Pull Request Overview

This PR is a second attempt at my original app_id PR.

This is similar to an old PR: #1300

This PR adds a permission section to the TBF header. This permission section will contain a list of syscalls that the app is allowed and going to perform.

This only allows apps to interact with approved capsules. There are cases where we only want a single app to use a capsule. Take for example a Root of Trust (RoT) that uses I2C to control other devices. In this case we only want 1 approved app to have that control, while other (possibly malicious) apps are blocked from accessing the hardware.

We also then have a 64-bit bit mask of the commands that are allowed. Currently some capsules have large command numbers (like 100, 200 ect) and they will need to be updated in order to work with a bit mask.

The options can also be auto generated for apps. I can currently auto-generate them based on the compiled code for libtock-rs.

Security

From a thread model perspective this isn't ideal as we don't expect to always trust the TBF, see: https://github.com/tock/tock/blob/master/doc/threat_model/TBF_Headers.md

For secure applications though we can have the loader enforce/double check the permissions.

Testing Strategy

I have tested this by adding support to Elf2tab and by auto-generating the list in libtock-rs.

See tock/elf2tab#28 for Elf2tab details.

TODO or Help Wanted

A implementation in Tock after this is approved.

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@jrvanwhy
Copy link
Contributor

@gkelly I think this is related to your syscall filtering work.

@alistair23 alistair23 force-pushed the alistair/tbf-header-perms branch 5 times, most recently from c329e7b to 1c06903 Compare October 26, 2020 20:50
@jrvanwhy
Copy link
Contributor

You are correct to say that this PR is not secure under Tock's threat model.

Unfortunately, I think solving this limitation requires figuring out the app ID story. I don't think we can have a secure mechanism to enforce "only app X can do Y" unless we have a mechanism to verify that an app that claims it is X is actually X.

What we might need is a concept of resource ownership. Who "owns" a particular system call (i.e. determines who can call it)? Is it the kernel? I'm going to try to hash this out more on the core WG call and/or dev mailinglist.

@alistair23
Copy link
Contributor Author

alistair23 commented Oct 27, 2020

An app ID will have the same problem. Eventually the app ID will be stored in the TBF header as well.

My thinking here is that the loader (which we trust) can check this. For example for Tockloader could take a config file like this:

app1: "My test app"
  file: app1.elf
  appid: 0x12345678
  permissions:
    i2c: read, write
    console: write

app2: "My second app"
  file: app2.elf
  appid: 0x23456789
  permissions:
     usb
     ctap
  persistent_storage:
    write_id: 0xdeadbeef
    read_ids: 0xdeadbeef, <old_id>

Then Tockloader can compare the config file permissions with the individual app permissions to make sure they match. Then it can generate and sign a binary ready to deploy.

I'm not clear how ownership would help. Would an app own a driver? What happens if that app is compromised?

I think it makes sense to have the kernel enforce access. The question is how to tell the kernel to do that. Hard coding a function in Rust in a board specific function is one option, but seems too inflexible. Also how would that function know which app can do what, unless we trust something in the TBF header?

@alistair23 alistair23 force-pushed the alistair/tbf-header-perms branch from 1c06903 to 018b50d Compare December 3, 2020 23:23
@alevy
Copy link
Member

alevy commented Jan 11, 2021

Is this PR still reflective of the current state of the discussion?

@alistair23
Copy link
Contributor Author

I think it is

@jrvanwhy
Copy link
Contributor

Is this PR still reflective of the current state of the discussion?

Based on the current state of discussion:

  1. It is fine for an application to use this mechanism to sandbox itself, e.g. to limit the privileges an adversary would gain of the adversary compromises the app. This is equivalent to Unix daemons that drop privileges after startup.
  2. We could make tockloader read this header and tell the user what permissions the app needs before the user decides whether or not to load the app. From the perspective of the threat model, we're making the user running tockloader the arbiter of app permissions, and enforcing those permissions through a combination of tockloader and the mechanism described in this PR.
  3. We could add a permissions system to the kernel that contains a kernel-provided permissions list (keyed on application ID). The kernel would verify the list in this PR is consistent with the kernel-provided permissions for the app before loading an app. From the perspective of the threat model, the kernel-provided permissions list would be the arbiter of app permissions and this PR's mechanism would be part of the enforcement implementation.

So yes, it is consistent with the current state of the discussion. It is not a mechanism to isolate a possibly-malicious app on its own.

@alistair23
Copy link
Contributor Author

That was my understanding as well.

@hudson-ayers
Copy link
Contributor

Is tock/elf2tab#28 up to date with the design here, or are you waiting for approvals on this PR before updating the elf2tab PR?

@alistair23
Copy link
Contributor Author

tock/elf2tab#28 is up to date.

@alistair23
Copy link
Contributor Author

Ping!

@hudson-ayers
Copy link
Contributor

I looked through this PR and the corresponding elf2tab PR and think the design looks reasonable. I assume the idea is that this would be implemented by the already existing system call filtering mechanism -- perhaps the docs should mention that somewhere?

@alistair23 alistair23 force-pushed the alistair/tbf-header-perms branch from dcf335d to 7f4cc85 Compare February 12, 2021 19:20
Copy link
Contributor

@phil-levis phil-levis left a comment

Choose a reason for hiding this comment

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

Following the discussion on the core call, this proposal was generally accepted, with one change, the exact format of a permissions object. In order to support sparse identifier spaces (although perhaps not as efficiently), there should be an offset field. Detailed comments inline.

@alistair23 alistair23 force-pushed the alistair/tbf-header-perms branch from 7f4cc85 to edc6886 Compare March 3, 2021 20:41
@alistair23
Copy link
Contributor Author

Ping!

1 similar comment
@alistair23
Copy link
Contributor Author

Ping!

@alistair23
Copy link
Contributor Author

This must be ready to merge

hudson-ayers
hudson-ayers previously approved these changes May 4, 2021
Copy link
Contributor

@hudson-ayers hudson-ayers left a comment

Choose a reason for hiding this comment

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

LGTM with Brad's doc updates

@hudson-ayers
Copy link
Contributor

cc @phil-levis you need to dismiss your "request changes" for this to be mergeable

@alistair23
Copy link
Contributor Author

Updated and ready to go

@ppannuto ppannuto added the last-call Final review period for a pull request. label May 5, 2021
@alistair23
Copy link
Contributor Author

Ready to go!

@hudson-ayers hudson-ayers dismissed phil-levis’s stale review May 11, 2021 14:32

requested changes were made

@hudson-ayers
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented May 11, 2021

@bors bors bot merged commit 7fef0d0 into tock:master May 11, 2021
bors bot added a commit that referenced this pull request Jul 28, 2021
2177: TBF Header Persisent Access Control r=hudson-ayers a=alistair23

### Pull Request Overview

This PR builds on top of: #2172 to add a list of write and read permissions for persistent storage.

Apps can have a single write_id to allow them to write data with that id and multiple read IDs to read back the data. This allows the flexibility to read from multiple apps if required.

### Testing Strategy

### TODO or Help Wanted

### Documentation Updated

- [X] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [X] Ran `make prepush`.


Co-authored-by: Alistair Francis <[email protected]>
@alistair23 alistair23 deleted the alistair/tbf-header-perms branch September 28, 2021 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation last-call Final review period for a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants