History

Merge tag 'trace-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace

Pull syscall-get-arguments cleanup and fixes from Steven Rostedt: "Andy Lutomirski approached me to tell me that the syscall_get_arguments() implementation in x86 was horrible and gcc certainly gets it wrong. He said that since the tracepoints only pass in 0 and 6 for i and n repectively, it should be optimized for that case. Inspecting the kernel, I discovered that all users pass in 0 for i and only one file passing in something other than 6 for the number of arguments. That code happens to be my own code used for the special syscall tracing. That can easily be converted to just using 0 and 6 as well, and only copying what is needed. Which is probably the faster path anyway for that case. Along the way, a couple of real fixes came from this as the syscall_get_arguments() function was incorrect for csky and riscv. x86 has been optimized to for the new interface that removes the variable number of arguments, but the other architectures could still use some loving and take more advantage of the simpler interface" * tag 'trace-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: syscalls: Remove start and number from syscall_set_arguments() args syscalls: Remove start and number from syscall_get_arguments() args csky: Fix syscall_get_arguments() and syscall_set_arguments() riscv: Fix syscall_get_arguments() and syscall_set_arguments() tracing/syscalls: Pass in hardcoded 6 into syscall_get_arguments() ptrace: Remove maxargs from task_current_syscall()

Linus Torvalds committed 7 years ago

Commit 970b7662 parents 7f46774 32d925832 files · +247 −722Browse files

Unified · Split

32 files
  1. arch/arc/include/asm/syscall.h +3 −4
  2. arch/arm/include/asm/syscall.h +8 −39
  3. arch/arm64/include/asm/syscall.h +8 −38
  4. arch/c6x/include/asm/syscall.h +14 −65
  5. arch/csky/include/asm/syscall.h +8 −18
  6. arch/h8300/include/asm/syscall.h +7 −27
  7. arch/hexagon/include/asm/syscall.h +1 −3
  8. arch/ia64/include/asm/syscall.h +3 −10
  9. arch/ia64/kernel/ptrace.c +3 −4
  10. arch/microblaze/include/asm/syscall.h +6 −2
  11. arch/mips/include/asm/syscall.h +2 −1
  12. arch/mips/kernel/ptrace.c +1 −1
  13. arch/nds32/include/asm/syscall.h +11 −51
  14. arch/nios2/include/asm/syscall.h +14 −70
  15. arch/openrisc/include/asm/syscall.h +4 −8
  16. arch/parisc/include/asm/syscall.h +8 −22
  17. arch/powerpc/include/asm/syscall.h +5 −10
  18. arch/riscv/include/asm/syscall.h +6 −18
  19. arch/s390/include/asm/syscall.h +10 −18
  20. arch/sh/include/asm/syscall_32.h +12 −35
  21. arch/sh/include/asm/syscall_64.h +2 −6
  22. arch/sparc/include/asm/syscall.h +5 −6
  23. arch/um/include/asm/syscall-generic.h +12 −66
  24. arch/x86/include/asm/syscall.h +33 −109
  25. arch/xtensa/include/asm/syscall.h +6 −27
  26. fs/proc/base.c +9 −8
  27. include/asm-generic/syscall.h +5 −16
  28. include/linux/ptrace.h +8 −3
  29. include/trace/events/syscalls.h +1 −1
  30. kernel/seccomp.c +1 −1
  31. kernel/trace/trace_syscalls.c +6 −3
  32. lib/syscall.c +25 −32
