linux-brain/arch/powerpc
Michael Ellerman 380960e5a1 powerpc/ptrace: Simplify vr_get/set() to avoid GCC warning
commit ca6d5149d2 upstream.

GCC 8 warns about the logic in vr_get/set(), which with -Werror breaks
the build:

  In function ‘user_regset_copyin’,
      inlined from ‘vr_set’ at arch/powerpc/kernel/ptrace.c:628:9:
  include/linux/regset.h:295:4: error: ‘memcpy’ offset [-527, -529] is
  out of the bounds [0, 16] of object ‘vrsave’ with type ‘union
  <anonymous>’ [-Werror=array-bounds]
  arch/powerpc/kernel/ptrace.c: In function ‘vr_set’:
  arch/powerpc/kernel/ptrace.c:623:5: note: ‘vrsave’ declared here
     } vrsave;

This has been identified as a regression in GCC, see GCC bug 88273.

However we can avoid the warning and also simplify the logic and make
it more robust.

Currently we pass -1 as end_pos to user_regset_copyout(). This says
"copy up to the end of the regset".

The definition of the regset is:
	[REGSET_VMX] = {
		.core_note_type = NT_PPC_VMX, .n = 34,
		.size = sizeof(vector128), .align = sizeof(vector128),
		.active = vr_active, .get = vr_get, .set = vr_set
	},

The end is calculated as (n * size), ie. 34 * sizeof(vector128).

In vr_get/set() we pass start_pos as 33 * sizeof(vector128), meaning
we can copy up to sizeof(vector128) into/out-of vrsave.

The on-stack vrsave is defined as:
  union {
	  elf_vrreg_t reg;
	  u32 word;
  } vrsave;

And elf_vrreg_t is:
  typedef __vector128 elf_vrreg_t;

So there is no bug, but we rely on all those sizes lining up,
otherwise we would have a kernel stack exposure/overwrite on our
hands.

Rather than relying on that we can pass an explict end_pos based on
the sizeof(vrsave). The result should be exactly the same but it's
more obviously not over-reading/writing the stack and it avoids the
compiler warning.

Reported-by: Meelis Roos <mroos@linux.ee>
Reported-by: Mathieu Malaterre <malat@debian.org>
Cc: stable@vger.kernel.org
Tested-by: Mathieu Malaterre <malat@debian.org>
Tested-by: Meelis Roos <mroos@linux.ee>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-23 13:19:52 +01:00
..
boot powerpc: Fix COFF zImage booting on old powermacs 2019-01-13 10:03:47 +01:00
configs Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/scottwood/linux into next 2016-10-11 20:07:56 +11:00
crypto crypto: hash - annotate algorithms taking optional key 2018-02-25 11:05:43 +01:00
include powerpc: Always initialize input array when calling epapr_hypercall() 2019-03-05 17:57:06 +01:00
kernel powerpc/ptrace: Simplify vr_get/set() to avoid GCC warning 2019-03-23 13:19:52 +01:00
kvm KVM: PPC: Move and undef TRACE_INCLUDE_PATH/FILE 2018-12-01 09:44:20 +01:00
lib powerpc/64s: Add support for a store forwarding barrier at kernel entry/exit 2018-06-06 16:44:37 +02:00
math-emu powerpc: Correct emulated mtfsf instruction 2014-04-07 10:33:11 +10:00
mm powerpc/numa: Suppress "VPHN is not supported" messages 2018-12-01 09:44:21 +01:00
net bpf, ppc64: fix unexpected r0=0 exit path inside bpf_xadd 2018-09-05 09:20:00 +02:00
oprofile powerpc/sparse: Make a bunch of things static 2016-09-13 17:35:47 +10:00
perf powerpc/perf: Fix kernel address leak via sampling registers 2018-05-30 07:50:43 +02:00
platforms powerpc/83xx: Also save/restore SPRG4-7 during suspend 2019-03-23 13:19:51 +01:00
scripts powerpc/ftrace: Add Kconfig & Make glue for mprofile-kernel 2016-03-07 14:53:56 +11:00
sysdev powerpc: Fix size calculation using resource_size() 2018-09-15 09:42:59 +02:00
xmon powerpc/xmon: Fix invocation inside lock region 2019-01-26 09:38:33 +01:00
Kconfig powerpc/64s: Wire up cpu_show_meltdown() 2018-02-13 12:35:55 +01:00
Kconfig.debug powerpc/mm: Catch usage of cpu/mmu_has_feature() before jump label init 2016-08-01 11:15:06 +10:00
Makefile powerpc: Fix compiling a BE kernel with a powerpc64le toolchain 2017-12-14 09:28:17 +01:00
relocs_check.sh powerpc/64: whitelist unresolved modversions CRCs 2016-09-22 14:46:31 +02:00