syscall: add config option to check syscall source

This commit is contained in:
anna 2021-08-01 23:28:25 +02:00
parent 930cbc26e1
commit 7ef26f26e9
Signed by: fef
GPG key ID: EC22E476DC2D3D84
4 changed files with 24 additions and 0 deletions

View file

@ -9,6 +9,13 @@
#include <errno.h>
#include <stddef.h>
#include <config.h>
#ifdef CONFIG_CHECK_SYSCALL_SOURCE
/* syscall.S */
extern uintptr_t __syscall_entry_point;
#endif
void arch_enter(void *sp)
{
struct reg_snapshot *regs = sp;
@ -17,6 +24,18 @@ void arch_enter(void *sp)
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
int sc_ret;
# ifdef CONFIG_CHECK_SYSCALL_SOURCE
/*
* We need to ignore the program counter's LSB because the CPU uses
* that as a flag for whether it's operating in ARM or Thumb mode
* (1 for Thumb); the instructions are always 2-byte aligned.
*/
if ((regs->hw.pc & 0xfffffffe) != __syscall_entry_point) {
arch_syscall_set_rval(regs, -EACCES);
return;
}
# endif
if (sc_num > NSYSCALLS) {
arch_syscall_set_rval(regs, -ENOSYS);
return;

View file

@ -32,6 +32,8 @@ func_begin syscall
ldr r4, [sp, #16] /* arg5 */
ldr r5, [sp, #20] /* arg6 */
.global __syscall_entry_point
__syscall_entry_point:
svc #0
pop {r4-r5,r7}

View file

@ -13,6 +13,7 @@
#define ARDIX_VERSION_STR "@ardix_VERSION@@ardix_VERSION_SUFFIX@"
#cmakedefine DEBUG
#cmakedefine CONFIG_CHECK_SYSCALL_SOURCE
#define ARCH "@ARCH@"
#define ARCH_@ARCH_UPPERCASE@

View file

@ -25,6 +25,8 @@ set(CONFIG_SERIAL_BUFSZ 256 CACHE STRING "Default serial buffer size in bytes")
set(CONFIG_PRINTF_BUFSZ 64 CACHE STRING "Default buffer size for printf() and friends")
option(CONFIG_CHECK_SYSCALL_SOURCE "Prohibit inline syscalls" OFF)
# This file is part of Ardix.
# Copyright (c) 2021 Felix Kopp <owo@fef.moe>.
#