OSDN Git Service

nilfs2: fix sanity check of btree level in nilfs_btree_root_broken()
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Tue, 5 May 2015 23:24:00 +0000 (16:24 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 17 May 2015 16:55:06 +0000 (09:55 -0700)
commitd6e5098a4a4ac0ec566e3a471e92062a938afde0
treecba75fd3cd544556327de0b63093aa78390eeacf
parentd3992fd381e49aab649dd1aec87b05baf32cdf6d
nilfs2: fix sanity check of btree level in nilfs_btree_root_broken()

commit d8fd150fe3935e1692bf57c66691e17409ebb9c1 upstream.

The range check for b-tree level parameter in nilfs_btree_root_broken()
is wrong; it accepts the case of "level == NILFS_BTREE_LEVEL_MAX" even
though the level is limited to values in the range of 0 to
(NILFS_BTREE_LEVEL_MAX - 1).

Since the level parameter is read from storage device and used to index
nilfs_btree_path array whose element count is NILFS_BTREE_LEVEL_MAX, it
can cause memory overrun during btree operations if the boundary value
is set to the level parameter on device.

This fixes the broken sanity check and adds a comment to clarify that
the upper bound NILFS_BTREE_LEVEL_MAX is exclusive.

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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nilfs2/btree.c
include/linux/nilfs2_fs.h