Skip to content

Commit 7b22c03

Browse files
AKASHI Takahiroctmarinas
AKASHI Takahiro
authored andcommitted
arm64: check for number of arguments in syscall_get/set_arguments()
In ftrace_syscall_enter(), syscall_get_arguments(..., 0, n, ...) if (i == 0) { <handle orig_x0> ...; n--;} memcpy(..., n * sizeof(args[0])); If 'number of arguments(n)' is zero and 'argument index(i)' is also zero in syscall_get_arguments(), none of arguments should be copied by memcpy(). Otherwise 'n--' can be a big positive number and unexpected amount of data will be copied. Tracing system calls which take no argument, say sync(void), may hit this case and eventually make the system corrupted. This patch fixes the issue both in syscall_get_arguments() and syscall_set_arguments(). Signed-off-by: AKASHI Takahiro <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent d0e639c commit 7b22c03

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/arm64/include/asm/syscall.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ static inline void syscall_get_arguments(struct task_struct *task,
5959
unsigned int i, unsigned int n,
6060
unsigned long *args)
6161
{
62+
if (n == 0)
63+
return;
64+
6265
if (i + n > SYSCALL_MAX_ARGS) {
6366
unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
6467
unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
@@ -82,6 +85,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
8285
unsigned int i, unsigned int n,
8386
const unsigned long *args)
8487
{
88+
if (n == 0)
89+
return;
90+
8591
if (i + n > SYSCALL_MAX_ARGS) {
8692
pr_warning("%s called with max args %d, handling only %d\n",
8793
__func__, i + n, SYSCALL_MAX_ARGS);

0 commit comments

Comments
 (0)