Closed
Description
As pointed out in this thread on URLO, it is possible to read arbitrary memory without unsafe
using the link_section
attribute on architectures with separate address spaces for code and data.
To cite OP's code:
// Store PROG_BLOB in program space, ".text" would also work
#[link_section = ".progmem"]
static PROG_BLOB: [u8; 128] = [42; 128];
fn main() -> ! {
let mut serial = /* initialize a serial output */;
let mut idx = 0;
loop {
// This access is illegal, because Rust will emit a normal load
// instruction, whereas the data is in the program space,
// requiring a special load instruction.
let b = PROG_BLOB[idx];
// Dumping arbitrary RAM data!
ufmt::uwrite!(&mut serial, "{:?} ", b).void_unwrap();
idx += 1;
if idx == BIG_BLOB.len() {
break
}
}
loop {
// Just loop forever
}
}
I expected to see this happen: the code should not compile, as it reads OOB memory.
Instead, this happened: The code compiles and outputs incorrect values, indicating UB.
Metadata
Metadata
Assignees
Labels
Area: linking into static, shared libraries and binariesCategory: This is a bug.Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessLow priorityRelevant to the language team