From 40d8679a5bdf09cf81e3865b36be0faec68d6a93 Mon Sep 17 00:00:00 2001 From: deadwood Date: Sat, 4 Oct 2014 19:16:49 +0000 Subject: [PATCH] dos.library: block m68k executables from running on non-m68k platforms git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@49698 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/dos/dos.conf | 2 +- rom/dos/internalloadseg_aos.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/rom/dos/dos.conf b/rom/dos/dos.conf index 842e7e513c..fcb65c2bce 100644 --- a/rom/dos/dos.conf +++ b/rom/dos/dos.conf @@ -1,5 +1,5 @@ ##begin config -version 50.68 +version 50.69 libbase DOSBase libbasetype struct IntDosBase libbasetypeextern struct DosLibrary diff --git a/rom/dos/internalloadseg_aos.c b/rom/dos/internalloadseg_aos.c index cdee666de4..20a96c0b15 100644 --- a/rom/dos/internalloadseg_aos.c +++ b/rom/dos/internalloadseg_aos.c @@ -49,6 +49,8 @@ static int seek_forward(BPTR fd, ULONG count, SIPTR *funcarray, struct DosLibrar return err; } +static BOOL allowed_hunk(BPTR seglist); + BPTR InternalLoadSeg_AOS(BPTR fh, BPTR table, SIPTR * funcarray, @@ -72,7 +74,6 @@ BPTR InternalLoadSeg_AOS(BPTR fh, static STRPTR segtypes[] = { "CODE", "DATA", "BSS", }; #endif - SIPTR *error = &dummy; if (DOSBase) { @@ -437,6 +438,12 @@ BPTR InternalLoadSeg_AOS(BPTR fh, } /* switch */ } /* while */ done: + if (firsthunk && !allowed_hunk(firsthunk)) + { + ERROR(ERROR_NOT_EXECUTABLE); + goto end; + } + if (hunktab) { ULONG hunksize; @@ -575,3 +582,25 @@ AROS_UFH4(BPTR, LoadSeg_Overlay, } #endif + +static BOOL allowed_hunk(BPTR seglist) +{ +#ifdef __mc68000 + return TRUE; +#else + /* deadwood: This is a not-so-great solution to the problem of crashes/reboots + * when users accidentally try running m68k hunk executables. + * I think the better solution would be to load the hunk (or non-native elf) + * but stop it from executing or redirect to emulator by mechanism similar + * to OS4 GetSegListInfo() and struct PseudoSegList. This way also runtime + * generated seglists would be handled properly. + */ + UBYTE * ptr = (UBYTE *)BADDR(seglist); + + /* Allow bitmap fonts */ + if (ptr[22] == 0x0f && ptr[23] == 0x80) + return TRUE; + + return FALSE; +#endif +} -- 2.11.4.GIT