]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
netconsole: don't drop the last byte of a full-sized message
authorBreno Leitao <leitao@debian.org>
Tue, 16 Jun 2026 16:09:52 +0000 (09:09 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 19 Jun 2026 01:08:41 +0000 (18:08 -0700)
nt->buf is exactly MAX_PRINT_CHUNK bytes, but scnprintf() reserves one
byte for its NUL terminator, so a non-fragmented payload of exactly
MAX_PRINT_CHUNK loses its last byte (emitted as a stray NUL in the
release path). Grow nt->buf to MAX_PRINT_CHUNK + 1 and bound the
scnprintf() calls with sizeof(nt->buf); the transmitted length stays
capped at MAX_PRINT_CHUNK.

Alternatively, nt->buf could be left at MAX_PRINT_CHUNK and the NUL byte
reserved by routing exactly-MAX_PRINT_CHUNK payloads to fragmentation
('len < MAX_PRINT_CHUNK'), at the cost of fragmenting those messages.
But it would look less sane, thus the current approach.

Fixes: c62c0a17f9b7 ("netconsole: Append kernel version to message")
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260616-max_print_chunk-v1-1-8dc125d67083@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netconsole.c

index a159cb293981114f1b80926a69b36340eb53e234..862001d09aa84f4e0c0d7af2a9b146cf3235ecc6 100644 (file)
@@ -190,8 +190,10 @@ struct netconsole_target {
        bool                    extended;
        bool                    release;
        struct netpoll          np;
-       /* protected by target_list_lock */
-       char                    buf[MAX_PRINT_CHUNK];
+       /* protected by target_list_lock; +1 gives scnprintf() room for its
+        * NUL terminator so a full MAX_PRINT_CHUNK payload is not truncated
+        */
+       char                    buf[MAX_PRINT_CHUNK + 1];
        struct work_struct      resume_wq;
 };
 
@@ -1938,7 +1940,7 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt,
        if (release_len) {
                release = init_utsname()->release;
 
-               scnprintf(nt->buf, MAX_PRINT_CHUNK, "%s,%.*s", release,
+               scnprintf(nt->buf, sizeof(nt->buf), "%s,%.*s", release,
                          msg_len, msg);
                msg_len += release_len;
        } else {
@@ -1947,12 +1949,12 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt,
 
        if (userdata)
                msg_len += scnprintf(&nt->buf[msg_len],
-                                    MAX_PRINT_CHUNK - msg_len, "%s",
+                                    sizeof(nt->buf) - msg_len, "%s",
                                     userdata);
 
        if (sysdata)
                msg_len += scnprintf(&nt->buf[msg_len],
-                                    MAX_PRINT_CHUNK - msg_len, "%s",
+                                    sizeof(nt->buf) - msg_len, "%s",
                                     sysdata);
 
        send_udp(nt, nt->buf, msg_len);