Skip to content

Commit 033724d

Browse files
Tetsuo Handagregkh
authored andcommitted
fbdev: Detect integer underflow at "struct fbcon_ops"->clear_margins.
syzbot is reporting general protection fault in bitfill_aligned() [1] caused by integer underflow in bit_clear_margins(). The cause of this problem is when and how do_vc_resize() updates vc->vc_{cols,rows}. If vc_do_resize() fails (e.g. kzalloc() fails) when var.xres or var.yres is going to shrink, vc->vc_{cols,rows} will not be updated. This allows bit_clear_margins() to see info->var.xres < (vc->vc_cols * cw) or info->var.yres < (vc->vc_rows * ch). Unexpectedly large rw or bh will try to overrun the __iomem region and causes general protection fault. Also, vc_resize(vc, 0, 0) does not set vc->vc_{cols,rows} = 0 due to new_cols = (cols ? cols : vc->vc_cols); new_rows = (lines ? lines : vc->vc_rows); exception. Since cols and lines are calculated as cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); cols /= vc->vc_font.width; rows /= vc->vc_font.height; vc_resize(vc, cols, rows); in fbcon_modechanged(), var.xres < vc->vc_font.width makes cols = 0 and var.yres < vc->vc_font.height makes rows = 0. This means that const int fd = open("/dev/fb0", O_ACCMODE); struct fb_var_screeninfo var = { }; ioctl(fd, FBIOGET_VSCREENINFO, &var); var.xres = var.yres = 1; ioctl(fd, FBIOPUT_VSCREENINFO, &var); easily reproduces integer underflow bug explained above. Of course, callers of vc_resize() are not handling vc_do_resize() failure is bad. But we can't avoid vc_resize(vc, 0, 0) which returns 0. Therefore, as a band-aid workaround, this patch checks integer underflow in "struct fbcon_ops"->clear_margins call, assuming that vc->vc_cols * vc->vc_font.width and vc->vc_rows * vc->vc_font.heigh do not cause integer overflow. [1] https://syzkaller.appspot.com/bug?id=a565882df74fa76f10d3a6fec4be31098dbb37c6 Reported-and-tested-by: syzbot <[email protected]> Signed-off-by: Tetsuo Handa <[email protected]> Acked-by: Daniel Vetter <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 551e553 commit 033724d

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

drivers/video/fbdev/core/bitblit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
216216
region.color = color;
217217
region.rop = ROP_COPY;
218218

219-
if (rw && !bottom_only) {
219+
if ((int) rw > 0 && !bottom_only) {
220220
region.dx = info->var.xoffset + rs;
221221
region.dy = 0;
222222
region.width = rw;
223223
region.height = info->var.yres_virtual;
224224
info->fbops->fb_fillrect(info, &region);
225225
}
226226

227-
if (bh) {
227+
if ((int) bh > 0) {
228228
region.dx = info->var.xoffset;
229229
region.dy = info->var.yoffset + bs;
230230
region.width = rs;

drivers/video/fbdev/core/fbcon_ccw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ static void ccw_clear_margins(struct vc_data *vc, struct fb_info *info,
201201
region.color = color;
202202
region.rop = ROP_COPY;
203203

204-
if (rw && !bottom_only) {
204+
if ((int) rw > 0 && !bottom_only) {
205205
region.dx = 0;
206206
region.dy = info->var.yoffset;
207207
region.height = rw;
208208
region.width = info->var.xres_virtual;
209209
info->fbops->fb_fillrect(info, &region);
210210
}
211211

212-
if (bh) {
212+
if ((int) bh > 0) {
213213
region.dx = info->var.xoffset + bs;
214214
region.dy = 0;
215215
region.height = info->var.yres_virtual;

drivers/video/fbdev/core/fbcon_cw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ static void cw_clear_margins(struct vc_data *vc, struct fb_info *info,
184184
region.color = color;
185185
region.rop = ROP_COPY;
186186

187-
if (rw && !bottom_only) {
187+
if ((int) rw > 0 && !bottom_only) {
188188
region.dx = 0;
189189
region.dy = info->var.yoffset + rs;
190190
region.height = rw;
191191
region.width = info->var.xres_virtual;
192192
info->fbops->fb_fillrect(info, &region);
193193
}
194194

195-
if (bh) {
195+
if ((int) bh > 0) {
196196
region.dx = info->var.xoffset;
197197
region.dy = info->var.yoffset;
198198
region.height = info->var.yres;

drivers/video/fbdev/core/fbcon_ud.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ static void ud_clear_margins(struct vc_data *vc, struct fb_info *info,
231231
region.color = color;
232232
region.rop = ROP_COPY;
233233

234-
if (rw && !bottom_only) {
234+
if ((int) rw > 0 && !bottom_only) {
235235
region.dy = 0;
236236
region.dx = info->var.xoffset;
237237
region.width = rw;
238238
region.height = info->var.yres_virtual;
239239
info->fbops->fb_fillrect(info, &region);
240240
}
241241

242-
if (bh) {
242+
if ((int) bh > 0) {
243243
region.dy = info->var.yoffset;
244244
region.dx = info->var.xoffset;
245245
region.height = bh;

0 commit comments

Comments
 (0)