arch/arc/include/asm/syscall.h+3−4
@@ -55,12 +55,11 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, · 54 unmodified lines
5555 */
5656 static inline void
5757 syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
58− unsigned int i, unsigned int n, unsigned long *args)
58+ unsigned long *args)
5959 {
6060 unsigned long *inside_ptregs = &(regs->r0);
61− inside_ptregs -= i;
62−
63− BUG_ON((i + n) > 6);
61+ unsigned int n = 6;
62+ unsigned int i = 0;
6463
6564 while (n--) {
6665 args[i++] = (*inside_ptregs);
arch/arm/include/asm/syscall.h+8−39
@@ -55,53 +55,22 @@ static inline void syscall_set_return_value(struct task_struct *task, · 54 unmodified lines
5555
5656 static inline void syscall_get_arguments(struct task_struct *task,
5757 struct pt_regs *regs,
58− unsigned int i, unsigned int n,
5958 unsigned long *args)
6059 {
61− if (n == 0)
62− return;
63−
64− if (i + n > SYSCALL_MAX_ARGS) {
65− unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
66− unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
67− pr_warn("%s called with max args %d, handling only %d\n",
68− __func__, i + n, SYSCALL_MAX_ARGS);
69− memset(args_bad, 0, n_bad * sizeof(args[0]));
70− n = SYSCALL_MAX_ARGS - i;
71− }
72−
73− if (i == 0) {
74− args[0] = regs->ARM_ORIG_r0;
75− args++;
76− i++;
77− n--;
78− }
79−
80− memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
60+ args[0] = regs->ARM_ORIG_r0;
61+ args++;
62+
63+ memcpy(args, &regs->ARM_r0 + 1, 5 * sizeof(args[0]));
8164 }
8265
8366 static inline void syscall_set_arguments(struct task_struct *task,
8467 struct pt_regs *regs,
85− unsigned int i, unsigned int n,
8668 const unsigned long *args)
8769 {
88− if (n == 0)
89− return;
90−
91− if (i + n > SYSCALL_MAX_ARGS) {
92− pr_warn("%s called with max args %d, handling only %d\n",
93− __func__, i + n, SYSCALL_MAX_ARGS);
94− n = SYSCALL_MAX_ARGS - i;
95− }
96−
97− if (i == 0) {
98− regs->ARM_ORIG_r0 = args[0];
99− args++;
100− i++;
101− n--;
102− }
103−
104− memcpy(&regs->ARM_r0 + i, args, n * sizeof(args[0]));
70+ regs->ARM_ORIG_r0 = args[0];
71+ args++;
72+
73+ memcpy(&regs->ARM_r0 + 1, args, 5 * sizeof(args[0]));
10574 }
10675
10776 static inline int syscall_get_arch(void)
arch/arm64/include/asm/syscall.h+8−38
@@ -65,52 +65,22 @@ static inline void syscall_set_return_value(struct task_struct *task, · 64 unmodified lines
6565
6666 static inline void syscall_get_arguments(struct task_struct *task,
6767 struct pt_regs *regs,
68− unsigned int i, unsigned int n,
6968 unsigned long *args)
7069 {
71− if (n == 0)
72− return;
73−
74− if (i + n > SYSCALL_MAX_ARGS) {
75− unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
76− unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
77− pr_warning("%s called with max args %d, handling only %d\n",
78− __func__, i + n, SYSCALL_MAX_ARGS);
79− memset(args_bad, 0, n_bad * sizeof(args[0]));
80− }
81−
82− if (i == 0) {
83− args[0] = regs->orig_x0;
84− args++;
85− i++;
86− n--;
87− }
88−
89− memcpy(args, &regs->regs[i], n * sizeof(args[0]));
70+ args[0] = regs->orig_x0;
71+ args++;
72+
73+ memcpy(args, &regs->regs[1], 5 * sizeof(args[0]));
9074 }
9175
9276 static inline void syscall_set_arguments(struct task_struct *task,
9377 struct pt_regs *regs,
94− unsigned int i, unsigned int n,
9578 const unsigned long *args)
9679 {
97− if (n == 0)
98− return;
99−
100− if (i + n > SYSCALL_MAX_ARGS) {
101− pr_warning("%s called with max args %d, handling only %d\n",
102− __func__, i + n, SYSCALL_MAX_ARGS);
103− n = SYSCALL_MAX_ARGS - i;
104− }
105−
106− if (i == 0) {
107− regs->orig_x0 = args[0];
108− args++;
109− i++;
110− n--;
111− }
112−
113− memcpy(&regs->regs[i], args, n * sizeof(args[0]));
80+ regs->orig_x0 = args[0];
81+ args++;
82+
83+ memcpy(&regs->regs[1], args, 5 * sizeof(args[0]));
11484 }
11585
11686 /*
arch/c6x/include/asm/syscall.h+14−65
@@ -46,78 +46,27 @@ static inline void syscall_set_return_value(struct task_struct *task, · 45 unmodified lines
4646 }
4747
4848 static inline void syscall_get_arguments(struct task_struct *task,
49− struct pt_regs *regs, unsigned int i,
50− unsigned int n, unsigned long *args)
49+ struct pt_regs *regs,
50+ unsigned long *args)
5151 {
52− switch (i) {
53− case 0:
54− if (!n--)
55− break;
56− *args++ = regs->a4;
57− case 1:
58− if (!n--)
59− break;
60− *args++ = regs->b4;
61− case 2:
62− if (!n--)
63− break;
64− *args++ = regs->a6;
65− case 3:
66− if (!n--)
67− break;
68− *args++ = regs->b6;
69− case 4:
70− if (!n--)
71− break;
72− *args++ = regs->a8;
73− case 5:
74− if (!n--)
75− break;
76− *args++ = regs->b8;
77− case 6:
78− if (!n--)
79− break;
80− default:
81− BUG();
82− }
52+ *args++ = regs->a4;
53+ *args++ = regs->b4;
54+ *args++ = regs->a6;
55+ *args++ = regs->b6;
56+ *args++ = regs->a8;
57+ *args = regs->b8;
8358 }
8459
8560 static inline void syscall_set_arguments(struct task_struct *task,
8661 struct pt_regs *regs,
87− unsigned int i, unsigned int n,
8862 const unsigned long *args)
8963 {
90− switch (i) {
91− case 0:
92− if (!n--)
93− break;
94− regs->a4 = *args++;
95− case 1:
96− if (!n--)
97− break;
98− regs->b4 = *args++;
99− case 2:
100− if (!n--)
101− break;
102− regs->a6 = *args++;
103− case 3:
104− if (!n--)
105− break;
106− regs->b6 = *args++;
107− case 4:
108− if (!n--)
109− break;
110− regs->a8 = *args++;
111− case 5:
112− if (!n--)
113− break;
114− regs->a9 = *args++;
115− case 6:
116− if (!n)
117− break;
118− default:
119− BUG();
120− }
64+ regs->a4 = *args++;
65+ regs->b4 = *args++;
66+ regs->a6 = *args++;
67+ regs->b6 = *args++;
68+ regs->a8 = *args++;
69+ regs->a9 = *args;
12170 }
12271
12372 #endif /* __ASM_C6X_SYSCALLS_H */
arch/csky/include/asm/syscall.h+8−18
@@ -43,30 +43,20 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, · 42 unmodified lines
4343
4444 static inline void
4545 syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
46− unsigned int i, unsigned int n, unsigned long *args)
46+ unsigned long *args)
4747 {
48− BUG_ON(i + n > 6);
49− if (i == 0) {
50− args[0] = regs->orig_a0;
51− args++;
52− i++;
53− n--;
54− }
55− memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
48+ args[0] = regs->orig_a0;
49+ args++;
50+ memcpy(args, &regs->a1, 5 * sizeof(args[0]));
5651 }
5752
5853 static inline void
5954 syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
60− unsigned int i, unsigned int n, const unsigned long *args)
55+ const unsigned long *args)
6156 {
62− BUG_ON(i + n > 6);
63− if (i == 0) {
64− regs->orig_a0 = args[0];
65− args++;
66− i++;
67− n--;
68− }
69− memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
57+ regs->orig_a0 = args[0];
58+ args++;
59+ memcpy(&regs->a1, args, 5 * sizeof(regs->a1));
7060 }
7161
7262 static inline int
arch/h8300/include/asm/syscall.h+7−27
@@ -17,34 +17,14 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) · 16 unmodified lines
1717
1818 static inline void
1919 syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
20− unsigned int i, unsigned int n, unsigned long *args)
20+ unsigned long *args)
2121 {
22− BUG_ON(i + n > 6);
23−
24− while (n > 0) {
25− switch (i) {
26− case 0:
27− *args++ = regs->er1;
28− break;
29− case 1:
30− *args++ = regs->er2;
31− break;
32− case 2:
33− *args++ = regs->er3;
34− break;
35− case 3:
36− *args++ = regs->er4;
37− break;
38− case 4:
39− *args++ = regs->er5;
40− break;
41− case 5:
42− *args++ = regs->er6;
43− break;
44− }
45− i++;
46− n--;
47− }
22+ *args++ = regs->er1;
23+ *args++ = regs->er2;
24+ *args++ = regs->er3;
25+ *args++ = regs->er4;
26+ *args++ = regs->er5;
27+ *args = regs->er6;
4828 }
4929
5030
arch/hexagon/include/asm/syscall.h+1−3
@@ -37,10 +37,8 @@ static inline long syscall_get_nr(struct task_struct *task, · 36 unmodified lines
3737
3838 static inline void syscall_get_arguments(struct task_struct *task,
3939 struct pt_regs *regs,
40− unsigned int i, unsigned int n,
4140 unsigned long *args)
4241 {
43− BUG_ON(i + n > 6);
44− memcpy(args, &(&regs->r00)[i], n * sizeof(args[0]));
42+ memcpy(args, &(&regs->r00)[0], 6 * sizeof(args[0]));
4543 }
4644 #endif
arch/ia64/include/asm/syscall.h+3−10
@@ -59,26 +59,19 @@ static inline void syscall_set_return_value(struct task_struct *task, · 58 unmodified lines
5959 }
6060
6161 extern void ia64_syscall_get_set_arguments(struct task_struct *task,
62− struct pt_regs *regs, unsigned int i, unsigned int n,
63− unsigned long *args, int rw);
62+ struct pt_regs *regs, unsigned long *args, int rw);
6463 static inline void syscall_get_arguments(struct task_struct *task,
6564 struct pt_regs *regs,
66− unsigned int i, unsigned int n,
6765 unsigned long *args)
6866 {
69− BUG_ON(i + n > 6);
70−
71− ia64_syscall_get_set_arguments(task, regs, i, n, args, 0);
67+ ia64_syscall_get_set_arguments(task, regs, args, 0);
7268 }
7369
7470 static inline void syscall_set_arguments(struct task_struct *task,
7571 struct pt_regs *regs,
76− unsigned int i, unsigned int n,
7772 unsigned long *args)
7873 {
79− BUG_ON(i + n > 6);
80−
81− ia64_syscall_get_set_arguments(task, regs, i, n, args, 1);
74+ ia64_syscall_get_set_arguments(task, regs, args, 1);
8275 }
8376
8477 static inline int syscall_get_arch(void)
arch/ia64/kernel/ptrace.c+3−4
@@ -2179,12 +2179,11 @@ static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) · 2178 unmodified lines
21792179 }
21802180
21812181 void ia64_syscall_get_set_arguments(struct task_struct *task,
2182− struct pt_regs *regs, unsigned int i, unsigned int n,
2183− unsigned long *args, int rw)
2182+ struct pt_regs *regs, unsigned long *args, int rw)
21842183 {
21852184 struct syscall_get_set_args data = {
2186− .i = i,
2187− .n = n,
2185+ .i = 0,
2186+ .n = 6,
21882187 .args = args,
21892188 .regs = regs,
21902189 .rw = rw,
arch/microblaze/include/asm/syscall.h+6−2
@@ -82,18 +82,22 @@ static inline void microblaze_set_syscall_arg(struct pt_regs *regs, · 81 unmodified lines
8282
8383 static inline void syscall_get_arguments(struct task_struct *task,
8484 struct pt_regs *regs,
85− unsigned int i, unsigned int n,
8685 unsigned long *args)
8786 {
87+ unsigned int i = 0;
88+ unsigned int n = 6;
89+
8890 while (n--)
8991 *args++ = microblaze_get_syscall_arg(regs, i++);
9092 }
9193
9294 static inline void syscall_set_arguments(struct task_struct *task,
9395 struct pt_regs *regs,
94− unsigned int i, unsigned int n,
9596 const unsigned long *args)
9697 {
98+ unsigned int i = 0;
99+ unsigned int n = 6;
100+
97101 while (n--)
98102 microblaze_set_syscall_arg(regs, i++, *args++);
99103 }
arch/mips/include/asm/syscall.h+2−1
@@ -116,9 +116,10 @@ static inline void syscall_set_return_value(struct task_struct *task, · 115 unmodified lines
116116
117117 static inline void syscall_get_arguments(struct task_struct *task,
118118 struct pt_regs *regs,
119− unsigned int i, unsigned int n,
120119 unsigned long *args)
121120 {
121+ unsigned int i = 0;
122+ unsigned int n = 6;
122123 int ret;
123124
124125 /* O32 ABI syscall() */
arch/mips/kernel/ptrace.c+1−1
@@ -1419,7 +1419,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall) · 1418 unmodified lines
14191419
14201420 sd.nr = syscall;
14211421 sd.arch = syscall_get_arch();
1422− syscall_get_arguments(current, regs, 0, 6, args);
1422+ syscall_get_arguments(current, regs, args);
14231423 for (i = 0; i < 6; i++)
14241424 sd.args[i] = args[i];
14251425 sd.instruction_pointer = KSTK_EIP(current);
arch/nds32/include/asm/syscall.h+11−51
@@ -108,81 +108,41 @@ void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, · 107 unmodified lines
108108 * syscall_get_arguments - extract system call parameter values
109109 * @task: task of interest, must be blocked
110110 * @regs: task_pt_regs() of @task
111− * @i: argument index [0,5]
112− * @n: number of arguments; n+i must be [1,6].
113111 * @args: array filled with argument values
114112 *
115− * Fetches @n arguments to the system call starting with the @i'th argument
116− * (from 0 through 5). Argument @i is stored in @args[0], and so on.
117− * An arch inline version is probably optimal when @i and @n are constants.
113+ * Fetches 6 arguments to the system call (from 0 through 5). The first
114+ * argument is stored in @args[0], and so on.
118115 *
119116 * It's only valid to call this when @task is stopped for tracing on
120117 * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
121− * It's invalid to call this with @i + @n > 6; we only support system calls
122− * taking up to 6 arguments.
123118 */
124119 #define SYSCALL_MAX_ARGS 6
125120 void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
126− unsigned int i, unsigned int n, unsigned long *args)
121+ unsigned long *args)
127122 {
128− if (n == 0)
129− return;
130− if (i + n > SYSCALL_MAX_ARGS) {
131− unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
132− unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
133− pr_warning("%s called with max args %d, handling only %d\n",
134− __func__, i + n, SYSCALL_MAX_ARGS);
135− memset(args_bad, 0, n_bad * sizeof(args[0]));
136− memset(args_bad, 0, n_bad * sizeof(args[0]));
137− }
138−
139− if (i == 0) {
140− args[0] = regs->orig_r0;
141− args++;
142− i++;
143− n--;
144− }
145−
146− memcpy(args, &regs->uregs[0] + i, n * sizeof(args[0]));
123+ args[0] = regs->orig_r0;
124+ args++;
125+ memcpy(args, &regs->uregs[0] + 1, 5 * sizeof(args[0]));
147126 }
148127
149128 /**
150129 * syscall_set_arguments - change system call parameter value
151130 * @task: task of interest, must be in system call entry tracing
152131 * @regs: task_pt_regs() of @task
153− * @i: argument index [0,5]
154− * @n: number of arguments; n+i must be [1,6].
155132 * @args: array of argument values to store
156133 *
157− * Changes @n arguments to the system call starting with the @i'th argument.
158− * Argument @i gets value @args[0], and so on.
159− * An arch inline version is probably optimal when @i and @n are constants.
134+ * Changes 6 arguments to the system call. The first argument gets value
135+ * @args[0], and so on.
160136 *
161137 * It's only valid to call this when @task is stopped for tracing on
162138 * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
163− * It's invalid to call this with @i + @n > 6; we only support system calls
164− * taking up to 6 arguments.
165139 */
166140 void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
167− unsigned int i, unsigned int n,
168141 const unsigned long *args)
169142 {
170− if (n == 0)
171− return;
172−
173− if (i + n > SYSCALL_MAX_ARGS) {
174− pr_warn("%s called with max args %d, handling only %d\n",
175− __func__, i + n, SYSCALL_MAX_ARGS);
176− n = SYSCALL_MAX_ARGS - i;
177− }
178−
179− if (i == 0) {
180− regs->orig_r0 = args[0];
181− args++;
182− i++;
183− n--;
184− }
143+ regs->orig_r0 = args[0];
144+ args++;
185145
186− memcpy(&regs->uregs[0] + i, args, n * sizeof(args[0]));
146+ memcpy(&regs->uregs[0] + 1, args, 5 * sizeof(args[0]));
187147 }
188148 #endif /* _ASM_NDS32_SYSCALL_H */
arch/nios2/include/asm/syscall.h+14−70
@@ -58,81 +58,25 @@ static inline void syscall_set_return_value(struct task_struct *task, · 57 unmodified lines
5858 }
5959
6060 static inline void syscall_get_arguments(struct task_struct *task,
61− struct pt_regs *regs, unsigned int i, unsigned int n,
62− unsigned long *args)
61+ struct pt_regs *regs, unsigned long *args)
6362 {
64− BUG_ON(i + n > 6);
65−
66− switch (i) {
67− case 0:
68− if (!n--)
69− break;
70− *args++ = regs->r4;
71− case 1:
72− if (!n--)
73− break;
74− *args++ = regs->r5;
75− case 2:
76− if (!n--)
77− break;
78− *args++ = regs->r6;
79− case 3:
80− if (!n--)
81− break;
82− *args++ = regs->r7;
83− case 4:
84− if (!n--)
85− break;
86− *args++ = regs->r8;
87− case 5:
88− if (!n--)
89− break;
90− *args++ = regs->r9;
91− case 6:
92− if (!n--)
93− break;
94− default:
95− BUG();
96− }
63+ *args++ = regs->r4;
64+ *args++ = regs->r5;
65+ *args++ = regs->r6;
66+ *args++ = regs->r7;
67+ *args++ = regs->r8;
68+ *args = regs->r9;
9769 }
9870
9971 static inline void syscall_set_arguments(struct task_struct *task,
100− struct pt_regs *regs, unsigned int i, unsigned int n,
101− const unsigned long *args)
72+ struct pt_regs *regs, const unsigned long *args)
10273 {
103− BUG_ON(i + n > 6);
104−
105− switch (i) {
106− case 0:
107− if (!n--)
108− break;
109− regs->r4 = *args++;
110− case 1:
111− if (!n--)
112− break;
113− regs->r5 = *args++;
114− case 2:
115− if (!n--)
116− break;
117− regs->r6 = *args++;
118− case 3:
119− if (!n--)
120− break;
121− regs->r7 = *args++;
122− case 4:
123− if (!n--)
124− break;
125− regs->r8 = *args++;
126− case 5:
127− if (!n--)
128− break;
129− regs->r9 = *args++;
130− case 6:
131− if (!n)
132− break;
133− default:
134− BUG();
135− }
74+ regs->r4 = *args++;
75+ regs->r5 = *args++;
76+ regs->r6 = *args++;
77+ regs->r7 = *args++;
78+ regs->r8 = *args++;
79+ regs->r9 = *args;
13680 }
13781
13882 #endif
arch/openrisc/include/asm/syscall.h+4−8
@@ -56,20 +56,16 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, · 55 unmodified lines
5656
5757 static inline void
5858 syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
59− unsigned int i, unsigned int n, unsigned long *args)
59+ unsigned long *args)
6060 {
61− BUG_ON(i + n > 6);
62−
63− memcpy(args, &regs->gpr[3 + i], n * sizeof(args[0]));
61+ memcpy(args, &regs->gpr[3], 6 * sizeof(args[0]));
6462 }
6563
6664 static inline void
6765 syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
68− unsigned int i, unsigned int n, const unsigned long *args)
66+ const unsigned long *args)
6967 {
70− BUG_ON(i + n > 6);
71−
72− memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
68+ memcpy(&regs->gpr[3], args, 6 * sizeof(args[0]));
7369 }
7470
7571 static inline int syscall_get_arch(void)
arch/parisc/include/asm/syscall.h+8−22
@@ -18,29 +18,15 @@ static inline long syscall_get_nr(struct task_struct *tsk, · 17 unmodified lines
1818 }
1919
2020 static inline void syscall_get_arguments(struct task_struct *tsk,
21− struct pt_regs *regs, unsigned int i,
22− unsigned int n, unsigned long *args)
21+ struct pt_regs *regs,
22+ unsigned long *args)
2323 {
24− BUG_ON(i);
25−
26− switch (n) {
27− case 6:
28− args[5] = regs->gr[21];
29− case 5:
30− args[4] = regs->gr[22];
31− case 4:
32− args[3] = regs->gr[23];
33− case 3:
34− args[2] = regs->gr[24];
35− case 2:
36− args[1] = regs->gr[25];
37− case 1:
38− args[0] = regs->gr[26];
39− case 0:
40− break;
41− default:
42− BUG();
43− }
24+ args[5] = regs->gr[21];
25+ args[4] = regs->gr[22];
26+ args[3] = regs->gr[23];
27+ args[2] = regs->gr[24];
28+ args[1] = regs->gr[25];
29+ args[0] = regs->gr[26];
4430 }
4531
4632 static inline long syscall_get_return_value(struct task_struct *task,
arch/powerpc/include/asm/syscall.h+5−10
@@ -65,22 +65,20 @@ static inline void syscall_set_return_value(struct task_struct *task, · 64 unmodified lines
6565
6666 static inline void syscall_get_arguments(struct task_struct *task,
6767 struct pt_regs *regs,
68− unsigned int i, unsigned int n,
6968 unsigned long *args)
7069 {
7170 unsigned long val, mask = -1UL;
72−
73− BUG_ON(i + n > 6);
71+ unsigned int n = 6;
7472
7573 #ifdef CONFIG_COMPAT
7674 if (test_tsk_thread_flag(task, TIF_32BIT))
7775 mask = 0xffffffff;
7876 #endif
7977 while (n--) {
80− if (n == 0 && i == 0)
78+ if (n == 0)
8179 val = regs->orig_gpr3;
8280 else
83− val = regs->gpr[3 + i + n];
81+ val = regs->gpr[3 + n];
8482
8583 args[n] = val & mask;
8684 }
@@ -88,15 +86,12 @@ static inline void syscall_get_arguments(struct task_struct *task, · 1 unmodified line
8886
8987 static inline void syscall_set_arguments(struct task_struct *task,
9088 struct pt_regs *regs,
91− unsigned int i, unsigned int n,
9289 const unsigned long *args)
9390 {
94− BUG_ON(i + n > 6);
95− memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
91+ memcpy(&regs->gpr[3], args, 6 * sizeof(args[0]));
9692
9793 /* Also copy the first argument into orig_gpr3 */
98− if (i == 0 && n > 0)
99− regs->orig_gpr3 = args[0];
94+ regs->orig_gpr3 = args[0];
10095 }
10196
10297 static inline int syscall_get_arch(void)
arch/riscv/include/asm/syscall.h+6−18
@@ -72,32 +72,20 @@ static inline void syscall_set_return_value(struct task_struct *task, · 71 unmodified lines
7272
7373 static inline void syscall_get_arguments(struct task_struct *task,
7474 struct pt_regs *regs,
75− unsigned int i, unsigned int n,
7675 unsigned long *args)
7776 {
78− BUG_ON(i + n > 6);
79− if (i == 0) {
80− args[0] = regs->orig_a0;
81− args++;
82− i++;
83− n--;
84− }
85− memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
77+ args[0] = regs->orig_a0;
78+ args++;
79+ memcpy(args, &regs->a1, 5 * sizeof(args[0]));
8680 }
8781
8882 static inline void syscall_set_arguments(struct task_struct *task,
8983 struct pt_regs *regs,
90− unsigned int i, unsigned int n,
9184 const unsigned long *args)
9285 {
93− BUG_ON(i + n > 6);
94− if (i == 0) {
95− regs->orig_a0 = args[0];
96− args++;
97− i++;
98− n--;
99− }
100− memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
86+ regs->orig_a0 = args[0];
87+ args++;
88+ memcpy(&regs->a1, args, 5 * sizeof(regs->a1));
10189 }
10290
10391 static inline int syscall_get_arch(void)
arch/s390/include/asm/syscall.h+10−18
@@ -56,40 +56,32 @@ static inline void syscall_set_return_value(struct task_struct *task, · 55 unmodified lines
5656
5757 static inline void syscall_get_arguments(struct task_struct *task,
5858 struct pt_regs *regs,
59− unsigned int i, unsigned int n,
6059 unsigned long *args)
6160 {
6261 unsigned long mask = -1UL;
62+ unsigned int n = 6;
6363
64− /*
65− * No arguments for this syscall, there's nothing to do.
66− */
67− if (!n)
68− return;
69−
70− BUG_ON(i + n > 6);
7164 #ifdef CONFIG_COMPAT
7265 if (test_tsk_thread_flag(task, TIF_31BIT))
7366 mask = 0xffffffff;
7467 #endif
7568 while (n-- > 0)
76− if (i + n > 0)
77− args[n] = regs->gprs[2 + i + n] & mask;
78− if (i == 0)
79− args[0] = regs->orig_gpr2 & mask;
69+ if (n > 0)
70+ args[n] = regs->gprs[2 + n] & mask;
71+
72+ args[0] = regs->orig_gpr2 & mask;
8073 }
8174
8275 static inline void syscall_set_arguments(struct task_struct *task,
8376 struct pt_regs *regs,
84− unsigned int i, unsigned int n,
8577 const unsigned long *args)
8678 {
87− BUG_ON(i + n > 6);
79+ unsigned int n = 6;
80+
8881 while (n-- > 0)
89− if (i + n > 0)
90− regs->gprs[2 + i + n] = args[n];
91− if (i == 0)
92− regs->orig_gpr2 = args[0];
82+ if (n > 0)
83+ regs->gprs[2 + n] = args[n];
84+ regs->orig_gpr2 = args[0];
9385 }
9486
9587 static inline int syscall_get_arch(void)
arch/sh/include/asm/syscall_32.h+12−35
@@ -48,51 +48,28 @@ static inline void syscall_set_return_value(struct task_struct *task, · 47 unmodified lines
4848
4949 static inline void syscall_get_arguments(struct task_struct *task,
5050 struct pt_regs *regs,
51− unsigned int i, unsigned int n,
5251 unsigned long *args)
5352 {
54− /*
55− * Do this simply for now. If we need to start supporting
56− * fetching arguments from arbitrary indices, this will need some
57− * extra logic. Presently there are no in-tree users that depend
58− * on this behaviour.
59− */
60− BUG_ON(i);
6153
6254 /* Argument pattern is: R4, R5, R6, R7, R0, R1 */
63− switch (n) {
64− case 6: args[5] = regs->regs[1];
65− case 5: args[4] = regs->regs[0];
66− case 4: args[3] = regs->regs[7];
67− case 3: args[2] = regs->regs[6];
68− case 2: args[1] = regs->regs[5];
69− case 1: args[0] = regs->regs[4];
70− case 0:
71− break;
72− default:
73− BUG();
74− }
55+ args[5] = regs->regs[1];
56+ args[4] = regs->regs[0];
57+ args[3] = regs->regs[7];
58+ args[2] = regs->regs[6];
59+ args[1] = regs->regs[5];
60+ args[0] = regs->regs[4];
7561 }
7662
7763 static inline void syscall_set_arguments(struct task_struct *task,
7864 struct pt_regs *regs,
79− unsigned int i, unsigned int n,
8065 const unsigned long *args)
8166 {
82− /* Same note as above applies */
83− BUG_ON(i);
84−
85− switch (n) {
86− case 6: regs->regs[1] = args[5];
87− case 5: regs->regs[0] = args[4];
88− case 4: regs->regs[7] = args[3];
89− case 3: regs->regs[6] = args[2];
90− case 2: regs->regs[5] = args[1];
91− case 1: regs->regs[4] = args[0];
92− break;
93− default:
94− BUG();
95− }
67+ regs->regs[1] = args[5];
68+ regs->regs[0] = args[4];
69+ regs->regs[7] = args[3];
70+ regs->regs[6] = args[2];
71+ regs->regs[5] = args[1];
72+ regs->regs[4] = args[0];
9673 }
9774
9875 static inline int syscall_get_arch(void)
arch/sh/include/asm/syscall_64.h+2−6
@@ -47,20 +47,16 @@ static inline void syscall_set_return_value(struct task_struct *task, · 46 unmodified lines
4747
4848 static inline void syscall_get_arguments(struct task_struct *task,
4949 struct pt_regs *regs,
50− unsigned int i, unsigned int n,
5150 unsigned long *args)
5251 {
53− BUG_ON(i + n > 6);
54− memcpy(args, &regs->regs[2 + i], n * sizeof(args[0]));
52+ memcpy(args, &regs->regs[2], 6 * sizeof(args[0]));
5553 }
5654
5755 static inline void syscall_set_arguments(struct task_struct *task,
5856 struct pt_regs *regs,
59− unsigned int i, unsigned int n,
6057 const unsigned long *args)
6158 {
62− BUG_ON(i + n > 6);
63− memcpy(&regs->regs[2 + i], args, n * sizeof(args[0]));
59+ memcpy(&regs->regs[2], args, 6 * sizeof(args[0]));
6460 }
6561
6662 static inline int syscall_get_arch(void)
arch/sparc/include/asm/syscall.h+5−6
@@ -96,11 +96,11 @@ static inline void syscall_set_return_value(struct task_struct *task, · 95 unmodified lines
9696
9797 static inline void syscall_get_arguments(struct task_struct *task,
9898 struct pt_regs *regs,
99− unsigned int i, unsigned int n,
10099 unsigned long *args)
101100 {
102101 int zero_extend = 0;
103102 unsigned int j;
103+ unsigned int n = 6;
104104
105105 #ifdef CONFIG_SPARC64
106106 if (test_tsk_thread_flag(task, TIF_32BIT))
@@ -108,7 +108,7 @@ static inline void syscall_get_arguments(struct task_struct *task, · 1 unmodified line
108108 #endif
109109
110110 for (j = 0; j < n; j++) {
111− unsigned long val = regs->u_regs[UREG_I0 + i + j];
111+ unsigned long val = regs->u_regs[UREG_I0 + j];
112112
113113 if (zero_extend)
114114 args[j] = (u32) val;
@@ -119,13 +119,12 @@ static inline void syscall_get_arguments(struct task_struct *task, · 4 unmodified lines
119119
120120 static inline void syscall_set_arguments(struct task_struct *task,
121121 struct pt_regs *regs,
122− unsigned int i, unsigned int n,
123122 const unsigned long *args)
124123 {
125− unsigned int j;
124+ unsigned int i;
126125
127− for (j = 0; j < n; j++)
128− regs->u_regs[UREG_I0 + i + j] = args[j];
126+ for (i = 0; i < 6; i++)
127+ regs->u_regs[UREG_I0 + i] = args[i];
129128 }
130129
131130 static inline int syscall_get_arch(void)
arch/um/include/asm/syscall-generic.h+12−66
@@ -53,84 +53,30 @@ static inline void syscall_set_return_value(struct task_struct *task, · 52 unmodified lines
5353
5454 static inline void syscall_get_arguments(struct task_struct *task,
5555 struct pt_regs *regs,
56− unsigned int i, unsigned int n,
5756 unsigned long *args)
5857 {
5958 const struct uml_pt_regs *r = &regs->regs;
6059
61− switch (i) {
62− case 0:
63− if (!n--)
64− break;
65− *args++ = UPT_SYSCALL_ARG1(r);
66− case 1:
67− if (!n--)
68− break;
69− *args++ = UPT_SYSCALL_ARG2(r);
70− case 2:
71− if (!n--)
72− break;
73− *args++ = UPT_SYSCALL_ARG3(r);
74− case 3:
75− if (!n--)
76− break;
77− *args++ = UPT_SYSCALL_ARG4(r);
78− case 4:
79− if (!n--)
80− break;
81− *args++ = UPT_SYSCALL_ARG5(r);
82− case 5:
83− if (!n--)
84− break;
85− *args++ = UPT_SYSCALL_ARG6(r);
86− case 6:
87− if (!n--)
88− break;
89− default:
90− BUG();
91− break;
92− }
60+ *args++ = UPT_SYSCALL_ARG1(r);
61+ *args++ = UPT_SYSCALL_ARG2(r);
62+ *args++ = UPT_SYSCALL_ARG3(r);
63+ *args++ = UPT_SYSCALL_ARG4(r);
64+ *args++ = UPT_SYSCALL_ARG5(r);
65+ *args = UPT_SYSCALL_ARG6(r);
9366 }
9467
9568 static inline void syscall_set_arguments(struct task_struct *task,
9669 struct pt_regs *regs,
97− unsigned int i, unsigned int n,
9870 const unsigned long *args)
9971 {
10072 struct uml_pt_regs *r = &regs->regs;
10173
102− switch (i) {
103− case 0:
104− if (!n--)
105− break;
106− UPT_SYSCALL_ARG1(r) = *args++;
107− case 1:
108− if (!n--)
109− break;
110− UPT_SYSCALL_ARG2(r) = *args++;
111− case 2:
112− if (!n--)
113− break;
114− UPT_SYSCALL_ARG3(r) = *args++;
115− case 3:
116− if (!n--)
117− break;
118− UPT_SYSCALL_ARG4(r) = *args++;
119− case 4:
120− if (!n--)
121− break;
122− UPT_SYSCALL_ARG5(r) = *args++;
123− case 5:
124− if (!n--)
125− break;
126− UPT_SYSCALL_ARG6(r) = *args++;
127− case 6:
128− if (!n--)
129− break;
130− default:
131− BUG();
132− break;
133− }
74+ UPT_SYSCALL_ARG1(r) = *args++;
75+ UPT_SYSCALL_ARG2(r) = *args++;
76+ UPT_SYSCALL_ARG3(r) = *args++;
77+ UPT_SYSCALL_ARG4(r) = *args++;
78+ UPT_SYSCALL_ARG5(r) = *args++;
79+ UPT_SYSCALL_ARG6(r) = *args;
13480 }
13581
13682 /* See arch/x86/um/asm/syscall.h for syscall_get_arch() definition. */
arch/x86/include/asm/syscall.h+33−109
@@ -91,11 +91,9 @@ static inline void syscall_set_return_value(struct task_struct *task, · 90 unmodified lines
9191
9292 static inline void syscall_get_arguments(struct task_struct *task,
9393 struct pt_regs *regs,
94− unsigned int i, unsigned int n,
9594 unsigned long *args)
9695 {
97− BUG_ON(i + n > 6);
98− memcpy(args, &regs->bx + i, n * sizeof(args[0]));
96+ memcpy(args, &regs->bx, 6 * sizeof(args[0]));
9997 }
10098
10199 static inline void syscall_set_arguments(struct task_struct *task,
@@ -116,124 +114,50 @@ static inline int syscall_get_arch(void) · 14 unmodified lines
116114
117115 static inline void syscall_get_arguments(struct task_struct *task,
118116 struct pt_regs *regs,
119− unsigned int i, unsigned int n,
120117 unsigned long *args)
121118 {
122119 # ifdef CONFIG_IA32_EMULATION
123− if (task->thread_info.status & TS_COMPAT)
124− switch (i) {
125− case 0:
126− if (!n--) break;
127− *args++ = regs->bx;
128− case 1:
129− if (!n--) break;
130− *args++ = regs->cx;
131− case 2:
132− if (!n--) break;
133− *args++ = regs->dx;
134− case 3:
135− if (!n--) break;
136− *args++ = regs->si;
137− case 4:
138− if (!n--) break;
139− *args++ = regs->di;
140− case 5:
141− if (!n--) break;
142− *args++ = regs->bp;
143− case 6:
144− if (!n--) break;
145− default:
146− BUG();
147− break;
148− }
149− else
120+ if (task->thread_info.status & TS_COMPAT) {
121+ *args++ = regs->bx;
122+ *args++ = regs->cx;
123+ *args++ = regs->dx;
124+ *args++ = regs->si;
125+ *args++ = regs->di;
126+ *args = regs->bp;
127+ } else
150128 # endif
151− switch (i) {
152− case 0:
153− if (!n--) break;
154− *args++ = regs->di;
155− case 1:
156− if (!n--) break;
157− *args++ = regs->si;
158− case 2:
159− if (!n--) break;
160− *args++ = regs->dx;
161− case 3:
162− if (!n--) break;
163− *args++ = regs->r10;
164− case 4:
165− if (!n--) break;
166− *args++ = regs->r8;
167− case 5:
168− if (!n--) break;
169− *args++ = regs->r9;
170− case 6:
171− if (!n--) break;
172− default:
173− BUG();
174− break;
175− }
129+ {
130+ *args++ = regs->di;
131+ *args++ = regs->si;
132+ *args++ = regs->dx;
133+ *args++ = regs->r10;
134+ *args++ = regs->r8;
135+ *args = regs->r9;
136+ }
176137 }
177138
178139 static inline void syscall_set_arguments(struct task_struct *task,
179140 struct pt_regs *regs,
180− unsigned int i, unsigned int n,
181141 const unsigned long *args)
182142 {
183143 # ifdef CONFIG_IA32_EMULATION
184− if (task->thread_info.status & TS_COMPAT)
185− switch (i) {
186− case 0:
187− if (!n--) break;
188− regs->bx = *args++;
189− case 1:
190− if (!n--) break;
191− regs->cx = *args++;
192− case 2:
193− if (!n--) break;
194− regs->dx = *args++;
195− case 3:
196− if (!n--) break;
197− regs->si = *args++;
198− case 4:
199− if (!n--) break;
200− regs->di = *args++;
201− case 5:
202− if (!n--) break;
203− regs->bp = *args++;
204− case 6:
205− if (!n--) break;
206− default:
207− BUG();
208− break;
209− }
210− else
144+ if (task->thread_info.status & TS_COMPAT) {
145+ regs->bx = *args++;
146+ regs->cx = *args++;
147+ regs->dx = *args++;
148+ regs->si = *args++;
149+ regs->di = *args++;
150+ regs->bp = *args;
151+ } else
211152 # endif
212− switch (i) {
213− case 0:
214− if (!n--) break;
215− regs->di = *args++;
216− case 1:
217− if (!n--) break;
218− regs->si = *args++;
219− case 2:
220− if (!n--) break;
221− regs->dx = *args++;
222− case 3:
223− if (!n--) break;
224− regs->r10 = *args++;
225− case 4:
226− if (!n--) break;
227− regs->r8 = *args++;
228− case 5:
229− if (!n--) break;
230− regs->r9 = *args++;
231− case 6:
232− if (!n--) break;
233− default:
234− BUG();
235− break;
236− }
153+ {
154+ regs->di = *args++;
155+ regs->si = *args++;
156+ regs->dx = *args++;
157+ regs->r10 = *args++;
158+ regs->r8 = *args++;
159+ regs->r9 = *args;
160+ }
237161 }
238162
239163 static inline int syscall_get_arch(void)
arch/xtensa/include/asm/syscall.h+6−27
@@ -59,45 +59,24 @@ static inline void syscall_set_return_value(struct task_struct *task, · 58 unmodified lines
5959
6060 static inline void syscall_get_arguments(struct task_struct *task,
6161 struct pt_regs *regs,
62− unsigned int i, unsigned int n,
6362 unsigned long *args)
6463 {
6564 static const unsigned int reg[] = XTENSA_SYSCALL_ARGUMENT_REGS;
66− unsigned int j;
65+ unsigned int i;
6766
68− if (n == 0)
69− return;
70−
71− WARN_ON_ONCE(i + n > SYSCALL_MAX_ARGS);
72−
73− for (j = 0; j < n; ++j) {
74− if (i + j < SYSCALL_MAX_ARGS)
75− args[j] = regs->areg[reg[i + j]];
76− else
77− args[j] = 0;
78− }
67+ for (i = 0; i < 6; ++i)
68+ args[i] = regs->areg[reg[i]];
7969 }
8070
8171 static inline void syscall_set_arguments(struct task_struct *task,
8272 struct pt_regs *regs,
83− unsigned int i, unsigned int n,
8473 const unsigned long *args)
8574 {
8675 static const unsigned int reg[] = XTENSA_SYSCALL_ARGUMENT_REGS;
87− unsigned int j;
88−
89− if (n == 0)
90− return;
91−
92− if (WARN_ON_ONCE(i + n > SYSCALL_MAX_ARGS)) {
93− if (i < SYSCALL_MAX_ARGS)
94− n = SYSCALL_MAX_ARGS - i;
95− else
96− return;
97− }
76+ unsigned int i;
9877
99− for (j = 0; j < n; ++j)
100− regs->areg[reg[i + j]] = args[j];
78+ for (i = 0; i < 6; ++i)
79+ regs->areg[reg[i]] = args[i];
10180 }
10281
10382 asmlinkage long xtensa_rt_sigreturn(struct pt_regs*);
fs/proc/base.c+9−8
@@ -616,24 +616,25 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns, · 615 unmodified lines
616616 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
617617 struct pid *pid, struct task_struct *task)
618618 {
619− long nr;
620− unsigned long args[6], sp, pc;
619+ struct syscall_info info;
620+ u64 *args = &info.data.args[0];
621621 int res;
622622
623623 res = lock_trace(task);
624624 if (res)
625625 return res;
626626
627− if (task_current_syscall(task, &nr, args, 6, &sp, &pc))
627+ if (task_current_syscall(task, &info))
628628 seq_puts(m, "running\n");
629− else if (nr < 0)
630− seq_printf(m, "%ld 0x%lx 0x%lx\n", nr, sp, pc);
629+ else if (info.data.nr < 0)
630+ seq_printf(m, "%d 0x%llx 0x%llx\n",
631+ info.data.nr, info.sp, info.data.instruction_pointer);
631632 else
632633 seq_printf(m,
633− "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
634− nr,
634+ "%d 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx\n",
635+ info.data.nr,
635636 args[0], args[1], args[2], args[3], args[4], args[5],
636− sp, pc);
637+ info.sp, info.data.instruction_pointer);
637638 unlock_trace(task);
638639
639640 return 0;
include/asm-generic/syscall.h+5−16
@@ -105,41 +105,30 @@ void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs, · 104 unmodified lines
105105 * syscall_get_arguments - extract system call parameter values
106106 * @task: task of interest, must be blocked
107107 * @regs: task_pt_regs() of @task
108− * @i: argument index [0,5]
109− * @n: number of arguments; n+i must be [1,6].
110108 * @args: array filled with argument values
111109 *
112− * Fetches @n arguments to the system call starting with the @i'th argument
113− * (from 0 through 5). Argument @i is stored in @args[0], and so on.
114− * An arch inline version is probably optimal when @i and @n are constants.
110+ * Fetches 6 arguments to the system call. First argument is stored in
111+* @args[0], and so on.
115112 *
116113 * It's only valid to call this when @task is stopped for tracing on
117114 * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
118− * It's invalid to call this with @i + @n > 6; we only support system calls
119− * taking up to 6 arguments.
120115 */
121116 void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
122− unsigned int i, unsigned int n, unsigned long *args);
117+ unsigned long *args);
123118
124119 /**
125120 * syscall_set_arguments - change system call parameter value
126121 * @task: task of interest, must be in system call entry tracing
127122 * @regs: task_pt_regs() of @task
128− * @i: argument index [0,5]
129− * @n: number of arguments; n+i must be [1,6].
130123 * @args: array of argument values to store
131124 *
132− * Changes @n arguments to the system call starting with the @i'th argument.
133− * Argument @i gets value @args[0], and so on.
134− * An arch inline version is probably optimal when @i and @n are constants.
125+ * Changes 6 arguments to the system call.
126+ * The first argument gets value @args[0], and so on.
135127 *
136128 * It's only valid to call this when @task is stopped for tracing on
137129 * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
138− * It's invalid to call this with @i + @n > 6; we only support system calls
139− * taking up to 6 arguments.
140130 */
141131 void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
142− unsigned int i, unsigned int n,
143132 const unsigned long *args);
144133
145134 /**
include/linux/ptrace.h+8−3
@@ -9,6 +9,13 @@ · 8 unmodified lines
99 #include <linux/bug.h> /* For BUG_ON. */
1010 #include <linux/pid_namespace.h> /* For task_active_pid_ns. */
1111 #include <uapi/linux/ptrace.h>
12+#include <linux/seccomp.h>
13+
14+/* Add sp to seccomp_data, as seccomp is user API, we don't want to modify it */
15+struct syscall_info {
16+ __u64 sp;
17+ struct seccomp_data data;
18+};
1219
1320 extern int ptrace_access_vm(struct task_struct *tsk, unsigned long addr,
1421 void *buf, int len, unsigned int gup_flags);
@@ -407,9 +414,7 @@ static inline void user_single_step_report(struct pt_regs *regs) · 392 unmodified lines
407414 #define current_user_stack_pointer() user_stack_pointer(current_pt_regs())
408415 #endif
409416
410−extern int task_current_syscall(struct task_struct *target, long *callno,
411− unsigned long args[6], unsigned int maxargs,
412− unsigned long *sp, unsigned long *pc);
417+extern int task_current_syscall(struct task_struct *target, struct syscall_info *info);
413418
414419 extern void sigaction_compat_abi(struct k_sigaction *act, struct k_sigaction *oact);
415420 #endif
include/trace/events/syscalls.h+1−1
@@ -28,7 +28,7 @@ TRACE_EVENT_FN(sys_enter, · 27 unmodified lines
2828
2929 TP_fast_assign(
3030 __entry->id = id;
31− syscall_get_arguments(current, regs, 0, 6, __entry->args);
31+ syscall_get_arguments(current, regs, __entry->args);
3232 ),
3333
3434 TP_printk("NR %ld (%lx, %lx, %lx, %lx, %lx, %lx)",
kernel/seccomp.c+1−1
@@ -149,7 +149,7 @@ static void populate_seccomp_data(struct seccomp_data *sd) · 148 unmodified lines
149149
150150 sd->nr = syscall_get_nr(task, regs);
151151 sd->arch = syscall_get_arch();
152− syscall_get_arguments(task, regs, 0, 6, args);
152+ syscall_get_arguments(task, regs, args);
153153 sd->args[0] = args[0];
154154 sd->args[1] = args[1];
155155 sd->args[2] = args[2];
kernel/trace/trace_syscalls.c+6−3
@@ -314,6 +314,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · 313 unmodified lines
314314 struct ring_buffer_event *event;
315315 struct ring_buffer *buffer;
316316 unsigned long irq_flags;
317+ unsigned long args[6];
317318 int pc;
318319 int syscall_nr;
319320 int size;
@@ -347,7 +348,8 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) · 27 unmodified lines
347348
348349 entry = ring_buffer_event_data(event);
349350 entry->nr = syscall_nr;
350− syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args);
351+ syscall_get_arguments(current, regs, args);
352+ memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args);
351353
352354 event_trigger_unlock_commit(trace_file, buffer, event, entry,
353355 irq_flags, pc);
@@ -583,6 +585,7 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) · 229 unmodified lines
583585 struct syscall_metadata *sys_data;
584586 struct syscall_trace_enter *rec;
585587 struct hlist_head *head;
588+ unsigned long args[6];
586589 bool valid_prog_array;
587590 int syscall_nr;
588591 int rctx;
@@ -613,8 +616,8 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) · 24 unmodified lines
613616 return;
614617
615618 rec->nr = syscall_nr;
616− syscall_get_arguments(current, regs, 0, sys_data->nb_args,
617− (unsigned long *)&rec->args);
619+ syscall_get_arguments(current, regs, args);
620+ memcpy(&rec->args, args, sizeof(unsigned long) * sys_data->nb_args);
618621
619622 if ((valid_prog_array &&
620623 !perf_call_bpf_enter(sys_data->enter_event, regs, sys_data, rec)) ||
lib/syscall.c+25−32
@@ -5,16 +5,14 @@ · 4 unmodified lines
55 #include <linux/export.h>
66 #include <asm/syscall.h>
77
8−static int collect_syscall(struct task_struct *target, long *callno,
9− unsigned long args[6], unsigned int maxargs,
10− unsigned long *sp, unsigned long *pc)
8+static int collect_syscall(struct task_struct *target, struct syscall_info *info)
119 {
1210 struct pt_regs *regs;
1311
1412 if (!try_get_task_stack(target)) {
1513 /* Task has no stack, so the task isn't in a syscall. */
16− *sp = *pc = 0;
17− *callno = -1;
14+ memset(info, 0, sizeof(*info));
15+ info->data.nr = -1;
1816 return 0;
1917 }
2018
@@ -24,12 +22,13 @@ static int collect_syscall(struct task_struct *target, long *callno, · 3 unmodified lines
2422 return -EAGAIN;
2523 }
2624
27− *sp = user_stack_pointer(regs);
28− *pc = instruction_pointer(regs);
25+ info->sp = user_stack_pointer(regs);
26+ info->data.instruction_pointer = instruction_pointer(regs);
2927
30− *callno = syscall_get_nr(target, regs);
31− if (*callno != -1L && maxargs > 0)
32− syscall_get_arguments(target, regs, 0, maxargs, args);
28+ info->data.nr = syscall_get_nr(target, regs);
29+ if (info->data.nr != -1L)
30+ syscall_get_arguments(target, regs,
31+ (unsigned long *)&info->data.args[0]);
3332
3433 put_task_stack(target);
3534 return 0;
@@ -38,41 +37,35 @@ static int collect_syscall(struct task_struct *target, long *callno, · 2 unmodified lines
3837 /**
3938 * task_current_syscall - Discover what a blocked task is doing.
4039 * @target: thread to examine
41− * @callno: filled with system call number or -1
42− * @args: filled with @maxargs system call arguments
43− * @maxargs: number of elements in @args to fill
44− * @sp: filled with user stack pointer
45− * @pc: filled with user PC
40+ * @info: structure with the following fields:
41+ * .sp - filled with user stack pointer
42+ * .data.nr - filled with system call number or -1
43+ * .data.args - filled with @maxargs system call arguments
44+ * .data.instruction_pointer - filled with user PC
4645 *
47− * If @target is blocked in a system call, returns zero with *@callno
48− * set to the the call's number and @args filled in with its arguments.
49− * Registers not used for system call arguments may not be available and
50− * it is not kosher to use &struct user_regset calls while the system
46+ * If @target is blocked in a system call, returns zero with @info.data.nr
47+ * set to the the call's number and @info.data.args filled in with its
48+ * arguments. Registers not used for system call arguments may not be available
49+ * and it is not kosher to use &struct user_regset calls while the system
5150 * call is still in progress. Note we may get this result if @target
5251 * has finished its system call but not yet returned to user mode, such
5352 * as when it's stopped for signal handling or syscall exit tracing.
5453 *
5554 * If @target is blocked in the kernel during a fault or exception,
56− * returns zero with *@callno set to -1 and does not fill in @args.
57− * If so, it's now safe to examine @target using &struct user_regset
58− * get() calls as long as we're sure @target won't return to user mode.
55+ * returns zero with *@info.data.nr set to -1 and does not fill in
56+ * @info.data.args. If so, it's now safe to examine @target using
57+ * &struct user_regset get() calls as long as we're sure @target won't return
58+ * to user mode.
5959 *
6060 * Returns -%EAGAIN if @target does not remain blocked.
61− *
62− * Returns -%EINVAL if @maxargs is too large (maximum is six).
6361 */
64−int task_current_syscall(struct task_struct *target, long *callno,
65− unsigned long args[6], unsigned int maxargs,
66− unsigned long *sp, unsigned long *pc)
62+int task_current_syscall(struct task_struct *target, struct syscall_info *info)
6763 {
6864 long state;
6965 unsigned long ncsw;
7066
71− if (unlikely(maxargs > 6))
72− return -EINVAL;
73−
7467 if (target == current)
75− return collect_syscall(target, callno, args, maxargs, sp, pc);
68+ return collect_syscall(target, info);
7669
7770 state = target->state;
7871 if (unlikely(!state))
@@ -80,7 +73,7 @@ int task_current_syscall(struct task_struct *target, long *callno, · 1 unmodified line
8073
8174 ncsw = wait_task_inactive(target, state);
8275 if (unlikely(!ncsw) ||
83− unlikely(collect_syscall(target, callno, args, maxargs, sp, pc)) ||
76+ unlikely(collect_syscall(target, info)) ||
8477 unlikely(wait_task_inactive(target, state) != ncsw))
8578 return -EAGAIN;
8679

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t