From 323c11f5549b596b7a19e99a4e569fefe913da99 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 7 Jan 2021 16:58:13 +0800 Subject: [PATCH] commit a version that exhausts the kernel allocation --- services/com/src/main.rs | 10 ++++++++++ services/shell/src/main.rs | 33 +++++++++++++-------------------- services/xous-names/README.md | 2 +- services/xous-names/src/lib.rs | 2 +- services/xous-names/src/main.rs | 18 ++++++++++++++---- 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 2ea9a0a46..46bb4076c 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -243,6 +243,16 @@ fn xmain() -> ! { let shell_id = xous::SID::from_bytes(b"shell ").unwrap(); let shell_conn = xous::connect(shell_id).unwrap(); + /* + info!("Test NS registration"); + let registration = Registration::new(); + let mut sendable_registration = Sendable::new(registration) + .expect("can't create sendable registration structure"); + write!(sendable_registration.name, "A test Name!").unwrap(); + info!("namserver registration input: {:?}", sendable_registration.success); + sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!"); + info!("nameserver registration result: {:?}, {:?}", sendable_registration.success, sendable_registration.sid); +*/ let agent_conn: usize; if cfg!(feature = "fccagent") { let agent_id = xous::SID::from_bytes(b"fcc-agent-server").unwrap(); diff --git a/services/shell/src/main.rs b/services/shell/src/main.rs index 678aa90bd..2aabd54c1 100644 --- a/services/shell/src/main.rs +++ b/services/shell/src/main.rs @@ -345,32 +345,25 @@ fn shell_main() -> ! { ) .expect("unable to draw to screen"); + /* test code to exhaust memory allocation */ + let mut iter = 0; + info!("Test memory allocation"); + loop { + let lookup = Lookup::new(); + let mut sendable_lookup = Sendable::new(lookup) + .expect("can't create sendable lookup structure"); + write!(sendable_lookup.name, "A test Name!").unwrap(); + sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!"); + info!("memtest: iter {}", iter); + iter += 1; + } + // Periodic tasks if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) { if elapsed_time - last_time > 500 { last_time = elapsed_time; info!("Requesting batt stats from COM"); get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM"); - - info!("Test NS registration"); - let registration = Registration::new(); - let mut sendable_registration = Sendable::new(registration) - .expect("can't create sendable registration structure"); - write!(sendable_registration.name, "A test Name!").unwrap(); - info!("namserver registration input: {:?}", sendable_registration.success); - sendable_registration.lend_mut(ns_conn, sendable_registration.mid()).expect("nameserver registration failure!"); - info!("nameserver registration result: {:?}, {:?}", sendable_registration.success, sendable_registration.sid); - - info!("Test NS lookup"); - let lookup = Lookup::new(); - info!("making sendable"); - let mut sendable_lookup = Sendable::new(lookup) - .expect("can't create sendable lookup structure"); - info!("making a test name"); - write!(sendable_lookup.name, "A test Name!").unwrap(); - info!("nameserver lookup input: {:?}", sendable_lookup.success); - sendable_lookup.lend_mut(ns_conn, sendable_lookup.mid()).expect("nameserver lookup failure!"); - info!("nameserver lookup result: {:?}, {:?}", sendable_lookup.success, sendable_lookup.cid); } } else { error!("error requesting ticktimer!") diff --git a/services/xous-names/README.md b/services/xous-names/README.md index 68cd45ce7..f59f15235 100644 --- a/services/xous-names/README.md +++ b/services/xous-names/README.md @@ -81,7 +81,7 @@ asking for access to the `ticktimer` or other public services. B. flat denial: `xous-name-server` simply returns a message saying the request was denied by setting `success` to `false`. This is also the case when the request is malformed or incorrect. No information shall be leaked about the -nature of the denial. Denials are also delayed to the nearest 0.5 second interval since boot +nature of the denial. Denials are also delayed to the nearest 0.1 second interval since boot to eliminate side channels and to rate limit fuzzing requests. Some services (such as the key server) are restricted to only a set of trusted process loaded at boot, and therefore it should not be diff --git a/services/xous-names/src/lib.rs b/services/xous-names/src/lib.rs index f488b855e..167756a70 100644 --- a/services/xous-names/src/lib.rs +++ b/services/xous-names/src/lib.rs @@ -11,7 +11,7 @@ Calls are made using the xous::ipc::Sendable IPC wrapper, for example: let mut sendable_registration = Sendable::new(registration) .expect("can't create sendable registration structure"); - write!(sendable_registration.name, "I'm a server, call me Fred!"); + write!(sendable_registration.name, "I'm a server, please call me Fred!"); sendable_registration.lend_mut(ns_conn, sendable_registration.mid()); diff --git a/services/xous-names/src/main.rs b/services/xous-names/src/main.rs index f4f032526..6d21b0c3f 100644 --- a/services/xous-names/src/main.rs +++ b/services/xous-names/src/main.rs @@ -12,6 +12,8 @@ use heapless::consts::*; use log::{error, info}; +const FAIL_TIMEOUT_MS: u64 = 100; + #[xous::xous_main] fn xmain() -> ! { log_server::init_wait().unwrap(); @@ -43,8 +45,8 @@ fn xmain() -> ! { registration.success = true; } else { registration.success = false; - // compute the next interval that is 0.5s away - let target_time: u64 = ((ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() / 500) + 1) * 500; + // compute the next interval, rounded to a multiple of FAIL_TIMEOUT_MS to reduce timing side channels + let target_time: u64 = ((ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() / FAIL_TIMEOUT_MS) + 1) * FAIL_TIMEOUT_MS; info!("NS: request failed, waiting for deterministic timeout"); while ticktimer_server::elapsed_ms(ticktimer_conn).unwrap() < target_time { xous::yield_slice(); @@ -56,9 +58,17 @@ fn xmain() -> ! { let lookup: &mut Lookup = unsafe { &mut *(m.buf.as_mut_ptr() as *mut Lookup) }; + /* info!("NS: Lookup request for {}", lookup.name); - // lookup.cid = 1337; - lookup.success = true; + if let Ok(server_sid) = name_table.get(lookup) { + lookup.success = true; + let sender_pid = &envelope.sender.pid()?; + let connection_id = xous::connect_for_process(sender_pid, server_sid).expect("NS: can't broker connection"); + lookup.cid = connection_id; + } else { + lookup.success = false; + // no authenticate remedy currently supported, but we'd put that code somewhere around here eventually. + }*/ } else { error!("NS: unknown message ID received"); }