Skip to content

Commit 6762931

Browse files
committed
jump_label: RFC - tolerate toggled state
__jump_label_patch currently will "crash the box" if it finds a jump_entry not as expected. ISTM this overly harsh; it doesn't distinguish between "alternate/opposite" state, and truly "insane/corrupted". The "opposite" (but well-formed) state is a milder mis-initialization problem, and some less severe mitigation is practical ? ATM this just warns about it, obviously an range/enum of outcomes: warn, crash, silence, correct, etc are possible, if warranted. Ive managed to create this mis-initialization condition with test_dynamic_debug.ko & _submod.ko. This is definitely a useage bug, but crashing the box over a similar (undiscovered) bug seems severe. :#> echo 1 > /sys/module/test_dynamic_debug/parameters/p_disjoint_bits [ 235.258452] dyndbg: bits:0x1 > *.p_disjoint_bits [ 235.258908] dyndbg: apply bitmap: 0x1 to: 0x4f for '*' [ 235.259351] dyndbg: query 0: "class D2_DRIVER -p" mod:* [ 235.259799] dyndbg: split into words: "class" "D2_DRIVER" "-p" [ 235.260290] dyndbg: op='-' flags=0x0 maskp=0xfffffffe [ 235.260720] dyndbg: parsed: func="" file="" module="" format="" lineno=0-0 class=D2_DRIVER [ 235.261418] dyndbg: good-class: test_dynamic_debug.D2_DRIVER module: test_dynamic_debug nd: 32 nc: 4 nu: 0 [ 235.262276] dyndbg: class-ref: test_dynamic_debug_submod.D2_DRIVER module: test_dynamic_debug_submod nd: 32 nc: 0 nu: 4 [ 235.263178] jump_label: found alternate op at do_cats+0x16/0x180 [test_dynamic_debug_submod] [00000000ba944cc2] (0f 1f 44 00 00 != e9 e1 00 00 00)) size:5 type:0 [ 235.264431] dyndbg: processed 1 queries, with 2 matches, 0 errs [ 235.264951] dyndbg: bit_1: 2 matches on class: D2_DRIVER -> 0x1 [ 235.265444] dyndbg: query 0: "class D2_KMS -p" mod:* [ 235.265869] dyndbg: split into words: "class" "D2_KMS" "-p" [ 235.266337] dyndbg: op='-' flags=0x0 maskp=0xfffffffe [ 235.266767] dyndbg: parsed: func="" file="" module="" format="" lineno=0-0 class=D2_KMS [ 235.267432] dyndbg: good-class: test_dynamic_debug.D2_KMS module: test_dynamic_debug nd: 32 nc: 4 nu: 0 [ 235.268264] dyndbg: class-ref: test_dynamic_debug_submod.D2_KMS module: test_dynamic_debug_submod nd: 32 nc: 0 nu: 4 [ 235.269142] jump_label: found alternate op at do_cats+0x1b/0x180 [test_dynamic_debug_submod] [00000000e8d6c160] (0f 1f 44 00 00 != e9 c4 00 00 00)) size:5 type:0 [ 235.270384] dyndbg: processed 1 queries, with 2 matches, 0 errs RFC: Ive hit this case a few times, but havent been able to isolate the when and why. warn-only is something of a punt, and I'm still left with remaining bugs which are likely related; I'm able to toggle the p-flag on callsites in the submod, but their enablement still doesn't yield logging activity. CC: Jason Baron <[email protected]> CC: Peter Zijlstra <[email protected]> Signed-off-by: Jim Cromie <[email protected]> --- heres the Fatal kernel bug: (its on a -dirty kernel) [ 2831.639643] dyndbg: good-class: test_dynamic_debug.D2_CORE module: test_dynamic_debug nd: 32 nc: 4 nu: 0 [ 2831.641316] dyndbg: class-ref: test_dynamic_debug_submod.D2_CORE module: test_dynamic_debug_submod nd: 32 nc: 0 nu: 4 [ 2831.642048] jump_label: Fatal kernel bug, unexpected op at do_cats+0x11/0x180 [test_dynamic_debug_submod] [00000000fa724232] (0f 1f 44 00 00 != e9 fe 00 00 00)) size:5 type:0 [ 2831.643077] ------------[ cut here ]------------ [ 2831.643537] kernel BUG at arch/x86/kernel/jump_label.c:73! [ 2831.643902] invalid opcode: 0000 [#1] PREEMPT SMP KASAN [ 2831.644248] CPU: 1 PID: 425 Comm: bash Tainted: G E 6.1.0-tf2-00021-gbe37efe8728f-dirty torvalds#696 [ 2831.644862] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc37 04/01/2014 [ 2831.645431] RIP: 0010:__jump_label_patch.cold+0x24/0x26 [ 2831.645773] Code: 83 e9 ef 00 ac fe 48 c7 c3 20 4c 5c 85 41 56 45 89 f9 49 89 d8 4c 89 e9 4c 89 ea 4c 89 ee 48 c7 c7 00 70 c5 82 e8 d7 1a 01 00 <0f> 0b 41 54 45 31 e4 55 48 89 fd 53 bb 00 00 00 80 48 81 c3 00 20 [ 2831.646896] RSP: 0018:ffffc9000101f738 EFLAGS: 00010282 [ 2831.647242] RAX: 00000000000000a2 RBX: ffffffff855c4c20 RCX: 0000000000000000 [ 2831.647702] RDX: 00000000000000a2 RSI: ffffffff81294fc4 RDI: fffff52000203ede [ 2831.648155] RBP: ffffc9000101f778 R08: 0000000000000003 R09: ffffc9000101f4ff [ 2831.648626] R10: fffff52000203e9f R11: 78656e75202c756a R12: ffffffff855c4c20 [ 2831.649096] R13: ffffffffc0250011 R14: 0000000000000000 R15: 0000000000000005 [ 2831.649498] FS: 00007fe4014aa740(0000) GS:ffff88805ae00000(0000) knlGS:0000000000000000 [ 2831.649894] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 2831.650175] CR2: 00007f9c326e6c08 CR3: 000000000ff59000 CR4: 0000000000750ee0 [ 2831.650520] PKRU: 55555554 [ 2831.650667] Call Trace: [ 2831.650793] <TASK> [ 2831.650903] ? do_cats+0x11/0x180 [test_dynamic_debug_submod] [ 2831.651195] arch_jump_label_transform_queue+0x43/0xa0 [ 2831.651450] __jump_label_update+0x9b/0x1b0 [ 2831.651670] static_key_disable_cpuslocked+0x9f/0xd0 [ 2831.651917] static_key_disable+0x16/0x20 [ 2831.652117] ddebug_change+0x45d/0x5c0
1 parent c0e1a16 commit 6762931

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

arch/x86/kernel/jump_label.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct jump_label_patch {
3535
static struct jump_label_patch
3636
__jump_label_patch(struct jump_entry *entry, enum jump_label_type type)
3737
{
38-
const void *expect, *code, *nop;
38+
const void *expect, *code, *nop, *alt;
3939
const void *addr, *dest;
4040
int size;
4141

@@ -57,20 +57,28 @@ __jump_label_patch(struct jump_entry *entry, enum jump_label_type type)
5757
default: BUG();
5858
}
5959

60-
if (type == JUMP_LABEL_JMP)
60+
if (type == JUMP_LABEL_JMP) {
6161
expect = nop;
62-
else
62+
alt = code;
63+
} else {
6364
expect = code;
64-
65+
alt = nop;
66+
}
6567
if (memcmp(addr, expect, size)) {
6668
/*
67-
* The location is not an op that we were expecting.
68-
* Something went wrong. Crash the box, as something could be
69-
* corrupting the kernel.
69+
* The location is not the op that we were expecting.
70+
* If its the alternate/toggled op, then warn, otherwise
71+
* something went more wrong. Crash the box, as
72+
* something could be corrupting the kernel.
7073
*/
71-
pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph != %5ph)) size:%d type:%d\n",
74+
if (memcmp(addr, alt, size)) {
75+
pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph != %5ph)) size:%d type:%d\n",
76+
addr, addr, addr, expect, size, type);
77+
BUG();
78+
} else {
79+
pr_warn("jump_label: found alternate op at %pS [%p] (%5ph != %5ph)) size:%d type:%d\n",
7280
addr, addr, addr, expect, size, type);
73-
BUG();
81+
}
7482
}
7583

7684
if (type == JUMP_LABEL_NOP)

0 commit comments

Comments
 (0)