From 77b5e7a2bba64d7024d71c976c11a3e7ac645a24 Mon Sep 17 00:00:00 2001 From: Blake Smith Date: Sun, 20 Mar 2022 15:20:02 -0500 Subject: [PATCH] During sleep, clear the rest of the screen, to avoid any secrets being persistently visible on the display. --- .../graphics-server/src/backend/betrusted.rs | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/services/graphics-server/src/backend/betrusted.rs b/services/graphics-server/src/backend/betrusted.rs index ebe09ed69..09c44f9a1 100644 --- a/services/graphics-server/src/backend/betrusted.rs +++ b/services/graphics-server/src/backend/betrusted.rs @@ -1,8 +1,8 @@ use crate::api::Point; +use crate::api::{LINES, WIDTH}; use susres::{ManagedMem, RegManager, RegOrField, SuspendResume}; use utralib::generated::*; use xous::MemoryRange; -use crate::api::{LINES, WIDTH}; pub const FB_WIDTH_WORDS: usize = 11; pub const FB_WIDTH_PIXELS: usize = WIDTH; @@ -10,7 +10,6 @@ pub const FB_LINES: usize = LINES; pub const FB_SIZE: usize = FB_WIDTH_WORDS * FB_LINES; // 44 bytes by 536 lines const CONFIG_CLOCK_FREQUENCY: u32 = 100_000_000; - pub struct XousDisplay { fb: MemoryRange, hwfb: MemoryRange, @@ -91,19 +90,36 @@ impl XousDisplay { if draw_note { let note = crate::sleep_note::LOGO_MAP; let note_lines = note.len() / FB_WIDTH_WORDS; - let start_line = (FB_LINES - note_lines) / 2; + let note_start_line = (FB_LINES - note_lines) / 2; + let note_end_line = note_start_line + note_lines; let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE]; - for words in 0..note.len() { - unsafe { - (*hwfb)[words + start_line * FB_WIDTH_WORDS] = note[words]; + + for lines in 0..FB_LINES { + for words in 0..FB_WIDTH_WORDS { + if lines >= note_start_line && lines < note_end_line { + // We're on a line that has the 'Sleeping...' note. + // Draw it into the frame buffer. + let note_index = ((lines - note_start_line) * FB_WIDTH_WORDS) + words; + unsafe { + (*hwfb)[words + lines * FB_WIDTH_WORDS] = note[note_index]; + } + } else { + // We're not on a line that has the note. Clear the pixels, + // since we don't want any secrets to linger in the framebuffer + // and stay visible on the persistent display while the device is + // sleeping. + unsafe { + (*hwfb)[words + lines * FB_WIDTH_WORDS] = 0xFFFF_FFFF; + } + } } - } - for lines in start_line..start_line + note_lines { + // set the dirty bits unsafe { (*hwfb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] |= 0x1_0000; } } + self.update_dirty(); while self.busy() { // busy wait, blocking suspend until this has happened