Skip to content

Commit 1acbeb7

Browse files
nathanchancejfvogel
authored andcommitted
riscv: Avoid fortify warning in syscall_get_arguments()
commit adf53771a3123df99ca26e38818760fbcf5c05d0 upstream. When building with CONFIG_FORTIFY_SOURCE=y and W=1, there is a warning because of the memcpy() in syscall_get_arguments(): In file included from include/linux/string.h:392, from include/linux/bitmap.h:13, from include/linux/cpumask.h:12, from arch/riscv/include/asm/processor.h:55, from include/linux/sched.h:13, from kernel/ptrace.c:13: In function 'fortify_memcpy_chk', inlined from 'syscall_get_arguments.isra' at arch/riscv/include/asm/syscall.h:66:2: include/linux/fortify-string.h:580:25: error: call to '__read_overflow2_field' declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror=attribute-warning] 580 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors The fortified memcpy() routine enforces that the source is not overread and the destination is not overwritten if the size of either field and the size of the copy are known at compile time. The memcpy() in syscall_get_arguments() intentionally overreads from a1 to a5 in 'struct pt_regs' but this is bigger than the size of a1. Normally, this could be solved by wrapping a1 through a5 with struct_group() but there was already a struct_group() applied to these members in commit bba547810c66 ("riscv: tracing: Fix __write_overflow_field in ftrace_partial_regs()"). Just avoid memcpy() altogether and write the copying of args from regs manually, which clears up the warning at the expense of three extra lines of code. Signed-off-by: Nathan Chancellor <[email protected]> Reviewed-by: Dmitry V. Levin <[email protected]> Fixes: e2c0cdf ("RISC-V: User-facing API") Cc: [email protected] Link: https://lore.kernel.org/r/20250409-riscv-avoid-fortify-warning-syscall_get_arguments-v1-1-7853436d4755@kernel.org Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 3f1c81ae13dcfc8bba9c1c1b5d61e429980c3e65) Signed-off-by: Jack Vogel <[email protected]>
1 parent 1ace6fa commit 1acbeb7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/riscv/include/asm/syscall.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ static inline void syscall_get_arguments(struct task_struct *task,
6262
unsigned long *args)
6363
{
6464
args[0] = regs->orig_a0;
65-
args++;
66-
memcpy(args, &regs->a1, 5 * sizeof(args[0]));
65+
args[1] = regs->a1;
66+
args[2] = regs->a2;
67+
args[3] = regs->a3;
68+
args[4] = regs->a4;
69+
args[5] = regs->a5;
6770
}
6871

6972
static inline int syscall_get_arch(struct task_struct *task)

0 commit comments

Comments
 (0)