lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181015183841.114341-1-yuzhao@google.com>
Date:   Mon, 15 Oct 2018 12:38:41 -0600
From:   Yu Zhao <yuzhao@...gle.com>
To:     Andrew Morton <akpm@...ux-foundation.org>,
        Michal Hocko <mhocko@...e.com>
Cc:     Jan Kara <jack@...e.cz>, David Rientjes <rientjes@...gle.com>,
        Kemi Wang <kemi.wang@...el.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        Roman Gushchin <guro@...com>,
        Kees Cook <keescook@...omium.org>,
        Jann Horn <jannh@...gle.com>,
        Andrey Ryabinin <aryabinin@...tuozzo.com>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        Yu Zhao <yuzhao@...gle.com>
Subject: [PATCH] mm: detect numbers of vmstat keys/values mismatch

There were mismatches between number of vmstat keys and number of
vmstat values. They were fixed recently by:
  commit 58bc4c34d249 ("mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly")
  commit 28e2c4bb99aa ("mm/vmstat.c: fix outdated vmstat_text")

Add a BUILD_BUG_ON to detect such mismatch and hopefully prevent
it from happening again.

Signed-off-by: Yu Zhao <yuzhao@...gle.com>
---
 include/linux/vmstat.h |  4 ++++
 mm/vmstat.c            | 18 ++++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index f25cef84b41d..33fdd37124cb 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -78,6 +78,10 @@ extern void vm_events_fold_cpu(int cpu);
 
 #else
 
+struct vm_event_state {
+	unsigned long event[0];
+};
+
 /* Disable counters */
 static inline void count_vm_event(enum vm_event_item item)
 {
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 7878da76abf2..7ebf871b4cc9 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1647,23 +1647,21 @@ enum writeback_stat_item {
 	NR_VM_WRITEBACK_STAT_ITEMS,
 };
 
+#define NR_VM_STAT_ITEMS (NR_VM_ZONE_STAT_ITEMS + NR_VM_NUMA_STAT_ITEMS + \
+			  NR_VM_NODE_STAT_ITEMS + NR_VM_WRITEBACK_STAT_ITEMS + \
+			  ARRAY_SIZE(((struct vm_event_state *)0)->event))
+
 static void *vmstat_start(struct seq_file *m, loff_t *pos)
 {
+	int i;
 	unsigned long *v;
-	int i, stat_items_size;
+
+	BUILD_BUG_ON(ARRAY_SIZE(vmstat_text) != NR_VM_STAT_ITEMS);
 
 	if (*pos >= ARRAY_SIZE(vmstat_text))
 		return NULL;
-	stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) +
-			  NR_VM_NUMA_STAT_ITEMS * sizeof(unsigned long) +
-			  NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) +
-			  NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long);
-
-#ifdef CONFIG_VM_EVENT_COUNTERS
-	stat_items_size += sizeof(struct vm_event_state);
-#endif
 
-	v = kmalloc(stat_items_size, GFP_KERNEL);
+	v = kmalloc_array(NR_VM_STAT_ITEMS, sizeof(unsigned long), GFP_KERNEL);
 	m->private = v;
 	if (!v)
 		return ERR_PTR(-ENOMEM);
-- 
2.19.1.331.ge82ca0e54c-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