Skip to content

Commit d8fd150

Browse files
konistorvalds
authored andcommitted
nilfs2: fix sanity check of btree level in nilfs_btree_root_broken()
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> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 05836c3 commit d8fd150

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

fs/nilfs2/btree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static int nilfs_btree_root_broken(const struct nilfs_btree_node *node,
388388
nchildren = nilfs_btree_node_get_nchildren(node);
389389

390390
if (unlikely(level < NILFS_BTREE_LEVEL_NODE_MIN ||
391-
level > NILFS_BTREE_LEVEL_MAX ||
391+
level >= NILFS_BTREE_LEVEL_MAX ||
392392
nchildren < 0 ||
393393
nchildren > NILFS_BTREE_ROOT_NCHILDREN_MAX)) {
394394
pr_crit("NILFS: bad btree root (inode number=%lu): level = %d, flags = 0x%x, nchildren = %d\n",

include/linux/nilfs2_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ struct nilfs_btree_node {
460460
/* level */
461461
#define NILFS_BTREE_LEVEL_DATA 0
462462
#define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
463-
#define NILFS_BTREE_LEVEL_MAX 14
463+
#define NILFS_BTREE_LEVEL_MAX 14 /* Max level (exclusive) */
464464

465465
/**
466466
* struct nilfs_palloc_group_desc - block group descriptor

0 commit comments

Comments
 (0)