firmware: fix another TOCTTOU race in sync/async RPC code.

This commit is contained in:
whitequark 2018-11-12 15:39:55 +00:00
parent 583bba8777
commit dd829afebd
3 changed files with 22 additions and 2 deletions

View File

@ -514,6 +514,19 @@ pub unsafe fn main() {
attribute_writeback(typeinfo as *const ());
}
// Make sure all async RPCs are processed before exiting.
// Otherwise, if the comms and kernel CPU run in the following sequence:
//
// comms kernel
// ----------------------- -----------------------
// check for async RPC
// post async RPC
// post RunFinished
// check for mailbox
//
// the async RPC would be missed.
send(&RpcFlush);
send(&RunFinished);
loop {}

View File

@ -64,6 +64,7 @@ pub enum Message<'a> {
},
RpcRecvRequest(*mut ()),
RpcRecvReply(Result<usize, Exception<'a>>),
RpcFlush,
CacheGetRequest { key: &'a str },
CacheGetReply { value: &'static [i32] },

View File

@ -410,7 +410,13 @@ fn process_kern_message(io: &Io, aux_mutex: &Mutex,
kern_acknowledge()
}
}
}
},
&kern::RpcFlush => {
// See ksupport/lib.rs for the reason this request exists.
// We do not need to do anything here because of how the main loop is
// structured.
kern_acknowledge()
},
&kern::CacheGetRequest { key } => {
let value = session.congress.cache.get(key);