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

selftests/powerpc: Fix out of bounds access in TM signal test

Gcc helpfully points out that we're accessing past the end of the gprs
array:

tm-signal-msr-resv.c: In function 'signal_usr1':
tm-signal-msr-resv.c:43:37: error: array subscript is above array bounds [-Werror=array-bounds]
ucp->uc_mcontext.regs->gpr[PT_MSR] |= (7ULL);

We haven't noticed previously because -flto was hiding it somehow.

The code is confused, PT_MSR isn't a gpr, instead it's in
uc_regs->gregs, so fix it.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

+1 -1
+1 -1
tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
··· 40 40 #ifdef __powerpc64__ 41 41 ucp->uc_mcontext.gp_regs[PT_MSR] |= (7ULL << 32); 42 42 #else 43 - ucp->uc_mcontext.regs->gpr[PT_MSR] |= (7ULL); 43 + ucp->uc_mcontext.uc_regs->gregs[PT_MSR] |= (7ULL); 44 44 #endif 45 45 /* Should segv on return becuase of invalid context */ 46 46 segv_expected = 1;