Repository navigation
Commit 861c2e3
printk: fix buffer overflow potential for print_text()
commit f0e386e upstream.
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.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent cb14bbb commit 861c2e3
1 file changed
Lines changed: 27 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1338 | 1338 | | |
1339 | 1339 | | |
1340 | 1340 | | |
| 1341 | + | |
1341 | 1342 | | |
1342 | | - | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
1343 | 1347 | | |
1344 | 1348 | | |
1345 | | - | |
| 1349 | + | |
| 1350 | + | |
1346 | 1351 | | |
1347 | 1352 | | |
1348 | 1353 | | |
| |||
1385 | 1390 | | |
1386 | 1391 | | |
1387 | 1392 | | |
1388 | | - | |
| 1393 | + | |
1389 | 1394 | | |
1390 | | - | |
| 1395 | + | |
1391 | 1396 | | |
1392 | | - | |
| 1397 | + | |
1393 | 1398 | | |
1394 | 1399 | | |
1395 | | - | |
| 1400 | + | |
1396 | 1401 | | |
1397 | 1402 | | |
1398 | 1403 | | |
1399 | 1404 | | |
1400 | 1405 | | |
1401 | 1406 | | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1402 | 1413 | | |
1403 | | - | |
1404 | 1414 | | |
1405 | 1415 | | |
1406 | | - | |
1407 | | - | |
| 1416 | + | |
| 1417 | + | |
1408 | 1418 | | |
1409 | 1419 | | |
1410 | 1420 | | |
| |||
1429 | 1439 | | |
1430 | 1440 | | |
1431 | 1441 | | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
1432 | 1450 | | |
1433 | 1451 | | |
1434 | 1452 | | |
| |||
0 commit comments