vmcoreinfo: warn if we exceed vmcoreinfo data size
authorStephen Brennan <stephen.s.brennan@oracle.com>
Thu, 27 Oct 2022 20:50:08 +0000 (13:50 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 1 Dec 2022 00:13:17 +0000 (16:13 -0800)
Though vmcoreinfo is intended to be small, at just one page, useful
information is still added to it, so we risk running out of space.
Currently there is no runtime check to see whether the vmcoreinfo buffer
has been exhausted.  Add a warning for this case.

Currently, my static checking tool[1] indicates that a good upper bound
for vmcoreinfo size is currently 3415 bytes, but the best time to add
warnings is before the risk becomes too high.

[1] https://github.com/brenns10/kernel_stuff/blob/master/vmcoreinfosize/vmcoreinfosize.py

Link: https://lkml.kernel.org/r/20221027205008.312534-1-stephen.s.brennan@oracle.com
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/crash_core.c

index a0eb4d5cf557717b500d69270b4dfb1201cefea8..87ef6096823f3a370c84c23059f9bb4df0155882 100644 (file)
@@ -383,6 +383,9 @@ void vmcoreinfo_append_str(const char *fmt, ...)
        memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r);
 
        vmcoreinfo_size += r;
+
+       WARN_ONCE(vmcoreinfo_size == VMCOREINFO_BYTES,
+                 "vmcoreinfo data exceeds allocated size, truncating");
 }
 
 /*