Skip to content

Commit 95a22d2

Browse files
ubifs: Check data node size before truncate
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]>
1 parent 08acbdd commit 95a22d2

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
@@ -1393,7 +1393,16 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
13931393
else if (err)
13941394
goto out_free;
13951395
else {
1396-
if (le32_to_cpu(dn->size) <= dlen)
1396+
int dn_len = le32_to_cpu(dn->size);
1397+
1398+
if (dn_len <= 0 || dn_len > UBIFS_BLOCK_SIZE) {
1399+
ubifs_err(c, "bad data node (block %u, inode %lu)",
1400+
blk, inode->i_ino);
1401+
ubifs_dump_node(c, dn);
1402+
goto out_free;
1403+
}
1404+
1405+
if (dn_len <= dlen)
13971406
dlen = 0; /* Nothing to do */
13981407
else {
13991408
err = truncate_data_node(c, inode, blk, dn, &dlen);

0 commit comments

Comments
 (0)