Skip to content

Commit d4d2524

Browse files
albus-droidUlrich Hecht
authored andcommitted
fbdev: Add bounds checking in bit_putcs to fix vmalloc-out-of-bounds
[ Upstream commit 3637d34b35b287ab830e66048841ace404382b67 ] 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: syzbot+48b0652a95834717f190@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=48b0652a95834717f190 Suggested-by: Helge Deller <deller@gmx.de> Tested-by: syzbot+48b0652a95834717f190@syzkaller.appspotmail.com Signed-off-by: Albin Babu Varghese <albinbabuvarghese20@gmail.com> Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent a0d1fb8 commit d4d2524

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

drivers/video/fbdev/core/bitblit.c

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

172+
if (image.dy >= info->var.yres)
173+
return;
174+
175+
image.height = min(image.height, info->var.yres - image.dy);
176+
172177
if (attribute) {
173178
buf = kmalloc(cellsize, GFP_ATOMIC);
174179
if (!buf)
@@ -182,6 +187,18 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,
182187
cnt = count;
183188

184189
image.width = vc->vc_font.width * cnt;
190+
191+
if (image.dx >= info->var.xres)
192+
break;
193+
194+
if (image.dx + image.width > info->var.xres) {
195+
image.width = info->var.xres - image.dx;
196+
cnt = image.width / vc->vc_font.width;
197+
if (cnt == 0)
198+
break;
199+
image.width = cnt * vc->vc_font.width;
200+
}
201+
185202
pitch = DIV_ROUND_UP(image.width, 8) + scan_align;
186203
pitch &= ~scan_align;
187204
size = pitch * image.height + buf_align;

0 commit comments

Comments
 (0)