2021-01-13 16:48:36

by John Ogness

[permalink] [raw]
Subject: [PATCH] printk: fix kmsg_dump_get_buffer length calulations

kmsg_dump_get_buffer() uses @syslog to determine if the syslog
prefix should be written to the buffer. However, when calculating
the maximum number of records that can fit into the buffer, it
always counts the bytes from the syslog prefix.

Use @syslog when calculating the maximum number of records that can
fit into the buffer.

Fixes: e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")
Signed-off-by: John Ogness <[email protected]>
---
kernel/printk/printk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ffdd0dc7ec6d..848b56efc9d7 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3427,7 +3427,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
while (prb_read_valid_info(prb, seq, &info, &line_count)) {
if (r.info->seq >= dumper->next_seq)
break;
- l += get_record_print_text_size(&info, line_count, true, time);
+ l += get_record_print_text_size(&info, line_count, syslog, time);
seq = r.info->seq + 1;
}

@@ -3437,7 +3437,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
&info, &line_count)) {
if (r.info->seq >= dumper->next_seq)
break;
- l -= get_record_print_text_size(&info, line_count, true, time);
+ l -= get_record_print_text_size(&info, line_count, syslog, time);
seq = r.info->seq + 1;
}

--
2.20.1


2021-01-14 13:29:42

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] printk: fix kmsg_dump_get_buffer length calulations

On Wed 2021-01-13 17:50:13, John Ogness wrote:
> kmsg_dump_get_buffer() uses @syslog to determine if the syslog
> prefix should be written to the buffer. However, when calculating
> the maximum number of records that can fit into the buffer, it
> always counts the bytes from the syslog prefix.
>
> Use @syslog when calculating the maximum number of records that can
> fit into the buffer.

Another great catch!

> Fixes: e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")
> Signed-off-by: John Ogness <[email protected]>

Reviewed-by: Petr Mladek <[email protected]>

Best Regards,
Petr

2021-01-14 14:20:41

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH] printk: fix kmsg_dump_get_buffer length calulations

On (21/01/13 17:50), John Ogness wrote:
>
> kmsg_dump_get_buffer() uses @syslog to determine if the syslog
> prefix should be written to the buffer. However, when calculating
> the maximum number of records that can fit into the buffer, it
> always counts the bytes from the syslog prefix.
>
> Use @syslog when calculating the maximum number of records that can
> fit into the buffer.
>
> Fixes: e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")
> Signed-off-by: John Ogness <[email protected]>

Acked-by: Sergey Senozhatsky <[email protected]>

-ss

2021-01-15 11:33:25

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] printk: fix kmsg_dump_get_buffer length calulations

On Wed 2021-01-13 17:50:13, John Ogness wrote:
> kmsg_dump_get_buffer() uses @syslog to determine if the syslog
> prefix should be written to the buffer. However, when calculating
> the maximum number of records that can fit into the buffer, it
> always counts the bytes from the syslog prefix.
>
> Use @syslog when calculating the maximum number of records that can
> fit into the buffer.
>
> Fixes: e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")
> Signed-off-by: John Ogness <[email protected]>

The patch is committed in printk/linux.git, branch printk-rework.

I plan to send it for-5.11 the following week after it spends
few days in linux-next.

Best Regards,
Petr