diff options
author | Marvin Borner | 2021-03-14 18:42:54 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-14 18:42:54 +0100 |
commit | 665b00e7f44e5088b134d111ba1d5226c11f0ae8 (patch) | |
tree | 49f5a9b0ea82d8c6fd067f5acfbc08607109c0bd /kernel/features | |
parent | b7ae466ac77c68d0a1e1a124e6ea8c4cfc8d7100 (diff) |
Some security measurements
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/fs.c | 5 | ||||
-rw-r--r-- | kernel/features/mm.c | 20 |
2 files changed, 16 insertions, 9 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c index c8ad317..c692aac 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -5,6 +5,7 @@ #include <fs.h> #include <ide.h> #include <mem.h> +#include <mm.h> #include <print.h> #include <random.h> #include <str.h> @@ -240,11 +241,11 @@ s32 vfs_poll(const char **files) if (!files) return -1; - for (const char **p = files; *p && **p; p++) + for (const char **p = files; memory_user_valid((u32)*p) && *p && **p; p++) if (vfs_ready(*p)) return p - files; - for (const char **p = files; *p && **p; p++) + for (const char **p = files; memory_user_valid((u32)*p) && *p && **p; p++) vfs_wait(*p, (u32)vfs_poll); return PROC_MAX_WAIT_IDS + 1; diff --git a/kernel/features/mm.c b/kernel/features/mm.c index 9eca438..875d752 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -9,7 +9,7 @@ #include <print.h> static struct page_dir kernel_dir ALIGNED(PAGE_SIZE) = { 0 }; -static struct page_table kernel_tables[256] ALIGNED(PAGE_SIZE) = { 0 }; +static struct page_table kernel_tables[PAGE_KERNEL_COUNT] ALIGNED(PAGE_SIZE) = { 0 }; /** * Lowlevel paging @@ -233,8 +233,8 @@ struct memory_range virtual_alloc(struct page_dir *dir, struct memory_range pran u32 vaddr = 0; u32 size = 0; - for (u32 i = (user ? 256 : 1) * PAGE_COUNT; i < (user ? PAGE_COUNT : 256) * PAGE_COUNT; - i++) { + for (u32 i = (user ? PAGE_KERNEL_COUNT : 1) * PAGE_COUNT; + i < (user ? PAGE_COUNT : PAGE_KERNEL_COUNT) * PAGE_COUNT; i++) { u32 addr = i * PAGE_SIZE; if (!virtual_present(dir, addr)) { if (size == 0) @@ -284,7 +284,7 @@ struct page_dir *virtual_create_dir(void) memset(dir, 0, sizeof(*dir)); - for (u32 i = 0; i < 256; i++) { + for (u32 i = 0; i < PAGE_KERNEL_COUNT; i++) { union page_dir_entry *dir_entry = &dir->entries[i]; dir_entry->bits.present = 1; @@ -300,7 +300,7 @@ void virtual_destroy_dir(struct page_dir *dir) { assert(dir != &kernel_dir); - for (u32 i = 256; i < PAGE_COUNT; i++) { + for (u32 i = PAGE_KERNEL_COUNT; i < PAGE_COUNT; i++) { union page_dir_entry *dir_entry = &dir->entries[i]; if (dir_entry->bits.present) { struct page_table *table = @@ -358,7 +358,7 @@ err: void *memory_alloc_identity(struct page_dir *dir, u32 flags) { - for (u32 i = 1; i < 256 * PAGE_COUNT; i++) { + for (u32 i = 1; i < PAGE_KERNEL_COUNT * PAGE_COUNT; i++) { struct memory_range range = memory_range(i * PAGE_SIZE, PAGE_SIZE); if (!virtual_present(dir, range.base) && !physical_is_used(range)) { @@ -411,6 +411,12 @@ void memory_backup_dir(struct page_dir **backup) *backup = dir; } +// TODO: Check memory validity more often +u8 memory_user_valid(u32 addr) +{ + return addr / PAGE_SIZE / PAGE_COUNT >= PAGE_KERNEL_COUNT; +} + struct memory_range memory_range_from(u32 base, u32 size) { u32 align = PAGE_SIZE - base % PAGE_SIZE; @@ -466,7 +472,7 @@ void memory_install(struct mem_info *mem_info, struct vid_info *vid_info) } } - for (u32 i = 0; i < 256; i++) { + for (u32 i = 0; i < PAGE_KERNEL_COUNT; i++) { union page_dir_entry *dir_entry = &kernel_dir.entries[i]; dir_entry->bits.present = 1; dir_entry->bits.writable = 1; |