printk: ringbuffer: fix line counting
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 13 Jan 2021 14:42:34 +0000 (15:48 +0106)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Jan 2021 10:55:08 +0000 (11:55 +0100)
commitcf3cca5f1580ce846e36c32db2c125199dca2d86
treedac88f4b0b13c2bae20f3fbdcf35a65b495cfd35
parent2cd90971a2c960c2c7a0f4e14fec8bf9c1a2e49b
printk: ringbuffer: fix line counting

[ Upstream commit 668af87f995b6d6d09595c088ad1fb5dd9ff25d2 ]

Counting text lines in a record simply involves counting the number
of newline characters (+1). However, it is searching the full data
block for newline characters, even though the text data can be (and
often is) a subset of that area. Since the extra area in the data
block was never initialized, the result is that extra newlines may
be seen and counted.

Restrict newline searching to the text data length.

Fixes: b6cf8b3f3312 ("printk: add lockless ringbuffer")
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/20210113144234.6545-1-john.ogness@linutronix.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/printk/printk_ringbuffer.c