Skip to content

Commit c8d74fb

Browse files
committed
implement soft-disabling ME using straps
Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 48af639 commit c8d74fb

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/clean.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1-
use intel_fw::me::ME;
1+
use intel_fw::{
2+
ifd::{IFD, IfdError},
3+
me::ME,
4+
};
25
use log::warn;
36

47
pub struct Options {
58
pub relocate: bool,
9+
pub disable_me: bool,
10+
pub disable_me_only: bool,
611
}
712

8-
pub fn clean(me: &ME, data: &mut [u8], options: Options) -> Result<Vec<u8>, String> {
13+
pub fn clean(
14+
ifd: &Result<IFD, IfdError>,
15+
me: &ME,
16+
data: &mut [u8],
17+
options: Options,
18+
) -> Result<Vec<u8>, String> {
19+
if (options.disable_me || options.disable_me_only)
20+
&& let Ok(ifd) = ifd
21+
{
22+
let mut new_ifd = ifd.clone();
23+
if let Err(e) = new_ifd.disable_me(&me.generation, &me.version) {
24+
let msg = format!("Could not disable ME: {e}");
25+
if options.disable_me_only {
26+
return Err(msg);
27+
}
28+
warn!("{msg}");
29+
} else {
30+
let new_ifd = new_ifd.to_vec();
31+
let size = new_ifd.len();
32+
data[..size].copy_from_slice(&new_ifd);
33+
}
34+
if options.disable_me_only {
35+
return Ok(data.to_vec());
36+
}
37+
}
938
let mut new_me = me.clone();
1039
new_me.fpt_area.clean();
1140
if options.relocate {

src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ fn main() {
148148
debug!(" Retain FTPR modules: {keep_modules}");
149149
debug!(" Relocate FTPR partition: {relocate}");
150150
debug!(" Truncate empty parts: {truncate}");
151-
let disable_me = soft_disable || soft_disable_only;
151+
let disable_me = match (soft_disable, soft_disable_only) {
152+
(true, false) => "yes",
153+
(false, false) => "no",
154+
(_, true) => "only this and nothing more",
155+
};
152156
debug!(" Soft disable ME: {disable_me}");
153157
debug!("");
154158
if let Some(allowlist) = whitelist {
@@ -179,8 +183,12 @@ fn main() {
179183
let Ok(me) = me_res else {
180184
return;
181185
};
182-
let opts = clean::Options { relocate };
183-
match clean::clean(&me, &mut data, opts) {
186+
let opts = clean::Options {
187+
relocate,
188+
disable_me: soft_disable,
189+
disable_me_only: soft_disable_only,
190+
};
191+
match clean::clean(&fw.ifd, &me, &mut data, opts) {
184192
Ok(data) => {
185193
if let Some(out_file) = output {
186194
let mut file = fs::File::create(out_file).unwrap();

0 commit comments

Comments
 (0)