allow management token returns on servers with more than one connection

Mangement tokens were added to xous-names for the special case of
servers that had exactly 1 connection, so they could explicitly
control when they are disconnected (preventing e.g. griefing by
rogue processes).

This was a good idea except it also conflicts with the "eager TOFU"
model of Xous security when you have servers that act as plugins to
each other. Eager TOFU means Xous has a "trust on first use" model
for capabilities, and eager implies that anyone who will use
anything will claim it early on. This gives the important property
that one can ask, "has everyone eaten their TOFU?" before doing
anything really sensitive. If all the TOFU slots are used, then
you can conclude that no new rogue servers can inject themselves
into sensitive APIs and you can move forward.

In the case of a plugin API with multiple plug options, when
you unplug something, the previously eagerly occupied slot
now becomes unoccopied -- and this becomes a flag against
the TOFU check, disallowing sensitive operations to proceed.

This is *particularly* a problem with the predictive history
plugins for the IME. The architecture was created to allow
for multiple histories to be used. Up until now, only the shellchat
plugin was ever used, so, the eager TOFU check always passed.

However, in creating more applications, this flaw was uncovered
once we introduced a second plugin.

This means predictors can not delegate their security to Xous-names.
They must individually implement API tokens to control access
to the prediction history (to prevent rogue apps from e.g. connecting
to the predictor and then reading out the prediction history to
figure out what the most recent words were typed).

A subsequent commit will add the API tokens, but this commit simply
has xous-names return a mangament token even if servers with
more than 1 connection are created. The main downside of doing
this is the management token lose meaning in the context of
multiple servers; but, so long as the tokens aren't used for
anything in those situations, it's fine (cue burning building
meme).

More importantly, it allows the existing code to manage the xous-names
count to function even on a server that sets no explicit limit
on connection count, which is now going to be the case for the
prediction engines going forward.
This commit is contained in:
bunnie 2022-06-19 00:51:02 +08:00
parent 9bc9811472
commit 14e22d07b9

View file

@ -111,7 +111,7 @@ struct Connection {
pub max_conns: Option<u32>, // if None, unlimited connections allowed
pub _allow_authenticate: bool,
pub _auth_conns: u32, // number of authenticated connections
pub token: Option<[u32; 4]>, // a random number that must be presented to allow for disconnection for single-connection servers
pub token: Option<[u32; 4]>, // a random number that must be presented to allow for disconnection
}
#[derive(Debug)]
struct CheckedHashMap {
@ -129,16 +129,17 @@ impl CheckedHashMap {
sid: xous::SID,
max_conns: Option<u32>,
) -> Result<(), xous::Error> {
let token = if max_conns == Some(1) {
// for the special case of 1-connection servers, provision a one-time use token for disconnects
let token =
// for use with 1-connection servers, provision a one-time use token for disconnects
// it will be returned for multi-connection servers as well, but it doesn't have a clear
// semantic meaning with multiple connections. However, this exists in particular to
// allow clean connect/disconnect in the special case of 1-connection servers that
// can be swapped out (such as plugins for IME predictions)
Some(
xous::create_server_id()
.expect("couldn't create token")
.to_array(),
)
} else {
None
};
);
self.map.insert(
name,
Connection {
@ -189,7 +190,7 @@ impl CheckedHashMap {
Some(max) => {
if entry.current_conns < max {
(*entry).current_conns += 1;
(Some(entry.sid), None)
(Some(entry.sid), entry.token)
} else {
(None, None)
}
@ -197,7 +198,15 @@ impl CheckedHashMap {
_ => {
// unlimited connections allowed
(*entry).current_conns += 1;
(Some(entry.sid), None)
// previously, this did not return an entry.token, but we now do
// because we had to loosen the restriction on the count of connections to
// the IME plugins -- because by essence, a disconnected IME plugin does
// not have its connection table full, and therefore, this would disallow
// root key operations. However, we stil want some control over who
// is allowed to initiate the disconnect, so, we've moved the access
// control to the server itself, thus allowing a permissive policy inside
// xous-names.
(Some(entry.sid), entry.token)
}
}
} else {
@ -245,7 +254,10 @@ impl CheckedHashMap {
pub fn disconnect_with_token(&mut self, name: &XousServerName, token: [u32; 4]) -> bool {
if let Some(entry) = self.map.get_mut(name) {
if let Some(old_token) = entry.token {
if (token == old_token) && (entry.current_conns == 1) {
if token == old_token {
if entry.current_conns != 1 {
log::warn!("disconnect with token used on system with more than one client; this will cause other disconnects to fail");
}
(*entry).current_conns = 0;
// generate the token -- we should never re-use these!
(*entry).token = Some(