Commit f0e386e
printk: fix buffer overflow potential for print_text()
Before the commit 896fbe2 ("printk: use the lockless
ringbuffer"), msg_print_text() would only write up to size-1 bytes
into the provided buffer. Some callers expect this behavior and
append a terminator to returned string. In particular:
arch/powerpc/xmon/xmon.c:dump_log_buf()
arch/um/kernel/kmsg_dump.c:kmsg_dumper_stdout()
msg_print_text() has been replaced by record_print_text(), which
currently fills the full size of the buffer. This causes a
buffer overflow for the above callers.
Change record_print_text() so that it will only use size-1 bytes
for text data. Also, for paranoia sakes, add a terminator after
the text data.
And finally, document this behavior so that it is clear that only
size-1 bytes are used and a terminator is added.
Fixes: 896fbe2 ("printk: use the lockless ringbuffer")
Cc: stable@vger.kernel.org # 5.10+
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210114170412.4819-1-john.ogness@linutronix.de1 parent 89ccf18 commit f0e386e
1 file changed
Lines changed: 27 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1292 | 1292 | | |
1293 | 1293 | | |
1294 | 1294 | | |
| 1295 | + | |
1295 | 1296 | | |
1296 | | - | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
1297 | 1301 | | |
1298 | 1302 | | |
1299 | | - | |
| 1303 | + | |
| 1304 | + | |
1300 | 1305 | | |
1301 | 1306 | | |
1302 | 1307 | | |
| |||
1339 | 1344 | | |
1340 | 1345 | | |
1341 | 1346 | | |
1342 | | - | |
| 1347 | + | |
1343 | 1348 | | |
1344 | | - | |
| 1349 | + | |
1345 | 1350 | | |
1346 | | - | |
| 1351 | + | |
1347 | 1352 | | |
1348 | 1353 | | |
1349 | | - | |
| 1354 | + | |
1350 | 1355 | | |
1351 | 1356 | | |
1352 | 1357 | | |
1353 | 1358 | | |
1354 | 1359 | | |
1355 | 1360 | | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
1356 | 1367 | | |
1357 | | - | |
1358 | 1368 | | |
1359 | 1369 | | |
1360 | | - | |
1361 | | - | |
| 1370 | + | |
| 1371 | + | |
1362 | 1372 | | |
1363 | 1373 | | |
1364 | 1374 | | |
| |||
1383 | 1393 | | |
1384 | 1394 | | |
1385 | 1395 | | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
1386 | 1404 | | |
1387 | 1405 | | |
1388 | 1406 | | |
| |||
0 commit comments