diff --git a/arch/x86_64/include/x86_64/defs.h b/arch/x86_64/include/x86_64/defs.h index 54501bd..9077a26 100644 --- a/arch/x86_64/include/x86_64/defs.h +++ b/arch/x86_64/include/x86_64/defs.h @@ -117,6 +117,7 @@ #define CPUID_7D_AMX_INT8 (1 << 25) #define RFLAGS_CF (1u << 0) +#define RFLAGS_BRKI (1u << 1) #define RFLAGS_PF (1u << 2) #define RFLAGS_AF (1u << 4) #define RFLAGS_ZF (1u << 6) diff --git a/arch/x86_64/percpu.c b/arch/x86_64/percpu.c index c46127b..8994957 100644 --- a/arch/x86_64/percpu.c +++ b/arch/x86_64/percpu.c @@ -66,10 +66,11 @@ void x86_64_cpu_setup(struct percpu* cpu) { asm_wrmsr(MSR_EFER, asm_rdmsr(MSR_EFER) | MSR_EFER_SCE); union ia32_star star = {0}; star.kernel_cs_ss = offsetof(struct gdt, kernel_code64); - star.user_cs_ss = offsetof(struct gdt, user_code32); + star.user_cs_ss = offsetof(struct gdt, user_code32) | CPL_USER; asm_wrmsr(MSR_STAR, star.value); asm_wrmsr(MSR_LSTAR, (uint64_t)arch_syscall_stub); - asm_wrmsr(MSR_SFMASK, RFLAGS_AC | RFLAGS_DF | RFLAGS_IF); + // Mask all RFLAGS except for BRKI which is reserved. + asm_wrmsr(MSR_SFMASK, ~RFLAGS_BRKI); // TODO: FRED diff --git a/arch/x86_64/syscall.c b/arch/x86_64/syscall.c index 9b73b1c..c48dcb1 100644 --- a/arch/x86_64/syscall.c +++ b/arch/x86_64/syscall.c @@ -58,8 +58,10 @@ void arch_syscall_stub() { " pop rbx\n" " pop rax\n" " add rsp, 0x10\n" // Skip .error and .isr fields - "2:\n" - " mov rsp, gs:%c[user_stack]\n" + " pop rcx\n" // rip + " add rsp, 0x08\n" // Skip cs + " pop r11\n" // rflags + " pop rsp\n" // rsp " swapgs\n" " sysretq\n" : diff --git a/meson.build b/meson.build index 45d0bfe..2521e4b 100644 --- a/meson.build +++ b/meson.build @@ -97,8 +97,6 @@ subdir('syscalls') subdir('dev') subdir('fs') -subdir('tests') - configure_file( configuration: cfg, output: 'config.h', diff --git a/syscalls/syslog.c b/syscalls/syslog.c index 86cc658..d10e015 100644 --- a/syscalls/syslog.c +++ b/syscalls/syslog.c @@ -19,10 +19,15 @@ enum syslog_kind : uintptr_t { struct syscall_ret sys_syslog(enum syslog_kind kind, __user char* message, size_t len) { struct syscall_ret ret = {}; - const size_t buf_len = MIN(len + 1, 0x1000); + const size_t buf_len = MIN(len + 1, 256); char* buf = mem_alloc(buf_len, ALLOC_NOZERO); - usercopy_read(buf, message, buf_len - 1); - buf[buf_len] = 0; + if (!usercopy_read(buf, message, buf_len - 1)) { + mem_free(buf); + + ret.error = EFAULT; + return ret; + } + buf[buf_len - 1] = 0; const char* log_level; switch (kind) {