Skip to content

Commit

Permalink
Add label field to Channel struct
Browse files Browse the repository at this point in the history
Will be used for enforcing Information Flow between Nodes and Channels
as part of project-oak#630.

Ref project-oak#603
  • Loading branch information
tiziano88 committed Mar 24, 2020
1 parent 70da189 commit 6996420
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
6 changes: 4 additions & 2 deletions oak/server/rust/oak_runtime/src/node/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ impl WasmInterface {
&config_name,
&entrypoint,
// TODO(#630): Let caller provide this label via the Wasm ABI.
// TODO(#630): Check whether the label of the caller "flows to" the provided label.
&oak_abi::label::Label::public_trusted(),
channel_ref.clone(),
)
Expand All @@ -220,7 +219,10 @@ impl WasmInterface {
write_addr: AbiPointer,
read_addr: AbiPointer,
) -> Result<(), OakStatus> {
let (writer, reader) = self.runtime.new_channel();
let (writer, reader) = self
.runtime
// TODO(#630): Let caller provide this label via the Wasm ABI.
.new_channel(&oak_abi::label::Label::public_trusted());

self.validate_ptr(write_addr, 8)?;
self.validate_ptr(read_addr, 8)?;
Expand Down
14 changes: 11 additions & 3 deletions oak/server/rust/oak_runtime/src/runtime/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ pub struct Channel {
/// instead of removing itself from all the `Channel`s it subscribed to.
/// Threads can be woken up spuriously without issue.
pub waiting_threads: WaitingThreads,

/// The Label associated with this channel.
///
/// This is set at channel creation time and does not change after that.
///
/// See https://github.com/project-oak/oak/blob/master/docs/concepts.md#labels
label: oak_abi::label::Label,
}

/// A reference to a [`Channel`]. Each [`Handle`] has an implicit direction such that it is only
Expand Down Expand Up @@ -88,12 +95,13 @@ pub struct ChannelMapping {
impl Channel {
/// Create a new channel with the assumption there is currently one active reader and one active
/// writer references.
pub fn new() -> Channel {
pub fn new(label: &oak_abi::label::Label) -> Channel {
Channel {
messages: RwLock::new(Messages::new()),
writers: AtomicU64::new(1),
readers: AtomicU64::new(1),
waiting_threads: Mutex::new(HashMap::new()),
label: label.clone(),
}
}

Expand Down Expand Up @@ -150,10 +158,10 @@ impl ChannelMapping {
}

/// Create a new [`Channel`] and return a `(writer handle, reader handle)` pair.
pub fn new_channel(&self) -> (Handle, Handle) {
pub fn new_channel(&self, label: &oak_abi::label::Label) -> (Handle, Handle) {
let channel_id = self.next_channel_id.fetch_add(1, SeqCst);
let mut channels = self.channels.write().unwrap();
channels.insert(channel_id, Channel::new());
channels.insert(channel_id, Channel::new(label));
(self.new_writer(channel_id), self.new_reader(channel_id))
}

Expand Down
15 changes: 12 additions & 3 deletions oak/server/rust/oak_runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pub use channel::{Handle, HandleDirection};
struct Node {
reference: NodeRef,
join_handle: JoinHandle<()>,

/// The Label associated with this node.
///
/// This is set at node creation time and does not change after that.
///
/// See https://github.com/project-oak/oak/blob/master/docs/concepts.md#labels
label: oak_abi::label::Label,
}

Expand Down Expand Up @@ -84,7 +90,10 @@ impl Runtime {

let runtime = RuntimeRef(Arc::new(runtime));

let (chan_writer, chan_reader) = runtime.new_channel();
// When first starting, we assign the least privileged label to the channel connecting the
// outside world to the entry point node.
let (chan_writer, chan_reader) =
runtime.new_channel(&oak_abi::label::Label::public_trusted());

runtime.node_create(
&config.entry_module,
Expand Down Expand Up @@ -125,8 +134,8 @@ impl Runtime {
}

/// Creates a new channel.
pub fn new_channel(&self) -> (Handle, Handle) {
self.channels.new_channel()
pub fn new_channel(&self, label: &oak_abi::label::Label) -> (Handle, Handle) {
self.channels.new_channel(label)
}

/// Reads the statuses from a slice of `Option<&ChannelReader>`s.
Expand Down
12 changes: 10 additions & 2 deletions sdk/rust/oak_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,21 @@ where
.expect("failed to serialize GrpcRequest message");

// Create a new channel to hold the request message.
let (req_write_half, req_read_half) = runtime.new_channel();
//
// In most cases we do not care about labels, so we use the least privileged label for this
// channel.
let (req_write_half, req_read_half) =
runtime.new_channel(&oak_abi::label::Label::public_trusted());
runtime
.channel_write(req_write_half, req_msg)
.expect("could not write message");

// Create a new channel for responses to arrive on and also attach that to the message.
let (rsp_write_half, rsp_read_half) = runtime.new_channel();
//
// In most cases we do not care about labels, so we use the least privileged label for this
// channel.
let (rsp_write_half, rsp_read_half) =
runtime.new_channel(&oak_abi::label::Label::public_trusted());

// Create a notification message and attach the method-invocation specific channels to it.
let notify_msg = oak_runtime::Message {
Expand Down

0 comments on commit 6996420

Please sign in to comment.