* [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing
@ 2023-08-10 19:54 Kees Cook
2023-08-10 19:54 ` [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing Kees Cook
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Kees Cook @ 2023-08-10 19:54 UTC (permalink / raw)
To: Russell King
Cc: Kees Cook, Arnd Bergmann, Lecopzer Chen, Oleg Nesterov,
Matthias Brugger, AngeloGioacchino Del Regno, Linus Walleij,
Wolfram Sang, Arnd Bergmann, Dan Williams, Russell King (Oracle),
linux-kernel, linux-arm-kernel, linux-mediatek, linux-hardening
Hi,
Fix tracing on arm since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall:
always store thread_info->abi_syscall"). This was seen with the broken
seccomp tests "syscall_errno", "syscall_faked", and "syscall_restart".
Thanks!
-Kees
v2:
- split fixes
- move scno store into the actual restart path
v1: https://lore.kernel.org/lkml/20230804071045.never.134-kees@kernel.org
Kees Cook (2):
ARM: ptrace: Restore syscall restart tracing
ARM: ptrace: Restore syscall skipping for tracers
arch/arm/include/asm/syscall.h | 3 +++
arch/arm/kernel/entry-common.S | 1 +
arch/arm/kernel/ptrace.c | 5 +++--
3 files changed, 7 insertions(+), 2 deletions(-)
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing
2023-08-10 19:54 [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
@ 2023-08-10 19:54 ` Kees Cook
2023-08-10 20:17 ` Arnd Bergmann
2023-08-10 19:54 ` [PATCH v2 2/2] ARM: ptrace: Restore syscall skipping for tracers Kees Cook
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2023-08-10 19:54 UTC (permalink / raw)
To: Russell King
Cc: Kees Cook, Arnd Bergmann, Lecopzer Chen, Oleg Nesterov,
linux-arm-kernel, Matthias Brugger, AngeloGioacchino Del Regno,
Linus Walleij, Wolfram Sang, Arnd Bergmann, Dan Williams,
Russell King (Oracle), linux-kernel, linux-mediatek,
linux-hardening
Since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store
thread_info->abi_syscall"), the seccomp selftests "syscall_restart" has
been broken. This was caused by the restart syscall not being stored to
"abi_syscall" during restart setup before branching to the "local_restart"
label. Tracers would see the wrong syscall, and scno would get overwritten
while returning from the TIF_WORK path. Add the missing store.
Cc: Russell King <linux@armlinux.org.uk>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
Fixes: 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store thread_info->abi_syscall")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
arch/arm/kernel/entry-common.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index bcc4c9ec3aa4..5c31e9de7a60 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -90,6 +90,7 @@ slow_work_pending:
cmp r0, #0
beq no_work_pending
movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
+ str scno, [tsk, #TI_ABI_SYSCALL] @ make sure tracers see update
ldmia sp, {r0 - r6} @ have to reload r0 - r6
b local_restart @ ... and off we go
ENDPROC(ret_fast_syscall)
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] ARM: ptrace: Restore syscall skipping for tracers
2023-08-10 19:54 [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
2023-08-10 19:54 ` [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing Kees Cook
@ 2023-08-10 19:54 ` Kees Cook
2023-08-10 20:11 ` Arnd Bergmann
2023-08-11 5:55 ` [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
2023-08-16 20:59 ` Kees Cook
3 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2023-08-10 19:54 UTC (permalink / raw)
To: Russell King
Cc: Kees Cook, Arnd Bergmann, Lecopzer Chen, Oleg Nesterov,
linux-arm-kernel, Matthias Brugger, AngeloGioacchino Del Regno,
Linus Walleij, Wolfram Sang, Arnd Bergmann, Dan Williams,
Russell King (Oracle), linux-kernel, linux-mediatek,
linux-hardening
Since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store
thread_info->abi_syscall"), the seccomp selftests "syscall_errno"
and "syscall_faked" have been broken. Both seccomp and PTRACE depend
on using the special value of "-1" for skipping syscalls. This value
wasn't working because it was getting masked by __NR_SYSCALL_MASK in
both PTRACE_SET_SYSCALL and get_syscall_nr().
Explicitly test for -1 in PTRACE_SET_SYSCALL and get_syscall_nr(),
leaving it exposed when present, allowing tracers to skip syscalls
again.
Cc: Russell King <linux@armlinux.org.uk>
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
Fixes: 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store thread_info->abi_syscall")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
arch/arm/include/asm/syscall.h | 3 +++
arch/arm/kernel/ptrace.c | 5 +++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h
index dfeed440254a..fe4326d938c1 100644
--- a/arch/arm/include/asm/syscall.h
+++ b/arch/arm/include/asm/syscall.h
@@ -25,6 +25,9 @@ static inline int syscall_get_nr(struct task_struct *task,
if (IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))
return task_thread_info(task)->abi_syscall;
+ if (task_thread_info(task)->abi_syscall == -1)
+ return -1;
+
return task_thread_info(task)->abi_syscall & __NR_SYSCALL_MASK;
}
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 2d8e2516906b..fef32d73f912 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -783,8 +783,9 @@ long arch_ptrace(struct task_struct *child, long request,
break;
case PTRACE_SET_SYSCALL:
- task_thread_info(child)->abi_syscall = data &
- __NR_SYSCALL_MASK;
+ if (data != -1)
+ data &= __NR_SYSCALL_MASK;
+ task_thread_info(child)->abi_syscall = data;
ret = 0;
break;
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] ARM: ptrace: Restore syscall skipping for tracers
2023-08-10 19:54 ` [PATCH v2 2/2] ARM: ptrace: Restore syscall skipping for tracers Kees Cook
@ 2023-08-10 20:11 ` Arnd Bergmann
0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2023-08-10 20:11 UTC (permalink / raw)
To: Kees Cook, Russell King
Cc: Arnd Bergmann, Lecopzer Chen, Oleg Nesterov, linux-arm-kernel,
Matthias Brugger, AngeloGioacchino Del Regno, Linus Walleij,
Wolfram Sang, Dan Williams, Russell King, linux-kernel,
linux-mediatek, linux-hardening
On Thu, Aug 10, 2023, at 21:54, Kees Cook wrote:
> Since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store
> thread_info->abi_syscall"), the seccomp selftests "syscall_errno"
> and "syscall_faked" have been broken. Both seccomp and PTRACE depend
> on using the special value of "-1" for skipping syscalls. This value
> wasn't working because it was getting masked by __NR_SYSCALL_MASK in
> both PTRACE_SET_SYSCALL and get_syscall_nr().
>
> Explicitly test for -1 in PTRACE_SET_SYSCALL and get_syscall_nr(),
> leaving it exposed when present, allowing tracers to skip syscalls
> again.
>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Arnd Bergmann <arnd@kernel.org>
> Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Fixes: 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store
> thread_info->abi_syscall")
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing
2023-08-10 19:54 ` [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing Kees Cook
@ 2023-08-10 20:17 ` Arnd Bergmann
0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2023-08-10 20:17 UTC (permalink / raw)
To: Kees Cook, Russell King
Cc: Arnd Bergmann, Lecopzer Chen, Oleg Nesterov, linux-arm-kernel,
Matthias Brugger, AngeloGioacchino Del Regno, Linus Walleij,
Wolfram Sang, Dan Williams, Russell King, linux-kernel,
linux-mediatek, linux-hardening
On Thu, Aug 10, 2023, at 21:54, Kees Cook wrote:
> Since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always store
> thread_info->abi_syscall"), the seccomp selftests "syscall_restart" has
> been broken. This was caused by the restart syscall not being stored to
> "abi_syscall" during restart setup before branching to the "local_restart"
> label. Tracers would see the wrong syscall, and scno would get overwritten
> while returning from the TIF_WORK path. Add the missing store.
>
> diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> index bcc4c9ec3aa4..5c31e9de7a60 100644
> --- a/arch/arm/kernel/entry-common.S
> +++ b/arch/arm/kernel/entry-common.S
> @@ -90,6 +90,7 @@ slow_work_pending:
> cmp r0, #0
> beq no_work_pending
> movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
> + str scno, [tsk, #TI_ABI_SYSCALL] @ make sure tracers see update
> ldmia sp, {r0 - r6} @ have to reload r0 - r6
> b local_restart @ ... and off we go
> ENDPROC(ret_fast_syscall)
Looks good to me, as in my previous reply this is safe for all cases
with the current restartable syscalls, though it would be wrong if
we had a restartblock version of epoll_wait on an OABI_COMPAT task,
which needs to look at the high bits of the number to tell which
structure layout to use.
I also looked at my original patch now and see what I did wrong
there.
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing
2023-08-10 19:54 [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
2023-08-10 19:54 ` [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing Kees Cook
2023-08-10 19:54 ` [PATCH v2 2/2] ARM: ptrace: Restore syscall skipping for tracers Kees Cook
@ 2023-08-11 5:55 ` Kees Cook
2023-08-16 20:59 ` Kees Cook
3 siblings, 0 replies; 7+ messages in thread
From: Kees Cook @ 2023-08-11 5:55 UTC (permalink / raw)
To: Russell King
Cc: Arnd Bergmann, Lecopzer Chen, Oleg Nesterov, Matthias Brugger,
AngeloGioacchino Del Regno, Linus Walleij, Wolfram Sang,
Arnd Bergmann, Dan Williams, Russell King (Oracle), linux-kernel,
linux-arm-kernel, linux-mediatek, linux-hardening
On Thu, Aug 10, 2023 at 12:54:17PM -0700, Kees Cook wrote:
> Fix tracing on arm since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall:
> always store thread_info->abi_syscall"). This was seen with the broken
> seccomp tests "syscall_errno", "syscall_faked", and "syscall_restart".
I'd like to get this fixed in v6.5. Russell, do you have a fixes tree
that you'll be sending Linus's way before the next -rc? I can send it
via my seccomp-fixes tree if that'd be easier.
Thanks!
-Kees
--
Kees Cook
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing
2023-08-10 19:54 [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
` (2 preceding siblings ...)
2023-08-11 5:55 ` [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
@ 2023-08-16 20:59 ` Kees Cook
3 siblings, 0 replies; 7+ messages in thread
From: Kees Cook @ 2023-08-16 20:59 UTC (permalink / raw)
To: Russell King, Kees Cook
Cc: Arnd Bergmann, Lecopzer Chen, Oleg Nesterov, Matthias Brugger,
AngeloGioacchino Del Regno, Linus Walleij, Wolfram Sang,
Arnd Bergmann, Dan Williams, Russell King (Oracle), linux-kernel,
linux-arm-kernel, linux-mediatek, linux-hardening
On Thu, 10 Aug 2023 12:54:17 -0700, Kees Cook wrote:
> Fix tracing on arm since commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall:
> always store thread_info->abi_syscall"). This was seen with the broken
> seccomp tests "syscall_errno", "syscall_faked", and "syscall_restart".
Applied to for-next/seccomp, thanks!
[1/2] ARM: ptrace: Restore syscall restart tracing
https://git.kernel.org/kees/c/cf007647475b
[2/2] ARM: ptrace: Restore syscall skipping for tracers
https://git.kernel.org/kees/c/4697b5848bd9
Take care,
--
Kees Cook
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-08-16 20:59 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 19:54 [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
2023-08-10 19:54 ` [PATCH v2 1/2] ARM: ptrace: Restore syscall restart tracing Kees Cook
2023-08-10 20:17 ` Arnd Bergmann
2023-08-10 19:54 ` [PATCH v2 2/2] ARM: ptrace: Restore syscall skipping for tracers Kees Cook
2023-08-10 20:11 ` Arnd Bergmann
2023-08-11 5:55 ` [PATCH v2 0/2] ARM: ptrace: Restore syscall skipping and restart while tracing Kees Cook
2023-08-16 20:59 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).