nilfs2: fix potential memory overrun on inode
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Fri, 27 Feb 2015 23:51:56 +0000 (15:51 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 9 May 2015 22:16:21 +0000 (23:16 +0100)
commitdb92697414a6e91bb5c467a02665e7bf91033fd5
treeeb65eff9e95bb125ae8c9e7937f6b5b4cd076d96
parentde067f5e8e22ea1db777aa30174797d92b1d4329
nilfs2: fix potential memory overrun on inode

commit 957ed60b53b519064a54988c4e31e0087e47d091 upstream.

Each inode of nilfs2 stores a root node of a b-tree, and it turned out to
have a memory overrun issue:

Each b-tree node of nilfs2 stores a set of key-value pairs and the number
of them (in "bn_nchildren" member of nilfs_btree_node struct), as well as
a few other "bn_*" members.

Since the value of "bn_nchildren" is used for operations on the key-values
within the b-tree node, it can cause memory access overrun if a large
number is incorrectly set to "bn_nchildren".

For instance, nilfs_btree_node_lookup() function determines the range of
binary search with it, and too large "bn_nchildren" leads
nilfs_btree_node_get_key() in that function to overrun.

As for intermediate b-tree nodes, this is prevented by a sanity check
performed when each node is read from a drive, however, no sanity check
has been done for root nodes stored in inodes.

This patch fixes the issue by adding missing sanity check against b-tree
root nodes so that it's called when on-memory inodes are read from ifile,
inode metadata file.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/nilfs2/btree.c