Skip to content

Commit

Permalink
driver core: numa: fix BUILD_BUG_ON for node_read_distance
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Rientjes authored and Greg Kroah-Hartman committed Mar 19, 2010
1 parent f0eae0e commit 12ee3c0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/base/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 12ee3c0

Please sign in to comment.