2022-10-31 22:33:28

by Kuniyuki Iwashima

[permalink] [raw]
Subject: [PATCH] arm64/syscall: Include asm/ptrace.h in syscall_wrapper header.

Add the same change for ARM64 as done in the commit 9440c4294160
("x86/syscall: Include asm/ptrace.h in syscall_wrapper header") to
make sure all syscalls see 'struct pt_regs' definition and resulted
BTF for '__arm64_sys_*(struct pt_regs *regs)' functions point to
actual struct.

Without this patch, the BPF verifier refuses to load a tracing prog
which accesses pt_regs.

bpf(BPF_PROG_LOAD, {prog_type=0x1a, ...}, 128) = -1 EACCES

With this patch, we can see the correct error, which saves us time
in debugging the prog.

bpf(BPF_PROG_LOAD, {prog_type=0x1a, ...}, 128) = 4
bpf(BPF_RAW_TRACEPOINT_OPEN, {raw_tracepoint={name=NULL, prog_fd=4}}, 128) = -1 ENOTSUPP

Signed-off-by: Kuniyuki Iwashima <[email protected]>
---
Note the cited commit only exists in the tip tree for now.
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=9440c42941606af4c379afa3cf8624f0dc43a629
---
arch/arm64/include/asm/syscall_wrapper.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h
index b383b4802a7b..d30217c21eff 100644
--- a/arch/arm64/include/asm/syscall_wrapper.h
+++ b/arch/arm64/include/asm/syscall_wrapper.h
@@ -8,7 +8,7 @@
#ifndef __ASM_SYSCALL_WRAPPER_H
#define __ASM_SYSCALL_WRAPPER_H

-struct pt_regs;
+#include <asm/ptrace.h>

#define SC_ARM64_REGS_TO_ARGS(x, ...) \
__MAP(x,__SC_ARGS \
--
2.30.2



2022-11-04 21:15:08

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH] arm64/syscall: Include asm/ptrace.h in syscall_wrapper header.

On Mon, Oct 31, 2022 at 2:57 PM Kuniyuki Iwashima <[email protected]> wrote:
>
> Add the same change for ARM64 as done in the commit 9440c4294160
> ("x86/syscall: Include asm/ptrace.h in syscall_wrapper header") to
> make sure all syscalls see 'struct pt_regs' definition and resulted
> BTF for '__arm64_sys_*(struct pt_regs *regs)' functions point to
> actual struct.
>
> Without this patch, the BPF verifier refuses to load a tracing prog
> which accesses pt_regs.
>
> bpf(BPF_PROG_LOAD, {prog_type=0x1a, ...}, 128) = -1 EACCES
>
> With this patch, we can see the correct error, which saves us time
> in debugging the prog.
>
> bpf(BPF_PROG_LOAD, {prog_type=0x1a, ...}, 128) = 4
> bpf(BPF_RAW_TRACEPOINT_OPEN, {raw_tracepoint={name=NULL, prog_fd=4}}, 128) = -1 ENOTSUPP
>
> Signed-off-by: Kuniyuki Iwashima <[email protected]>
> ---

Some of these problems will be mitigated by [0], but still good to
have completely types if possible. LGTM.

Acked-by: Andrii Nakryiko <[email protected]>

[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=691488&state=*

> Note the cited commit only exists in the tip tree for now.
> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=9440c42941606af4c379afa3cf8624f0dc43a629
> ---
> arch/arm64/include/asm/syscall_wrapper.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h
> index b383b4802a7b..d30217c21eff 100644
> --- a/arch/arm64/include/asm/syscall_wrapper.h
> +++ b/arch/arm64/include/asm/syscall_wrapper.h
> @@ -8,7 +8,7 @@
> #ifndef __ASM_SYSCALL_WRAPPER_H
> #define __ASM_SYSCALL_WRAPPER_H
>
> -struct pt_regs;
> +#include <asm/ptrace.h>
>
> #define SC_ARM64_REGS_TO_ARGS(x, ...) \
> __MAP(x,__SC_ARGS \
> --
> 2.30.2
>

2022-11-09 10:29:18

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH] arm64/syscall: Include asm/ptrace.h in syscall_wrapper header.

On Mon, 31 Oct 2022 14:57:28 -0700, Kuniyuki Iwashima wrote:
> Add the same change for ARM64 as done in the commit 9440c4294160
> ("x86/syscall: Include asm/ptrace.h in syscall_wrapper header") to
> make sure all syscalls see 'struct pt_regs' definition and resulted
> BTF for '__arm64_sys_*(struct pt_regs *regs)' functions point to
> actual struct.
>
> Without this patch, the BPF verifier refuses to load a tracing prog
> which accesses pt_regs.
>
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64/syscall: Include asm/ptrace.h in syscall_wrapper header.
https://git.kernel.org/arm64/c/acfc35cfcee5

--
Catalin