Skip to content

Commit

Permalink
Added IO protection by setting IOPL to zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian-M-Moffett committed May 4, 2022
1 parent 294fc78 commit 1efc7eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ all:
mkdir -p kernel/lib/interrupts/asm kernel/lib/interrupts/sycall kernel/lib/interrupts/syscall/asm
mkdir -p kernel/lib/drivers/ps2/x86_64
mkdir -p kernel/lib/userspace
mkdir -p kernel/lib/arch/protection/
mkdir -p kernel/lib/arch/protection/asm
bash builduserspace.sh
mv *.o kernel/lib/userspace
cd gnu-efi/; make; make bootloader; cd ../; cd kernel; make; make buildimg
Expand Down
Binary file modified OVMFbin/OVMF_VARS-pure-efi.fd
Binary file not shown.
18 changes: 18 additions & 0 deletions kernel/src/arch/protection/asm/iopl.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;; 2022 Ian Moffett <ian@kesscoin.com>

global iopl_zero


;; This will make sure IO operations can only operate in
;; ring zero.
iopl_zero:
pushf ;; Push flags onto stack.
pop rax ;; Save it in RAX.
and rax, ~(1 << 12) ;; Clear bit 12.
and rax, ~(1 << 13) ;; Clear bit 13.

;; Now it should be zero and can only be accessed
;; in ring zero.
push rax ;; Push RAX back onto stack.
popf ;; Pop it into FLAGS.
retq
10 changes: 10 additions & 0 deletions kernel/src/arch/protection/iopl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef IOPL_H
#define IOPL_H

// 2022 Ian Moffett <ian@kesscoin.com>


void iopl_zero();


#endif
2 changes: 2 additions & 0 deletions kernel/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <arch/memory/vmm.h>
#include <arch/io/legacy-pic.h>
#include <arch/io/io.h>
#include <arch/protection/iopl.h>
#include <interrupts/IDT.h>
#include <interrupts/exceptions.h>
#include <interrupts/syscall/syscall.h>
Expand Down Expand Up @@ -161,6 +162,7 @@ static void init(meminfo_t meminfo, void* rsdp) {
// Stuff to init under init() before userspace.
static void footer_init() {
ps2_keyboard_init();
iopl_zero();
}


Expand Down

0 comments on commit 1efc7eb

Please sign in to comment.