summaryrefslogtreecommitdiffstats
path: root/drivers/video/fbdev/controlfb.h
diff options
context:
space:
mode:
authorJinke Han <jinkehan@didiglobal.com>2026-09-08 15:37:42 +0800
committerIngo Molnar <mingo@kernel.org>2026-09-17 09:48:42 +0200
commita5f7a5bb3b7f28ba7e4fa246775b29a0e5537255 (patch)
tree73fef824f9a846cf935869d0dbc5070ef6e2f741 /drivers/video/fbdev/controlfb.h
downloadlinux-stable-a5f7a5bb3b7f28ba7e4fa246775b29a0e5537255.tar.gz
linux-stable-a5f7a5bb3b7f28ba7e4fa246775b29a0e5537255.zip
x86/kprobes: Fix crash when probing CS CALL instructionsgrafted
When using eBPF to probe CS CALL instructions within a function, a crash can be triggered. The eBPF tool probes offset 257 of the __hrtimer_run_queues() function: <__hrtimer_run_queues+249>: nopl 0x0(%rax,%rax,1) <__hrtimer_run_queues+254>: mov %r14,%rdi <__hrtimer_run_queues+257>: cs call <__x86_indirect_thunk_r12> <__hrtimer_run_queues+263>: mov %eax,%r12d <__hrtimer_run_queues+266>: xchg %ax,%ax <__hrtimer_run_queues+268>: mov %r13,%rdi Which triggers this crash: BUG: unable to handle page fault for address: 00000000000f41c9 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 0 P4D 0 Oops: 0002 [#1] SMP NOPTI CPU: 1 PID: 0 Comm: swapper/1 Kdump: loaded Tainted: P RIP: 0010:__hrtimer_run_queues+0x106/0x230 Note that __hrtimer_run_queues+0x106 is __hrtimer_run_queues+262, which is at the 6th byte of the above CS CALL instruction. Since the CS CALL instruction occupies 6 bytes, the exception occurred in the middle of that call instruction. The root cause is that when using eBPF tools to probe in the middle of a function, a kprobe with INT3 is used as the underlying implementation. During single-step emulation of the original CALL instruction, int3_emulate_call() assumes that the probed CALL instruction is 5 bytes long. However, the actual CS-prefixed CALL instruction occupies 6 bytes, so it constructs an incorrect exception return address. When the CPU returns from the kprobe handler, the next instruction to be executed is at the address of the last byte of that CS CALL instruction. Coincidentally, starting from that address, the CPU fetches and decodes a completely different instruction, which ultimately triggers a kernel crash. Fix the issue by using the actual instruction length obtained from the instruction decoder when constructing the exception return address, rather than relying on the hardcoded CALL_INSN_SIZE macro. [ mingo: Refined the changelog ] Fixes: 6256e668b7af ("x86/kprobes: Use int3 instead of debug trap for single-step") Suggested-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Jinke Han <jinkehan@didiglobal.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Acked-by: Yafang Shao <laoar.shao@gmail.com> Acked-by: Borislav Petkov <bp@alien8.de> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://patch.msgid.link/20260908073742.GA10517@didi-ThinkCentre-M920t-N000
Diffstat (limited to 'drivers/video/fbdev/controlfb.h')
-rw-r--r--drivers/video/fbdev/controlfb.h143
1 files changed, 143 insertions, 0 deletions
diff --git a/drivers/video/fbdev/controlfb.h b/drivers/video/fbdev/controlfb.h
new file mode 100644
index 000000000..e779cca51
--- /dev/null
+++ b/drivers/video/fbdev/controlfb.h
@@ -0,0 +1,143 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * controlfb_hw.h: Constants of all sorts for controlfb
+ *
+ * Copyright (C) 1998 Daniel Jacobowitz <dan@debian.org>
+ *
+ * Based on an awful lot of code, including:
+ *
+ * control.c: Console support for PowerMac "control" display adaptor.
+ * Copyright (C) 1996 Paul Mackerras.
+ *
+ * The so far unpublished platinumfb.c
+ * Copyright (C) 1998 Jon Howell
+ */
+
+/*
+ * Structure of the registers for the RADACAL colormap device.
+ */
+struct cmap_regs {
+ unsigned char addr; /* index for both cmap and misc registers */
+ char pad1[15];
+ unsigned char crsr; /* cursor palette */
+ char pad2[15];
+ unsigned char dat; /* RADACAL misc register data */
+ char pad3[15];
+ unsigned char lut; /* cmap data */
+ char pad4[15];
+};
+
+/*
+ * Structure of the registers for the "control" display adaptor.
+ */
+#define PAD(x) char x[12]
+
+struct preg { /* padded register */
+ unsigned r;
+ char pad[12];
+};
+
+struct control_regs {
+ struct preg vcount; /* vertical counter */
+ /* Vertical parameters are in units of 1/2 scan line */
+ struct preg vswin; /* between vsblank and vssync */
+ struct preg vsblank; /* vert start blank */
+ struct preg veblank; /* vert end blank (display start) */
+ struct preg vewin; /* between vesync and veblank */
+ struct preg vesync; /* vert end sync */
+ struct preg vssync; /* vert start sync */
+ struct preg vperiod; /* vert period */
+ struct preg piped; /* pipe delay hardware cursor */
+ /* Horizontal params are in units of 2 pixels */
+ struct preg hperiod; /* horiz period - 2 */
+ struct preg hsblank; /* horiz start blank */
+ struct preg heblank; /* horiz end blank */
+ struct preg hesync; /* horiz end sync */
+ struct preg hssync; /* horiz start sync */
+ struct preg heq; /* half horiz sync len */
+ struct preg hlfln; /* half horiz period */
+ struct preg hserr; /* horiz period - horiz sync len */
+ struct preg cnttst;
+ struct preg ctrl; /* display control */
+ struct preg start_addr; /* start address: 5 lsbs zero */
+ struct preg pitch; /* addrs diff between scan lines */
+ struct preg mon_sense; /* monitor sense bits */
+ struct preg vram_attr; /* enable vram banks */
+ struct preg mode;
+ struct preg rfrcnt; /* refresh count */
+ struct preg intr_ena; /* interrupt enable */
+ struct preg intr_stat; /* interrupt status */
+ struct preg res[5];
+};
+
+struct control_regints {
+ /* Vertical parameters are in units of 1/2 scan line */
+ unsigned vswin; /* between vsblank and vssync */
+ unsigned vsblank; /* vert start blank */
+ unsigned veblank; /* vert end blank (display start) */
+ unsigned vewin; /* between vesync and veblank */
+ unsigned vesync; /* vert end sync */
+ unsigned vssync; /* vert start sync */
+ unsigned vperiod; /* vert period */
+ unsigned piped; /* pipe delay hardware cursor */
+ /* Horizontal params are in units of 2 pixels */
+ /* Except, apparently, for hres > 1024 (or == 1280?) */
+ unsigned hperiod; /* horiz period - 2 */
+ unsigned hsblank; /* horiz start blank */
+ unsigned heblank; /* horiz end blank */
+ unsigned hesync; /* horiz end sync */
+ unsigned hssync; /* horiz start sync */
+ unsigned heq; /* half horiz sync len */
+ unsigned hlfln; /* half horiz period */
+ unsigned hserr; /* horiz period - horiz sync len */
+};
+
+/*
+ * Dot clock rate is
+ * 3.9064MHz * 2**clock_params[2] * clock_params[1] / clock_params[0].
+ */
+struct control_regvals {
+ unsigned regs[16]; /* for vswin .. hserr */
+ unsigned char mode;
+ unsigned char radacal_ctrl;
+ unsigned char clock_params[3];
+};
+
+#define CTRLFB_OFF 16 /* position of pixel 0 in frame buffer */
+
+
+/*
+ * Best cmode supported by control
+ */
+struct max_cmodes {
+ int m[2]; /* 0: 2MB vram, 1: 4MB vram */
+};
+
+/*
+ * Video modes supported by macmodes.c
+ */
+static struct max_cmodes control_mac_modes[] = {
+ {{-1,-1}}, /* 512x384, 60Hz interlaced (NTSC) */
+ {{-1,-1}}, /* 512x384, 60Hz */
+ {{-1,-1}}, /* 640x480, 50Hz interlaced (PAL) */
+ {{-1,-1}}, /* 640x480, 60Hz interlaced (NTSC) */
+ {{ 2, 2}}, /* 640x480, 60Hz (VGA) */
+ {{ 2, 2}}, /* 640x480, 67Hz */
+ {{-1,-1}}, /* 640x870, 75Hz (portrait) */
+ {{-1,-1}}, /* 768x576, 50Hz (PAL full frame) */
+ {{ 2, 2}}, /* 800x600, 56Hz */
+ {{ 2, 2}}, /* 800x600, 60Hz */
+ {{ 2, 2}}, /* 800x600, 72Hz */
+ {{ 2, 2}}, /* 800x600, 75Hz */
+ {{ 1, 2}}, /* 832x624, 75Hz */
+ {{ 1, 2}}, /* 1024x768, 60Hz */
+ {{ 1, 2}}, /* 1024x768, 70Hz (or 72Hz?) */
+ {{ 1, 2}}, /* 1024x768, 75Hz (VESA) */
+ {{ 1, 2}}, /* 1024x768, 75Hz */
+ {{ 1, 2}}, /* 1152x870, 75Hz */
+ {{ 0, 1}}, /* 1280x960, 75Hz */
+ {{ 0, 1}}, /* 1280x1024, 75Hz */
+ {{ 1, 2}}, /* 1152x768, 60Hz */
+ {{ 0, 1}}, /* 1600x1024, 60Hz */
+};
+