Skip to contentSkip to conversation

printk: fix string termination for record_print_text()

PATCH In review John Ogness 2 participants 2 messages Jan 24, 2021 – Jan 26, 2021 Printk

lore
Share & tools
lore

John Ogness

author maintainer
#0 lore raw

PATCH 1/1 printk: fix string termination for record_print_text()

Commit f0e386ee0c0b ("printk: fix buffer overflow potential for print_text()") added string termination in record_print_text(). However it used the wrong base pointer for adding the terminator. This led to a 0-byte being written somewhere beyond the buffer.

Use the correct base pointer when adding the terminator.

Fixes f0e386ee0c0b ("printk: fix buffer overflow potential for print_text()")
---
 kernel/printk/printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/printk/printk.c +1 -1
index 6639a0cfe0ac..5a95c688621f 100644
@@ -1398,7 +1398,7 @@ static size_t record_print_text(struct printk_record *r, bool syslog,
 	 * not counted in the return value.
 	 */
 	if (buf_size > 0)
-		text[len] = 0;
+		r->text_buf[len] = 0;
 
 	return len;
 }
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 10 lines · John Ogness

Commit f0e386ee0c0b ("printk: fix buffer overflow potential for print_text()") added string termination in record_print_text(). However it used the wrong base pointer for adding the terminator. This led to a 0-byte being written somewhere beyond the buffer.

Use the correct base pointer when adding the terminator.

Fixes f0e386ee0c0b ("printk: fix buffer overflow potential for print_text()")

The patch is pushed in kernel/printk.git, branch printk-rework.

I am going to send pull request for-5.11 later today.

Thanks a lot for the debugging and quick fix. I feel shame that I did not caught this during the review.

Best Regards,
Petr