On 11/12/26 07:37, Weidong Wang via B4 Relay wrote:
From: Weidong Wang <[email protected]>

cirrusfb_check_var() raises xres_virtual to xres and then checks
xres_virtual * yres_virtual against the video memory in 32-bit
arithmetic. fb_set_var() checks the product for overflow, but only for
the values passed in, before the driver raises xres_virtual. A mode with
xres 65536, xres_virtual 640 and yres_virtual 65536 passes that check,
becomes 65536 x 65536 in cirrusfb_check_var(), and the product wraps to
0, so the mode is accepted on a 4 MiB card with a line length of
65536 bytes. The framebuffer console then draws at offsets far past the
end of the video memory mapping.

Do the multiplication in 64 bits.

Found by an AI code review agent (an LLM-based bug-finding tool
developed by Zijie Zhao and the submitter) and confirmed on an
unmodified kernel, without error injection, on x86_64 under QEMU with
-vga cirrus (GD5446, 4 MiB) and KASAN. FBIOPUT_VSCREENINFO with
xres 65536, yres 128, xres_virtual 640, yres_virtual 65536 at 8 bpp is
accepted as 65536x128, virtual 65536x65536. Booted with
video=cirrusfb:noaccel, fbcon's redraw then faults:

   BUG: unable to handle page fault for address: ffffc90000b00000
   RIP: 0010:cfb_imageblit+0xbc6/0x1970
    soft_cursor+0x5eb/0xcd0
    bit_cursor+0xb41/0x1910
    hide_cursor+0x6e/0x1d0

With acceleration enabled, text on the GD5446 is drawn with the blitter,
which QEMU bounds, so the mode is accepted but nothing faults; drawing
goes through the CPU with noaccel and on the Laguna chips, which always
run without acceleration. Asked for without the wrap, as 65536x128 with
a 65536x128 virtual resolution (8 MiB), the mode is rejected, as it
should be.

With this patch the mode is rejected with "virtual resolution too high
to fit into video memory", and 1024x768x8 is still accepted.

The reproducer, fix and changelog were drafted with AI assistance
(Claude), then reviewed and tested by the submitter.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: [email protected]
Cc: Zijie Zhao <[email protected]>
Signed-off-by: Weidong Wang <[email protected]>
---
Tested on v7.4-rc1 (05441d697f7f), x86_64, KASAN, QEMU/KVM -vga cirrus
(GD5446, 4 MiB). FBIOPUT_VSCREENINFO at 8 bpp:

                65536x128, virtual 640x65536    65536x128, virtual 65536x128
                                                (control)
   unpatched    accepted as virtual 65536x65536; rejected
                with noaccel, fbcon faults in
                cfb_imageblit, panic
   patched      rejected                        rejected


can't you simply check xres_virtual and yres_virtual values
against sane values, e.g. bail out if each of them is bigger than
e.g. 16384 pixels ?

Helge

Reply via email to