Skip to content

Commit f6d7acc

Browse files
richardweinbergergregkh
authored andcommitted
ubifs: Check data node size before truncate
commit 95a22d2 upstream. Check whether the size is within bounds before using it. If the size is not correct, abort and dump the bad data node. Cc: Kees Cook <[email protected]> Cc: Silvio Cesare <[email protected]> Cc: [email protected] Fixes: 1e51764 ("UBIFS: add new flash file system") Reported-by: Silvio Cesare <[email protected]> Signed-off-by: Richard Weinberger <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Richard Weinberger <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3259dd7 commit f6d7acc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/ubifs/journal.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,16 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
13881388
else if (err)
13891389
goto out_free;
13901390
else {
1391-
if (le32_to_cpu(dn->size) <= dlen)
1391+
int dn_len = le32_to_cpu(dn->size);
1392+
1393+
if (dn_len <= 0 || dn_len > UBIFS_BLOCK_SIZE) {
1394+
ubifs_err(c, "bad data node (block %u, inode %lu)",
1395+
blk, inode->i_ino);
1396+
ubifs_dump_node(c, dn);
1397+
goto out_free;
1398+
}
1399+
1400+
if (dn_len <= dlen)
13921401
dlen = 0; /* Nothing to do */
13931402
else {
13941403
err = truncate_data_node(c, inode, blk, dn, &dlen);

0 commit comments

Comments
 (0)