Add stack protector
This commit is contained in:
parent
470c208284
commit
1ee034683a
4 changed files with 27 additions and 17 deletions
19
kernel/src/cpu/boot.s
Normal file
19
kernel/src/cpu/boot.s
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
rdrand:
|
||||||
|
rdrand %rax
|
||||||
|
jnc rdrand
|
||||||
|
ret
|
||||||
|
.global _start
|
||||||
|
_start:
|
||||||
|
mov %rcx, %rdi
|
||||||
|
mov $stack, %rsp
|
||||||
|
call rdrand
|
||||||
|
mov %rax, __stack_chk_guard
|
||||||
|
call main
|
||||||
|
.section .bss
|
||||||
|
.align 8
|
||||||
|
.global __stack_chk_guard
|
||||||
|
__stack_chk_guard:
|
||||||
|
.skip 8
|
||||||
|
.align 16
|
||||||
|
.skip 0x100000
|
||||||
|
stack:
|
|
@ -25,20 +25,7 @@ mod sys;
|
||||||
static ALLOC: LockedHeap = LockedHeap::empty();
|
static ALLOC: LockedHeap = LockedHeap::empty();
|
||||||
pub static RSDP_ADDRESS: Once<u64> = Once::new();
|
pub static RSDP_ADDRESS: Once<u64> = Once::new();
|
||||||
|
|
||||||
global_asm!(
|
global_asm!(include_str!("cpu/boot.s"), options(att_syntax));
|
||||||
"
|
|
||||||
.global _start
|
|
||||||
_start:
|
|
||||||
mov %rcx, %rdi
|
|
||||||
mov $stack, %rsp
|
|
||||||
call main
|
|
||||||
.section .bss
|
|
||||||
.align 16
|
|
||||||
.skip 0x100000
|
|
||||||
stack:
|
|
||||||
",
|
|
||||||
options(att_syntax)
|
|
||||||
);
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
extern "C" fn main(temp_loader_struct: *const LoaderStruct) -> ! {
|
extern "C" fn main(temp_loader_struct: *const LoaderStruct) -> ! {
|
||||||
|
@ -55,11 +42,11 @@ extern "C" fn main(temp_loader_struct: *const LoaderStruct) -> ! {
|
||||||
if loader_struct.magic != LOADER_STRUCT_MAGIC {
|
if loader_struct.magic != LOADER_STRUCT_MAGIC {
|
||||||
panic!("Invalid bootloader struct");
|
panic!("Invalid bootloader struct");
|
||||||
}
|
}
|
||||||
RSDP_ADDRESS.call_once(|| loader_struct.rsdp_address);
|
|
||||||
setup_gdt();
|
setup_gdt();
|
||||||
setup_idt();
|
setup_idt();
|
||||||
setup_paging(&loader_struct, loader_struct.phys_kernel_start, loader_struct.phys_heap_start);
|
setup_paging(&loader_struct, loader_struct.phys_kernel_start, loader_struct.phys_heap_start);
|
||||||
disable_pic();
|
disable_pic();
|
||||||
|
RSDP_ADDRESS.call_once(|| loader_struct.rsdp_address);
|
||||||
loop {
|
loop {
|
||||||
hlt();
|
hlt();
|
||||||
}
|
}
|
||||||
|
@ -72,3 +59,7 @@ fn panic(info: &PanicInfo) -> ! {
|
||||||
hlt();
|
hlt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[no_mangle]
|
||||||
|
extern "C" fn __stack_chk_fail() {
|
||||||
|
panic!("Stack smashing detected");
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ COMPONENTS:=dispatcher events executer hardware namespace parser resources table
|
||||||
CFILES:=$(foreach comp, $(COMPONENTS), $(wildcard ../acpica/source/components/$(comp)/*.c))
|
CFILES:=$(foreach comp, $(COMPONENTS), $(wildcard ../acpica/source/components/$(comp)/*.c))
|
||||||
OFILES:=$(patsubst %.c, %.o, $(CFILES))
|
OFILES:=$(patsubst %.c, %.o, $(CFILES))
|
||||||
CC:=clang
|
CC:=clang
|
||||||
CFLAGS:=--target=x86_64-elf -ffreestanding -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -O2 -I. -I../acpica/source/include -DACPI_LIBRARY -D__linux__
|
CFLAGS:=--target=x86_64-elf -ffreestanding -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fstack-protector-strong -O2 -I. -I../acpica/source/include -DACPI_LIBRARY -D__linux__
|
||||||
|
|
||||||
libacpica.a: $(OFILES)
|
libacpica.a: $(OFILES)
|
||||||
llvm-ar rcD $@ $^
|
llvm-ar rcD $@ $^
|
||||||
|
|
2
qemu.sh
2
qemu.sh
|
@ -2,4 +2,4 @@
|
||||||
# shellcheck disable=SC2068
|
# shellcheck disable=SC2068
|
||||||
set -e
|
set -e
|
||||||
./build.sh
|
./build.sh
|
||||||
qemu-system-x86_64 -M q35 -m 256M -L /usr/share/OVMF -bios OVMF_CODE.fd -drive file=img/os.img,format=raw $@
|
qemu-system-x86_64 -M q35 -cpu qemu64,+rdrand -m 256M -L /usr/share/OVMF -bios OVMF_CODE.fd -drive file=img/os.img,format=raw $@
|
||||||
|
|
Loading…
Add table
Reference in a new issue