]> git.ipfire.org Git - thirdparty/util-linux.git/commit
dmesg: fix off-by-one read buffer size
authorBrian Mak <makb@juniper.net>
Thu, 28 May 2026 19:08:04 +0000 (12:08 -0700)
committerBrian Mak <makb@juniper.net>
Fri, 29 May 2026 19:27:10 +0000 (12:27 -0700)
commit01a424f502cf87f4cbd1c88bb10714b9f87154d4
tree4e4c1fcb9262faad2e08f3f90eea288ad7f9e81d
parentd968218c72c6a66d792610cf47a52b79f9bc8363
dmesg: fix off-by-one read buffer size

PRINTK_MESSAGE_MAX is 2048 in the kernel. In a formatted record that is
exactly 2048 bytes, reading /proc/kmsg with a size of PRINTK_MESSAGE_MAX
- 1 (2047) will result in the read syscall returning -EINVAL.

We see such a case when using a large initrd, for which the kernel
outputs loading spinner characters, based on the size of the initrd. For
a large enough initrd, there will be enough spinner characters to create
several formatted records of size 2048.

We fix this by increasing the kmsg_buf size by 1, which increases the
size used by the read syscall to PRINTK_MESSAGE_MAX (2048).

Signed-off-by: Brian Mak <makb@juniper.net>
sys-utils/dmesg.c