selftests/powerpc: Add exec() test to check for spr sanitisation
PATCH 1/5 selftests/powerpc: Add exec() test to check for spr sanitisation
--- tools/testing/selftests/powerpc/syscalls/Makefile | 3 +- .../testing/selftests/powerpc/syscalls/spr_exec.c | 78 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/syscalls/spr_exec.c
tools/testing/selftests/powerpc/syscalls/Makefile +2 -1
@@ -1,10 +1,11 @@ -TEST_PROGS := ipc_unmuxed +TEST_PROGS := ipc_unmuxed spr_exec CFLAGS += -I../../../../../usr/include all: $(TEST_PROGS) $(TEST_PROGS): ../harness.c +spr_exec: ../utils.c include ../../lib.mk
tools/testing/selftests/powerpc/syscalls/spr_exec.c new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/5 selftests/powerpc: Add fork() test to check for spr being preserved
--- tools/testing/selftests/powerpc/syscalls/Makefile | 3 +- .../testing/selftests/powerpc/syscalls/spr_fork.c | 78 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/syscalls/spr_fork.c
tools/testing/selftests/powerpc/syscalls/Makefile +2 -1
@@ -1,4 +1,4 @@ -TEST_PROGS := ipc_unmuxed spr_exec +TEST_PROGS := ipc_unmuxed spr_exec spr_fork CFLAGS += -I../../../../../usr/include
@@ -6,6 +6,7 @@ all: $(TEST_PROGS) $(TEST_PROGS): ../harness.c spr_exec: ../utils.c +spr_fork: ../utils.c include ../../lib.mk
tools/testing/selftests/powerpc/syscalls/spr_fork.c new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 3/5 powerpc: Fix TAR leak across exec() syscalls
In reply to Cyril BurCurrently start_thread() doesn't sanitise TAR.
The TAR SPR register is a register that can be set and branched to, not sanitising it presents an information leak to the new executable.
Other SPR registers such as the Performance registers used by perf (and are managed entirely by perf) as well as the Event Based Branch (EBB) registers are left alone by design as these fall into the same category as leaving file descriptors open across exec(), it is up the parent thread to sanitise what it deems necessary.
--- arch/powerpc/kernel/process.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/powerpc/kernel/process.c +14 -0
@@ -1577,6 +1577,8 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp) current->thread.vr_state.vscr.u[3 ] =0x00010000 ;/* Java mode disabled */ current->thread.vr_save_area =NULL ; current->thread.vrsave =0 ; +if (cpu_has_feature (CPU_FTR_ALTIVEC )) +mtspr (SPRN_VRSAVE ,0 ); current->thread.used_vr =0 ;#endif /* CONFIG_ALTIVEC */ #ifdef CONFIG_SPE
@@ -1592,6 +1594,18 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp) current->thread.tm_texasr =0 ; current->thread.tm_tfiar =0 ;#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ +#ifdef CONFIG_PPC_BOOK3S_64 +/* +* Zero out the SPRs. +* Don't touch the ones use by perf, it controls them. +* Don't touch the EBB regs. This falls into the same category of +* responsibly as open file descriptors across exec(), the parent should +* sanitise if it feels it would be a problem +*/ + current->thread.tar =0 ; +if (cpu_has_feature (CPU_FTR_ARCH_206 )) +mtspr (SPRN_TAR ,0 ); +#endif /* CONFIG_PPC_BOOK3S_64 */ }EXPORT_SYMBOL (start_thread);
Signature · 1 line
2.7.4
Re: [PATCH 3/5] powerpc: Fix TAR leak across exec() syscalls
Quoted 6 lines · Cyril Bur
Currently
start_thread()doesn't sanitise TAR.
=20
The TAR SPR register is a register that can be set and branched to, not sanitising it presents an information leak to the new executable. =20
Other SPR registers such as the Performance registers used by perf (and a=
re
Quoted 1 line
managed entirely by perf) as well as the Event Based Branch (EBB) registe=
rs are
Quoted 2 lines
left alone by design as these fall into the same category as leaving file descriptors open across
exec(), it is up the parent thread to sanitise wh=
at it
arch/powerpc/kernel/process.=
Quoted 8 lines
deems necessary.
=20Signed-off-by Cyril Bur <[email protected]>--- arch/powerpc/kernel/process.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)=20
arch/powerpc/kernel/process.= renamed from arch/powerpc/kernel/process.c +0
-0
c
arch/powerpc/kernel/process.c void start_thread(struct pt_regs *regs, unsigned lo=
Quoted 4 lines
index d7a9df5..56444a6 100644
arch/powerpc/kernel/process.c +0
-0@@ -1577,6 +1577,8 @@ void start_thread(struct pt_regs *regs, unsigned lo=
ng start, unsigned long sp)
arch/powerpc/kernel/process.c void start_thread(struct pt_regs *regs, unsigned lo= · line 1577
Quoted 1 line
arch/powerpc/kernel/process.c +0
-0current->thread.vr_state.vscr.u[3] =3D 0x00010000; /* Java mode disable=
d */
arch/powerpc/kernel/process.c void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp) · line 1581
Quoted 4 lines
arch/powerpc/kernel/process.c +2
-0current->thread.vr_save_area =3D NULL; current->thread.vrsave =3D 0; +if (cpu_has_feature (CPU_FTR_ALTIVEC )) +mtspr (SPRN_VRSAVE ,0 );
VRSAVE is not mentioned in the commit message.
arch/powerpc/kernel/process.c void start_thread(struct pt_regs *regs, unsigned l=
Quoted 4 lines
arch/powerpc/kernel/process.c +0
-0current->thread.used_vr =3D 0;#endif /* CONFIG_ALTIVEC */ #ifdef CONFIG_SPE @@ -1592,6 +1594,18 @@ void start_thread(struct pt_regs *regs, unsigned l=
ong start, unsigned long sp)
arch/powerpc/kernel/process.c void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
Quoted 9 lines
arch/powerpc/kernel/process.c +6
-0current->thread.tm_texasr =3D 0; current->thread.tm_tfiar =3D 0;#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ +#ifdef CONFIG_PPC_BOOK3S_64 +/* +* Zero out the SPRs. +* Don't touch the ones use by perf, it controls them. +* Don't touch the EBB regs. This falls into the same category of +* responsibly as open file descriptors across exec(), the parent sho=
uld
Quoted 9 lines
arch/powerpc/kernel/process.c +6
-0+* sanitise if it feels it would be a problem +*/ + current->thread.tar =3D 0; +if (cpu_has_feature (CPU_FTR_ARCH_206 )) +mtspr (SPRN_TAR ,0 ); +#endif /* CONFIG_PPC_BOOK3S_64 */ }EXPORT_SYMBOL (start_thread);=20
PATCH 4/5 powerpc: Move flush_all_to_thread() below save_sprs()
In reply to Cyril Bur--- arch/powerpc/kernel/process.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
arch/powerpc/kernel/process.c +17 -17
@@ -511,23 +511,6 @@ void save_all(struct task_struct *tsk)msr_check_and_clear (msr_all_available); } -void flush_all_to_thread (struct task_struct *tsk) -{ -if (tsk->thread.regs) { -preempt_disable (); -BUG_ON (tsk != current); -save_all (tsk); - -#ifdef CONFIG_SPE -if (tsk->thread.regs->msr &MSR_SPE ) - tsk->thread.spefscr =mfspr (SPRN_SPEFSCR ); -#endif - -preempt_enable (); - } -} -EXPORT_SYMBOL (flush_all_to_thread); -#ifdef CONFIG_PPC_ADV_DEBUG_REGS void do_send_trap (struct pt_regs *regs,unsigned long address,unsigned long error_code,int signal_code,int breakpt)
@@ -1047,6 +1030,23 @@ static inline void restore_sprs(struct thread_struct *old_thread,#endif } +void flush_all_to_thread (struct task_struct *tsk) +{ +if (tsk->thread.regs) { +preempt_disable (); +BUG_ON (tsk != current); +save_all (tsk); + +#ifdef CONFIG_SPE +if (tsk->thread.regs->msr &MSR_SPE ) + tsk->thread.spefscr =mfspr (SPRN_SPEFSCR ); +#endif + +preempt_enable (); + } +} +EXPORT_SYMBOL (flush_all_to_thread); +struct task_struct *__switch_to (struct task_struct *prev,struct task_struct *new) {
Signature · 1 line
2.7.4
PATCH 5/5 powerpc: Preserve the SPR values across fork() syscalls
In reply to Cyril BurCurrently copy_thread() doesn't flush SPRs to the parent thread struct. Currently this only affects the TAR register as perf takes care of some of the others and the remaining ones are all Event Based Branch (EBB) registers which are cleared across fork().
--- arch/powerpc/kernel/process.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/kernel/process.c +2 -0
@@ -1037,6 +1037,8 @@ void flush_all_to_thread(struct task_struct *tsk)BUG_ON (tsk != current);save_all (tsk); +save_sprs (&tsk->thread); +#ifdef CONFIG_SPE if (tsk->thread.regs->msr &MSR_SPE ) tsk->thread.spefscr =mfspr (SPRN_SPEFSCR );
Signature · 1 line
2.7.4