Skip to content

Commit

Permalink
riscv: tracing: Fix __write_overflow_field in ftrace_partial_regs()
Browse files Browse the repository at this point in the history
The size of &regs->a0 is unknown, causing the error:

../include/linux/fortify-string.h:571:25: warning: call to
'__write_overflow_field' declared with attribute warning: detected write
beyond size of field (1st parameter); maybe use struct_group()?
[-Wattribute-warning]

Fix this by wrapping the required registers in pt_regs with
struct_group() and reference the group when doing the offending
memcpy().

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20250224-fix_ftrace_partial_regs-v1-1-54b906417e86@rivosinc.com
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
  • Loading branch information
Charlie Jenkins authored and Alexandre Ghiti committed Mar 18, 2025
1 parent 7277069 commit bba5478
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion arch/riscv/include/asm/ftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs)
{
struct __arch_ftrace_regs *afregs = arch_ftrace_regs(fregs);

memcpy(&regs->a0, afregs->args, sizeof(afregs->args));
memcpy(&regs->a_regs, afregs->args, sizeof(afregs->args));
regs->epc = afregs->epc;
regs->ra = afregs->ra;
regs->sp = afregs->sp;
Expand Down
18 changes: 10 additions & 8 deletions arch/riscv/include/asm/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ struct pt_regs {
unsigned long t2;
unsigned long s0;
unsigned long s1;
unsigned long a0;
unsigned long a1;
unsigned long a2;
unsigned long a3;
unsigned long a4;
unsigned long a5;
unsigned long a6;
unsigned long a7;
struct_group(a_regs,
unsigned long a0;
unsigned long a1;
unsigned long a2;
unsigned long a3;
unsigned long a4;
unsigned long a5;
unsigned long a6;
unsigned long a7;
);
unsigned long s2;
unsigned long s3;
unsigned long s4;
Expand Down

0 comments on commit bba5478

Please sign in to comment.