Skip to content

Commit 17fc7b8

Browse files
ldv-altakpm00
authored andcommitted
syscall.h: add syscall_set_arguments()
This function is going to be needed on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. This partially reverts commit 7962c2e ("arch: remove unused function syscall_set_arguments()") by reusing some of old syscall_set_arguments() implementations. [nathan@kernel.org: fix compile time fortify checks] Link: https://lkml.kernel.org/r/20250408213131.GA2872426@ax162 Link: https://lkml.kernel.org/r/20250303112009.GC24170@strace.io Signed-off-by: Dmitry V. Levin <ldv@strace.io> Signed-off-by: Nathan Chancellor <nathan@kernel.org> Tested-by: Charlie Jenkins <charlie@rivosinc.com> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Acked-by: Helge Deller <deller@gmx.de> # parisc Reviewed-by: Maciej W. Rozycki <macro@orcam.me.uk> [mips] 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: 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: "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: 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: Oleg Nesterov <oleg@redhat.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>
1 parent 87a929a commit 17fc7b8

File tree

19 files changed

+256
-0
lines changed

19 files changed

+256
-0
lines changed

arch/arc/include/asm/syscall.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
6767
}
6868
}
6969

70+
static inline void
71+
syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
72+
unsigned long *args)
73+
{
74+
unsigned long *inside_ptregs = &regs->r0;
75+
unsigned int n = 6;
76+
unsigned int i = 0;
77+
78+
while (n--) {
79+
*inside_ptregs = args[i++];
80+
inside_ptregs--;
81+
}
82+
}
83+
7084
static inline int
7185
syscall_get_arch(struct task_struct *task)
7286
{

arch/arm/include/asm/syscall.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ static inline void syscall_get_arguments(struct task_struct *task,
8080
memcpy(args, &regs->ARM_r0 + 1, 5 * sizeof(args[0]));
8181
}
8282

83+
static inline void syscall_set_arguments(struct task_struct *task,
84+
struct pt_regs *regs,
85+
const unsigned long *args)
86+
{
87+
memcpy(&regs->ARM_r0, args, 6 * sizeof(args[0]));
88+
/*
89+
* Also copy the first argument into ARM_ORIG_r0
90+
* so that syscall_get_arguments() would return it
91+
* instead of the previous value.
92+
*/
93+
regs->ARM_ORIG_r0 = regs->ARM_r0;
94+
}
95+
8396
static inline int syscall_get_arch(struct task_struct *task)
8497
{
8598
/* ARM tasks don't change audit architectures on the fly. */

arch/arm64/include/asm/syscall.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ static inline void syscall_get_arguments(struct task_struct *task,
7373
memcpy(args, &regs->regs[1], 5 * sizeof(args[0]));
7474
}
7575

76+
static inline void syscall_set_arguments(struct task_struct *task,
77+
struct pt_regs *regs,
78+
const unsigned long *args)
79+
{
80+
memcpy(&regs->regs[0], args, 6 * sizeof(args[0]));
81+
/*
82+
* Also copy the first argument into orig_x0
83+
* so that syscall_get_arguments() would return it
84+
* instead of the previous value.
85+
*/
86+
regs->orig_x0 = regs->regs[0];
87+
}
88+
7689
/*
7790
* We don't care about endianness (__AUDIT_ARCH_LE bit) here because
7891
* AArch64 has the same system calls both on little- and big- endian.

arch/csky/include/asm/syscall.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
5959
memcpy(args, &regs->a1, 5 * sizeof(args[0]));
6060
}
6161

62+
static inline void
63+
syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
64+
const unsigned long *args)
65+
{
66+
memcpy(&regs->a0, args, 6 * sizeof(regs->a0));
67+
/*
68+
* Also copy the first argument into orig_a0
69+
* so that syscall_get_arguments() would return it
70+
* instead of the previous value.
71+
*/
72+
regs->orig_a0 = regs->a0;
73+
}
74+
6275
static inline int
6376
syscall_get_arch(struct task_struct *task)
6477
{

arch/hexagon/include/asm/syscall.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ static inline void syscall_get_arguments(struct task_struct *task,
3333
memcpy(args, &(&regs->r00)[0], 6 * sizeof(args[0]));
3434
}
3535

36+
static inline void syscall_set_arguments(struct task_struct *task,
37+
struct pt_regs *regs,
38+
unsigned long *args)
39+
{
40+
memcpy(&(&regs->r00)[0], args, 6 * sizeof(args[0]));
41+
}
42+
3643
static inline long syscall_get_error(struct task_struct *task,
3744
struct pt_regs *regs)
3845
{

arch/loongarch/include/asm/syscall.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ static inline void syscall_get_arguments(struct task_struct *task,
6161
memcpy(&args[1], &regs->regs[5], 5 * sizeof(long));
6262
}
6363

64+
static inline void syscall_set_arguments(struct task_struct *task,
65+
struct pt_regs *regs,
66+
unsigned long *args)
67+
{
68+
regs->orig_a0 = args[0];
69+
memcpy(&regs->regs[5], &args[1], 5 * sizeof(long));
70+
}
71+
6472
static inline int syscall_get_arch(struct task_struct *task)
6573
{
6674
return AUDIT_ARCH_LOONGARCH64;

arch/mips/include/asm/syscall.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ static inline void mips_get_syscall_arg(unsigned long *arg,
7474
#endif
7575
}
7676

77+
static inline void mips_set_syscall_arg(unsigned long *arg,
78+
struct task_struct *task, struct pt_regs *regs, unsigned int n)
79+
{
80+
#ifdef CONFIG_32BIT
81+
switch (n) {
82+
case 0: case 1: case 2: case 3:
83+
regs->regs[4 + n] = *arg;
84+
return;
85+
case 4: case 5: case 6: case 7:
86+
*arg = regs->args[n] = *arg;
87+
return;
88+
}
89+
#else
90+
regs->regs[4 + n] = *arg;
91+
#endif
92+
}
93+
7794
static inline long syscall_get_error(struct task_struct *task,
7895
struct pt_regs *regs)
7996
{
@@ -120,6 +137,17 @@ static inline void syscall_get_arguments(struct task_struct *task,
120137
mips_get_syscall_arg(args++, task, regs, i++);
121138
}
122139

140+
static inline void syscall_set_arguments(struct task_struct *task,
141+
struct pt_regs *regs,
142+
unsigned long *args)
143+
{
144+
unsigned int i = 0;
145+
unsigned int n = 6;
146+
147+
while (n--)
148+
mips_set_syscall_arg(args++, task, regs, i++);
149+
}
150+
123151
extern const unsigned long sys_call_table[];
124152
extern const unsigned long sys32_call_table[];
125153
extern const unsigned long sysn32_call_table[];

arch/nios2/include/asm/syscall.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ static inline void syscall_get_arguments(struct task_struct *task,
5858
*args = regs->r9;
5959
}
6060

61+
static inline void syscall_set_arguments(struct task_struct *task,
62+
struct pt_regs *regs, const unsigned long *args)
63+
{
64+
regs->r4 = *args++;
65+
regs->r5 = *args++;
66+
regs->r6 = *args++;
67+
regs->r7 = *args++;
68+
regs->r8 = *args++;
69+
regs->r9 = *args;
70+
}
71+
6172
static inline int syscall_get_arch(struct task_struct *task)
6273
{
6374
return AUDIT_ARCH_NIOS2;

arch/openrisc/include/asm/syscall.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
5757
memcpy(args, &regs->gpr[3], 6 * sizeof(args[0]));
5858
}
5959

60+
static inline void
61+
syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
62+
const unsigned long *args)
63+
{
64+
memcpy(&regs->gpr[3], args, 6 * sizeof(args[0]));
65+
}
66+
6067
static inline int syscall_get_arch(struct task_struct *task)
6168
{
6269
return AUDIT_ARCH_OPENRISC;

arch/parisc/include/asm/syscall.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ static inline void syscall_get_arguments(struct task_struct *tsk,
2929
args[0] = regs->gr[26];
3030
}
3131

32+
static inline void syscall_set_arguments(struct task_struct *tsk,
33+
struct pt_regs *regs,
34+
unsigned long *args)
35+
{
36+
regs->gr[21] = args[5];
37+
regs->gr[22] = args[4];
38+
regs->gr[23] = args[3];
39+
regs->gr[24] = args[2];
40+
regs->gr[25] = args[1];
41+
regs->gr[26] = args[0];
42+
}
43+
3244
static inline long syscall_get_error(struct task_struct *task,
3345
struct pt_regs *regs)
3446
{

0 commit comments

Comments
 (0)