]> git.kernelconcepts.de Git - karo-tx-linux.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)
commite05e279e6fc940a2adb9d4d4bf2b814dfc286176
tree2dfeef2f02576933e752d1fb40e21d810e224a58
parent36048853c5257a7b6df346b83758ffa776a59e9f
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