mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-20 22:13:25 +00:00
unaligned call protection
This commit is contained in:
parent
10cdd1b85f
commit
b4a5f830eb
30
src/luajit.c
30
src/luajit.c
@ -630,10 +630,13 @@ return x+y;
|
|||||||
|
|
||||||
#define C_FUNCTIONS_N 10
|
#define C_FUNCTIONS_N 10
|
||||||
|
|
||||||
|
|
||||||
struct global_var_t {
|
struct global_var_t {
|
||||||
char input_buffer[LUA_MAXINPUT];
|
char input_buffer[LUA_MAXINPUT];
|
||||||
int (*c_functions[C_FUNCTIONS_N]) (void);
|
int (*c_functions[C_FUNCTIONS_N]) (void);
|
||||||
} global = {{},{random_digit,get_time,do_something,0,0,0,0,0,0,0}};
|
}
|
||||||
|
__attribute__ ((aligned (0x10000))) // early optimization rocks
|
||||||
|
global = {{},{random_digit,get_time,do_something,0,0,0,0,0,0,0}};
|
||||||
|
|
||||||
static int pushline(lua_State *L, int firstline)
|
static int pushline(lua_State *L, int firstline)
|
||||||
{
|
{
|
||||||
@ -654,17 +657,26 @@ static int pushline(lua_State *L, int firstline)
|
|||||||
|
|
||||||
extern int call_c_function(int n)
|
extern int call_c_function(int n)
|
||||||
{
|
{
|
||||||
|
int (*func) (void) = global.c_functions[n];
|
||||||
|
|
||||||
|
// should not happen but we never know
|
||||||
|
if(((size_t)&global.c_functions[n] & ~0xffff) != (((size_t)&global) & ~0xffff))
|
||||||
|
{
|
||||||
|
printf("[DEBUG] Unaligned call.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (n>=C_FUNCTIONS_N){
|
if (n>=C_FUNCTIONS_N){
|
||||||
printf("Out of bounds call at index %d\n",n);
|
printf("[DEBUG] Out of bounds call at index %d\n",n);
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
else if(global.c_functions[n]==0){
|
else if(func==0){
|
||||||
printf("Null function pointer at index %d\n",n);
|
printf("[DEBUG] Null function pointer at index %d\n",n);
|
||||||
return -1;
|
return -3;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printf("Calling C function at address %p\n",global.c_functions[n]);
|
printf("[DEBUG] Calling C function at address %p\n",func);
|
||||||
return global.c_functions[n]();
|
return func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,7 +708,7 @@ int main(int argc, char **argv)
|
|||||||
smain.argc = argc;
|
smain.argc = argc;
|
||||||
smain.argv = argv;
|
smain.argv = argv;
|
||||||
|
|
||||||
printf("Seccomps activated");
|
printf("[DEBUG] Seccomps activated\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
init_seccomp();
|
init_seccomp();
|
||||||
|
Loading…
Reference in New Issue
Block a user