From 54fb220aa8587313d1e104673162c1f2e6989469 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 16 Sep 2013 13:13:41 +0800 Subject: [PATCH] Kernel - Fixed buggy module loader logic, allowed ELF relocations to RO pages --- KernelLand/Kernel/bin/elf.c | 13 ++++++++++++- KernelLand/Kernel/modules.c | 38 +++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/KernelLand/Kernel/bin/elf.c b/KernelLand/Kernel/bin/elf.c index f4c73e29..d404d6db 100644 --- a/KernelLand/Kernel/bin/elf.c +++ b/KernelLand/Kernel/bin/elf.c @@ -29,7 +29,18 @@ static int GetSymbol(const char *Name, void **Value, size_t *Size) { } #define AddLoaded(a,b) do{}while(0) #define LoadLibrary(a,b,c) (Log_Debug("ELF", "Module requested lib '%s'",a),0) -#define _SysSetMemFlags(ad,f,m) do{}while(0) +static int _SysSetMemFlags(tVAddr addr, int flag, int mask) { + if( mask & 1 ) { + if( flag ) { + // Re-set RO, clear COW + MM_SetFlags(addr, MM_PFLAG_RO, MM_PFLAG_RO|MM_PFLAG_COW); + } + else { + MM_SetFlags(addr, MM_PFLAG_RO|MM_PFLAG_COW, MM_PFLAG_RO|MM_PFLAG_COW); + } + } + return 0; +} #include "../../../Usermode/Libraries/ld-acess.so_src/elf.c" // ---- / ---- diff --git a/KernelLand/Kernel/modules.c b/KernelLand/Kernel/modules.c index c5e7f1bc..b5e917c3 100644 --- a/KernelLand/Kernel/modules.c +++ b/KernelLand/Kernel/modules.c @@ -341,7 +341,7 @@ int Module_LoadMem(void *Buffer, Uint Length, const char *ArgString) VFS_GetMemPath(path, Buffer, Length); - return Module_LoadFile( path, ArgString ); + return Module_LoadFile( path, ArgString ) == EOK; } /** @@ -360,7 +360,7 @@ int Module_LoadFile(const char *Path, const char *ArgString) // Error check if(base == NULL) { Log_Warning("Module", "Module_LoadFile - Unable to load '%s'", Path); - return 0; + return ENOENT; } // TODO: I need a way of relocating the dependencies before everything else, so @@ -368,7 +368,7 @@ int Module_LoadFile(const char *Path, const char *ArgString) if( !Binary_Relocate(base) ) { Log_Warning("Module", "Relocation of module %s failed", Path); Binary_Unload(base); - return 0; + return EINVAL; } // Check for Acess Driver @@ -384,24 +384,34 @@ int Module_LoadFile(const char *Path, const char *ArgString) if( !loader ) { Binary_Unload(base); Log_Warning("Module", "Module '%s' does not have a Module Info struct", Path); - return 0; + return EINVAL; } } - if( !Module_int_ResolveDeps(info) ) { - Log_Warning("Module", "Dependencies not met for '%s'", Path); - Binary_Unload(base); - return 0; + if( loader ) + { + if( loader->Loader(base) ) + { + Binary_Unload(base); + return EINVAL; + } } - - // Initialise (and register) - if( loader ? loader->Loader(base) : Module_int_Initialise( info, ArgString ) ) + else { - Binary_Unload(base); - return 0; + if( !Module_int_ResolveDeps(info) ) { + Log_Warning("Module", "Dependencies not met for '%s'", Path); + Binary_Unload(base); + return EINVAL; + } + + if( Module_int_Initialise(info, ArgString) ) + { + Binary_Unload(base); + return EINVAL; + } } - return 1; + return 0; } /** -- 2.20.1