Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op

Move the code that calculates the type of the system call stop out of
ptrace_get_syscall_info() into a separate function
ptrace_get_syscall_info_op() which is going to be used later to implement
PTRACE_SET_SYSCALL_INFO API.

Link: https://lkml.kernel.org/r/20250303112038.GE24170@strace.io
Signed-off-by: Dmitry V. Levin <ldv@strace.io>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexey Gladkov (Intel) <legion@kernel.org>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: anton ivanov <anton.ivanov@cambridgegreys.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Brian Cain <bcain@quicinc.com>
Cc: Charlie Jenkins <charlie@rivosinc.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Zankel <chris@zankel.net>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Davide Berardi <berardi.dav@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Eugene Syromiatnikov <esyr@redhat.com>
Cc: Eugene Syromyatnikov <evgsyr@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Renzo Davoi <renzo@cs.unibo.it>
Cc: Richard Weinberger <richard@nod.at>
Cc: Rich Felker <dalias@libc.org>
Cc: Russel King <linux@armlinux.org.uk>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Dmitry V. Levin and committed by
Andrew Morton
c354ec9c cc662273

+34 -24
+34 -24
kernel/ptrace.c
··· 921 921 unsigned long args[ARRAY_SIZE(info->entry.args)]; 922 922 int i; 923 923 924 - info->op = PTRACE_SYSCALL_INFO_ENTRY; 925 924 info->entry.nr = syscall_get_nr(child, regs); 926 925 syscall_get_arguments(child, regs, args); 927 926 for (i = 0; i < ARRAY_SIZE(args); i++) ··· 942 943 * diverge significantly enough. 943 944 */ 944 945 ptrace_get_syscall_info_entry(child, regs, info); 945 - info->op = PTRACE_SYSCALL_INFO_SECCOMP; 946 946 info->seccomp.ret_data = child->ptrace_message; 947 947 948 948 /* ret_data is the last field in struct ptrace_syscall_info.seccomp */ ··· 952 954 ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs, 953 955 struct ptrace_syscall_info *info) 954 956 { 955 - info->op = PTRACE_SYSCALL_INFO_EXIT; 956 957 info->exit.rval = syscall_get_error(child, regs); 957 958 info->exit.is_error = !!info->exit.rval; 958 959 if (!info->exit.is_error) ··· 962 965 } 963 966 964 967 static int 965 - ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size, 966 - void __user *datavp) 968 + ptrace_get_syscall_info_op(struct task_struct *child) 967 969 { 968 - struct pt_regs *regs = task_pt_regs(child); 969 - struct ptrace_syscall_info info = { 970 - .op = PTRACE_SYSCALL_INFO_NONE, 971 - .arch = syscall_get_arch(child), 972 - .instruction_pointer = instruction_pointer(regs), 973 - .stack_pointer = user_stack_pointer(regs), 974 - }; 975 - unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry); 976 - unsigned long write_size; 977 - 978 970 /* 979 971 * This does not need lock_task_sighand() to access 980 972 * child->last_siginfo because ptrace_freeze_traced() ··· 974 988 case SIGTRAP | 0x80: 975 989 switch (child->ptrace_message) { 976 990 case PTRACE_EVENTMSG_SYSCALL_ENTRY: 977 - actual_size = ptrace_get_syscall_info_entry(child, regs, 978 - &info); 979 - break; 991 + return PTRACE_SYSCALL_INFO_ENTRY; 980 992 case PTRACE_EVENTMSG_SYSCALL_EXIT: 981 - actual_size = ptrace_get_syscall_info_exit(child, regs, 982 - &info); 983 - break; 993 + return PTRACE_SYSCALL_INFO_EXIT; 994 + default: 995 + return PTRACE_SYSCALL_INFO_NONE; 984 996 } 985 - break; 986 997 case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8): 987 - actual_size = ptrace_get_syscall_info_seccomp(child, regs, 988 - &info); 998 + return PTRACE_SYSCALL_INFO_SECCOMP; 999 + default: 1000 + return PTRACE_SYSCALL_INFO_NONE; 1001 + } 1002 + } 1003 + 1004 + static int 1005 + ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size, 1006 + void __user *datavp) 1007 + { 1008 + struct pt_regs *regs = task_pt_regs(child); 1009 + struct ptrace_syscall_info info = { 1010 + .op = ptrace_get_syscall_info_op(child), 1011 + .arch = syscall_get_arch(child), 1012 + .instruction_pointer = instruction_pointer(regs), 1013 + .stack_pointer = user_stack_pointer(regs), 1014 + }; 1015 + unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry); 1016 + unsigned long write_size; 1017 + 1018 + switch (info.op) { 1019 + case PTRACE_SYSCALL_INFO_ENTRY: 1020 + actual_size = ptrace_get_syscall_info_entry(child, regs, &info); 1021 + break; 1022 + case PTRACE_SYSCALL_INFO_EXIT: 1023 + actual_size = ptrace_get_syscall_info_exit(child, regs, &info); 1024 + break; 1025 + case PTRACE_SYSCALL_INFO_SECCOMP: 1026 + actual_size = ptrace_get_syscall_info_seccomp(child, regs, &info); 989 1027 break; 990 1028 } 991 1029