fbdev: fbcon: release buffer when fbcon_do_set_font() failed
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Mon, 5 Dec 2022 22:10:31 +0000 (07:10 +0900)
committerHelge Deller <deller@gmx.de>
Wed, 14 Dec 2022 19:01:51 +0000 (20:01 +0100)
syzbot is reporting memory leak at fbcon_do_set_font() [1], for
commit a5a923038d70 ("fbdev: fbcon: Properly revert changes when
vc_resize() failed") missed that the buffer might be newly allocated
by fbcon_set_font().

Link: https://syzkaller.appspot.com/bug?extid=25bdb7b1703639abd498
Reported-by: syzbot <syzbot+25bdb7b1703639abd498@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: syzbot <syzbot+25bdb7b1703639abd498@syzkaller.appspotmail.com>
Fixes: a5a923038d70 ("fbdev: fbcon: Properly revert changes when vc_resize() failed")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/core/fbcon.c

index c0143d3..14a7d40 100644 (file)
@@ -2450,7 +2450,8 @@ err_out:
 
        if (userfont) {
                p->userfont = old_userfont;
-               REFCOUNT(data)--;
+               if (--REFCOUNT(data) == 0)
+                       kfree(data - FONT_EXTRA_WORDS * sizeof(int));
        }
 
        vc->vc_font.width = old_width;