in my masters thesis, I am working on a research operating system in Rust. Currently, I'm trying to hide most kernel memory from userspace to prevent attacks like Meltdown. Therefore, I've created a section .visible_from_usermode that contains relevant kernel code that's required in user space like switching the address space on interrupts etc. Therefore, my linker script contains:
Code: Select all
ENTRY(start)
MEMORY {
high : ORIGIN = 25M, LENGTH = 0x7000000
}
SECTIONS {
[...]
. = ALIGN (4K);
.data : { *(.data*) } AT> high
___KERNEL_DATA_END__ = .;
. = ALIGN (4K);
___VISIBLE_FROM_USERMODE_START__ = .;
.visible_from_usermode 0x8000000000 : { *(.visible_from_usermode*) } AT> high
___VISIBLE_FROM_USERMODE_END__ = ___VISIBLE_FROM_USERMODE_START__ + SIZEOF (.visible_from_usermode);
}Code: Select all
#[unsafe(link_section = ".visible_from_usermode")]
fn handle_interrupt(frame: InterruptStackFrame, index: u8, _error: Option<u64>) { ... }Code: Select all
$ readelf -Ws loader/kernel.elf | grep ___VISIBLE_FROM_USERMODE_START__
9570: 0000000001fef000 0 NOTYPE GLOBAL DEFAULT 43492 ___VISIBLE_FROM_USERMODE_START__Code: Select all
[0.000][DBG][boot.rs] ___VISIBLE_FROM_USERMODE_START__: 0x1fef000
[0.000][DBG][boot.rs] ___VISIBLE_FROM_USERMODE_END__: 0x1ff0cf6Code: Select all
(gdb) x/100bx 0x1fef000
0x1fef000: 0x08 0x48 0x8d 0x7c 0x24 0x18 0x48 0x8dCode: Select all
(gdb) x/100bx 0x8000000000
0x8000000000 <_ZN6kernel6memory3vmm19VirtualAddressSpace18load_address_space17had51e0a1f58e9345E>: 0x08 0x48 0x8d 0x7c 0x24 0x18 0x48 0x8dCode: Select all
$objdump -Dj .visible_from_usermode loader/kernel.elf
Disassembly of section .visible_from_usermode:
0000008000000000 <_ZN6kernel6memory3vmm19VirtualAddressSpace18load_address_space17had51e0a1f58e9345E>:
8000000000: 48 83 ec 18 sub $0x18,%rsp
8000000004: 48 8d 05 f9 ff ff ff lea -0x7(%rip),%rax # 8000000004 <_ZN6kernel6memory3vmm19VirtualAddressSpace18load_address_space17had51e0a1f58e9345E+0x4>Code: Select all
(gdb) x/100bx 0x1fef000-1208
0x1feeb48: 0x48 0x83 0xec 0x18 0x48 0x8d 0x05 0xf9Thanks a lot in advance!