]> git.baikalelectronics.ru Git - kernel.git/commit
debugfs: fix u32_array race in format_array_alloc
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 21 Sep 2012 18:48:05 +0000 (11:48 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 21 Sep 2012 18:48:05 +0000 (11:48 -0700)
commit8ed79f60cfe3c61da17677681868b859faf4b885
tree2dfeef2f02576933e752d1fb40e21d810e224a58
parentc1d5e2d25ef112e6dc0bf17bd4fa0fb7ab57d6db
debugfs: fix u32_array race in format_array_alloc

The format_array_alloc() function is fundamentally racy, in that it
prints the array twice: once to figure out how much space to allocate
for the buffer, and the second time to actually print out the data.

If any of the array contents changes in between, the allocation size may
be wrong, and the end result may be truncated in odd ways.

Just don't do it.  Allocate a maximum-sized array up-front, and just
format the array contents once.  The only user of the u32_array
interfaces is the Xen spinlock statistics code, and it has 31 entries in
the arrays, so the maximum size really isn't that big, and the end
result is much simpler code without the bug.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/debugfs/file.c