[PATCH 12/12] driver core: numa: fix BUILD_BUG_ON for node_read_distance

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg Kroah-Hartman
Date: Friday, March 19, 2010 - 8:18 am

From: David Rientjes <rientjes@google.com>

node_read_distance() has a BUILD_BUG_ON() to prevent buffer overruns when
the number of nodes printed will exceed the buffer length.

Each node only needs four chars: three for distance (maximum distance is
255) and one for a seperating space or a trailing newline.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/node.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index ad43185..93b3ac6 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -165,8 +165,11 @@ static ssize_t node_read_distance(struct sys_device * dev,
 	int len = 0;
 	int i;
 
-	/* buf currently PAGE_SIZE, need ~4 chars per node */
-	BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2);
+	/*
+	 * buf is currently PAGE_SIZE in length and each node needs 4 chars
+	 * at the most (distance + space or newline).
+	 */
+	BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE);
 
 	for_each_online_node(i)
 		len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
-- 
1.7.0.2

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PATCH] driver core fixes for 2.6.34-git, Greg KH, (Fri Mar 19, 8:13 am)
[PATCH 01/12] sysfs: use sysfs_bin_attr_init in firmware c ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 02/12] sysfs: Initialised pci bus legacy_mem field ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 03/12] sysfs: fix sysfs lockdep warning in ipmi code, Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 04/12] sysfs: fix sysfs lockdep warning in infiniba ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 05/12] sysfs: fix sysfs lockdep warning in mlx4 code, Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 06/12] Driver core: Early platform kernel-doc update, Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 07/12] driver-core: fix missing kernel-doc in firmw ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 08/12] kobject: documentation: Fix erroneous exampl ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 09/12] sysdev: the cpu probe/release attributes sho ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 10/12] kobject: documentation: Update to refer to k ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 11/12] driver-core: document ERR_PTR() return values, Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)
[PATCH 12/12] driver core: numa: fix BUILD_BUG_ON for node ..., Greg Kroah-Hartman, (Fri Mar 19, 8:18 am)