Skip to content

Commit b5bed7f

Browse files
Jon Medhurst (Tixy)Russell King
authored andcommitted
ARM: 7181/1: Restrict kprobes probing SWP instructions to ARMv5 and below
The SWP instruction is deprecated on ARMv6 and with ARMv7 it will be UNDEFINED when CONFIG_SWP_EMULATE is selected. In this case, probing a SWP instruction will cause an oops when the kprobes emulation code executes an undefined instruction. As the SWP instruction should be rare or non-existent in kernels for ARMv6 and later, we can simply avoid these problems by not allowing probing of these. Reported-by: Leif Lindholm <[email protected]> Tested-by: Leif Lindholm <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Signed-off-by: Jon Medhurst <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent 14383c2 commit b5bed7f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

arch/arm/kernel/kprobes-arm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,12 @@ static const union decode_item arm_cccc_0000_____1001_table[] = {
519519
static const union decode_item arm_cccc_0001_____1001_table[] = {
520520
/* Synchronization primitives */
521521

522+
#if __LINUX_ARM_ARCH__ < 6
523+
/* Deprecated on ARMv6 and may be UNDEFINED on v7 */
522524
/* SMP/SWPB cccc 0001 0x00 xxxx xxxx xxxx 1001 xxxx */
523525
DECODE_EMULATEX (0x0fb000f0, 0x01000090, emulate_rd12rn16rm0_rwflags_nopc,
524526
REGS(NOPC, NOPC, 0, 0, NOPC)),
525-
527+
#endif
526528
/* LDREX/STREX{,D,B,H} cccc 0001 1xxx xxxx xxxx xxxx 1001 xxxx */
527529
/* And unallocated instructions... */
528530
DECODE_END

arch/arm/kernel/kprobes-test-arm.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,25 @@ void kprobe_arm_test_cases(void)
427427

428428
TEST_GROUP("Synchronization primitives")
429429

430-
/*
431-
* Use hard coded constants for SWP instructions to avoid warnings
432-
* about deprecated instructions.
433-
*/
434-
TEST_RP( ".word 0xe108e097 @ swp lr, r",7,VAL2,", [r",8,0,"]")
435-
TEST_R( ".word 0x610d0091 @ swpvs r0, r",1,VAL1,", [sp]")
436-
TEST_RP( ".word 0xe10cd09e @ swp sp, r",14,VAL2,", [r",12,13*4,"]")
430+
#if __LINUX_ARM_ARCH__ < 6
431+
TEST_RP("swp lr, r",7,VAL2,", [r",8,0,"]")
432+
TEST_R( "swpvs r0, r",1,VAL1,", [sp]")
433+
TEST_RP("swp sp, r",14,VAL2,", [r",12,13*4,"]")
434+
#else
435+
TEST_UNSUPPORTED(".word 0xe108e097 @ swp lr, r7, [r8]")
436+
TEST_UNSUPPORTED(".word 0x610d0091 @ swpvs r0, r1, [sp]")
437+
TEST_UNSUPPORTED(".word 0xe10cd09e @ swp sp, r14 [r12]")
438+
#endif
437439
TEST_UNSUPPORTED(".word 0xe102f091 @ swp pc, r1, [r2]")
438440
TEST_UNSUPPORTED(".word 0xe102009f @ swp r0, pc, [r2]")
439441
TEST_UNSUPPORTED(".word 0xe10f0091 @ swp r0, r1, [pc]")
440-
TEST_RP( ".word 0xe148e097 @ swpb lr, r",7,VAL2,", [r",8,0,"]")
441-
TEST_R( ".word 0x614d0091 @ swpvsb r0, r",1,VAL1,", [sp]")
442+
#if __LINUX_ARM_ARCH__ < 6
443+
TEST_RP("swpb lr, r",7,VAL2,", [r",8,0,"]")
444+
TEST_R( "swpvsb r0, r",1,VAL1,", [sp]")
445+
#else
446+
TEST_UNSUPPORTED(".word 0xe148e097 @ swpb lr, r7, [r8]")
447+
TEST_UNSUPPORTED(".word 0x614d0091 @ swpvsb r0, r1, [sp]")
448+
#endif
442449
TEST_UNSUPPORTED(".word 0xe142f091 @ swpb pc, r1, [r2]")
443450

444451
TEST_UNSUPPORTED(".word 0xe1100090") /* Unallocated space */

0 commit comments

Comments
 (0)