Blame SOURCES/kexec-tools-2.0.15-Limit-the-size-of-vmcore-dmesg.txt-to-2G.patch

0c9820
From 4b23140193c5063438f6c5f1c0ba43f981609bb5 Mon Sep 17 00:00:00 2001
0c9820
From: Lianbo Jiang <lijiang@redhat.com>
0c9820
Date: Mon, 9 Sep 2019 09:48:10 +0800
0c9820
Subject: [PATCH] Limit the size of vmcore-dmesg.txt to 2G
0c9820
0c9820
With some corrupted vmcore files, the vmcore-dmesg.txt file may grow
0c9820
forever till the kdump disk becomes full, and also probably causes
0c9820
the disk error messages as follow:
0c9820
...
0c9820
sd 0:0:0:0: [sda] tag#6 FAILED Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
0c9820
sd 0:0:0:0: [sda] tag#6 CDB: Read(10) 28 00 08 06 4c 98 00 00 08 00
0c9820
blk_update_request: I/O error, dev sda, sector 134630552
0c9820
sd 0:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
0c9820
sd 0:0:0:0: [sda] tag#7 CDB: Read(10) 28 00 08 06 4c 98 00 00 08 00
0c9820
blk_update_request: I/O error, dev sda, sector 134630552
0c9820
...
0c9820
0c9820
If vmcore-dmesg.txt occupies the whole disk, the vmcore can not be
0c9820
saved, this is also a problem.
0c9820
0c9820
Lets limit the size of vmcore-dmesg.txt to avoid such problems.
0c9820
0c9820
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
0c9820
Signed-off-by: Simon Horman <horms@verge.net.au>
0c9820
---
0c9820
 vmcore-dmesg/vmcore-dmesg.c | 10 ++++++++++
0c9820
 1 file changed, 10 insertions(+)
0c9820
0c9820
diff --git a/vmcore-dmesg/vmcore-dmesg.c b/vmcore-dmesg/vmcore-dmesg.c
0c9820
index a8f56dfbe51f..41ab73147155 100644
0c9820
--- a/vmcore-dmesg/vmcore-dmesg.c
0c9820
+++ b/vmcore-dmesg/vmcore-dmesg.c
0c9820
@@ -22,6 +22,9 @@
0c9820
 /* The 32bit and 64bit note headers make it clear we don't care */
0c9820
 typedef Elf32_Nhdr Elf_Nhdr;
0c9820
 
0c9820
+/* stole this macro from kernel printk.c */
0c9820
+#define LOG_BUF_LEN_MAX (uint32_t)(1 << 31)
0c9820
+
0c9820
 static const char *fname;
0c9820
 static Elf64_Ehdr ehdr;
0c9820
 static Elf64_Phdr *phdr;
0c9820
@@ -476,6 +479,13 @@ static int32_t read_file_s32(int fd, uint64_t addr)
0c9820
 static void write_to_stdout(char *buf, unsigned int nr)
0c9820
 {
0c9820
 	ssize_t ret;
0c9820
+	static uint32_t n_bytes = 0;
0c9820
+
0c9820
+	n_bytes += nr;
0c9820
+	if (n_bytes > LOG_BUF_LEN_MAX) {
0c9820
+		fprintf(stderr, "The vmcore-dmesg.txt over 2G in size is not supported.\n");
0c9820
+		exit(53);
0c9820
+	}
0c9820
 
0c9820
 	ret = write(STDOUT_FILENO, buf, nr);
0c9820
 	if (ret != nr) {
0c9820
-- 
0c9820
2.17.1
0c9820