pstore: Avoid writing records with zero size
authorYue Hu <huyue2@yulong.com>
Thu, 31 Jan 2019 10:12:46 +0000 (18:12 +0800)
committerKees Cook <keescook@chromium.org>
Tue, 12 Feb 2019 20:09:49 +0000 (12:09 -0800)
Sometimes pstore_console_write() will write records with zero size
to persistent ram zone, which is unnecessary. It will only increase
resource consumption. Also adjust ramoops_write_kmsg_hdr() to have
same logic if memory allocation fails.

Signed-off-by: Yue Hu <huyue2@yulong.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
fs/pstore/platform.c
fs/pstore/ram.c

index 2d1066e..75887a2 100644 (file)
@@ -501,6 +501,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
 {
        struct pstore_record record;
 
+       if (!c)
+               return;
+
        pstore_record_init(&record, psinfo);
        record.type = PSTORE_TYPE_CONSOLE;
 
index 1adb5e3..b2471d4 100644 (file)
@@ -352,8 +352,10 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
                (time64_t)record->time.tv_sec,
                record->time.tv_nsec / 1000,
                record->compressed ? 'C' : 'D');
-       WARN_ON_ONCE(!hdr);
-       len = hdr ? strlen(hdr) : 0;
+       if (WARN_ON_ONCE(!hdr))
+               return 0;
+
+       len = strlen(hdr);
        persistent_ram_write(prz, hdr, len);
        kfree(hdr);