Commit ce68455
vt: Reject zero-sized screen buffer size.
syzbot is reporting general protection fault in do_con_write() [1] caused
by vc->vc_screenbuf == ZERO_SIZE_PTR caused by vc->vc_screenbuf_size == 0
caused by vc->vc_cols == vc->vc_rows == vc->vc_size_row == 0 caused by
fb_set_var() from ioctl(FBIOPUT_VSCREENINFO) on /dev/fb0 , for
gotoxy(vc, 0, 0) from reset_terminal() from vc_init() from vc_allocate()
from con_install() from tty_init_dev() from tty_open() on such console
causes vc->vc_pos == 0x10000000e due to
((unsigned long) ZERO_SIZE_PTR) + -1U * 0 + (-1U << 1).
I don't think that a console with 0 column or 0 row makes sense. And it
seems that vc_do_resize() does not intend to allow resizing a console to
0 column or 0 row due to
new_cols = (cols ? cols : vc->vc_cols);
new_rows = (lines ? lines : vc->vc_rows);
exception.
Theoretically, cols and rows can be any range as long as
0 < cols * rows * 2 <= KMALLOC_MAX_SIZE is satisfied (e.g.
cols == 1048576 && rows == 2 is possible) because of
vc->vc_size_row = vc->vc_cols << 1;
vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
in visual_init() and kzalloc(vc->vc_screenbuf_size) in vc_allocate().
Since we can detect cols == 0 or rows == 0 via screenbuf_size = 0 in
visual_init(), we can reject kzalloc(0). Then, vc_allocate() will return
an error, and con_write() will not be called on a console with 0 column
or 0 row.
We need to make sure that integer overflow in visual_init() won't happen.
Since vc_do_resize() restricts cols <= 32767 and rows <= 32767, applying
1 <= cols <= 32767 and 1 <= rows <= 32767 restrictions to vc_allocate()
will be practically fine.
This patch does not touch con_init(), for returning -EINVAL there
does not help when we are not returning -ENOMEM.
[1] https://syzkaller.appspot.com/bug?extid=017265e8553724e514e8
Reported-and-tested-by: syzbot <syzbot+017265e8553724e514e8@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200712111013.11881-1-penguin-kernel@I-love.SAKURA.ne.jp
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent ba47d84 commit ce68455
1 file changed
+18
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1092 | 1092 | | |
1093 | 1093 | | |
1094 | 1094 | | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1095 | 1103 | | |
1096 | 1104 | | |
1097 | 1105 | | |
1098 | 1106 | | |
| 1107 | + | |
1099 | 1108 | | |
1100 | 1109 | | |
1101 | 1110 | | |
| |||
1125 | 1134 | | |
1126 | 1135 | | |
1127 | 1136 | | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
1128 | 1142 | | |
1129 | 1143 | | |
1130 | 1144 | | |
| |||
1143 | 1157 | | |
1144 | 1158 | | |
1145 | 1159 | | |
1146 | | - | |
| 1160 | + | |
1147 | 1161 | | |
1148 | 1162 | | |
1149 | 1163 | | |
| |||
1158 | 1172 | | |
1159 | 1173 | | |
1160 | 1174 | | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | 1175 | | |
1170 | 1176 | | |
1171 | 1177 | | |
| |||
1201 | 1207 | | |
1202 | 1208 | | |
1203 | 1209 | | |
1204 | | - | |
| 1210 | + | |
1205 | 1211 | | |
1206 | 1212 | | |
1207 | 1213 | | |
| |||
1212 | 1218 | | |
1213 | 1219 | | |
1214 | 1220 | | |
1215 | | - | |
| 1221 | + | |
1216 | 1222 | | |
1217 | 1223 | | |
1218 | 1224 | | |
| |||
3393 | 3399 | | |
3394 | 3400 | | |
3395 | 3401 | | |
| 3402 | + | |
3396 | 3403 | | |
3397 | 3404 | | |
3398 | 3405 | | |
| |||
0 commit comments