Skip to content

Commit 3637d34

Browse files
albus-droidhdeller
authored andcommitted
fbdev: Add bounds checking in bit_putcs to fix vmalloc-out-of-bounds
Add bounds checking to prevent writes past framebuffer boundaries when rendering text near screen edges. Return early if the Y position is off-screen and clip image height to screen boundary. Break from the rendering loop if the X position is off-screen. When clipping image width to fit the screen, update the character count to match the clipped width to prevent buffer size mismatches. Without the character count update, bit_putcs_aligned and bit_putcs_unaligned receive mismatched parameters where the buffer is allocated for the clipped width but cnt reflects the original larger count, causing out-of-bounds writes. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=48b0652a95834717f190 Suggested-by: Helge Deller <[email protected]> Tested-by: [email protected] Signed-off-by: Albin Babu Varghese <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent c8fee6a commit 3637d34

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/video/fbdev/core/bitblit.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,
160160
image.height = vc->vc_font.height;
161161
image.depth = 1;
162162

163+
if (image.dy >= info->var.yres)
164+
return;
165+
166+
image.height = min(image.height, info->var.yres - image.dy);
167+
163168
if (attribute) {
164169
buf = kmalloc(cellsize, GFP_ATOMIC);
165170
if (!buf)
@@ -173,6 +178,18 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,
173178
cnt = count;
174179

175180
image.width = vc->vc_font.width * cnt;
181+
182+
if (image.dx >= info->var.xres)
183+
break;
184+
185+
if (image.dx + image.width > info->var.xres) {
186+
image.width = info->var.xres - image.dx;
187+
cnt = image.width / vc->vc_font.width;
188+
if (cnt == 0)
189+
break;
190+
image.width = cnt * vc->vc_font.width;
191+
}
192+
176193
pitch = DIV_ROUND_UP(image.width, 8) + scan_align;
177194
pitch &= ~scan_align;
178195
size = pitch * image.height + buf_align;

0 commit comments

Comments
 (0)