diff options
author | Richard Weinberger <richard@nod.at> | 2018-07-01 17:20:51 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2018-08-14 18:25:20 -0400 |
commit | 95a22d2084d72ea067d8323cc85677dba5d97cae (patch) | |
tree | 37301d32e351f1ced8060344148bd4d39dff4517 | |
parent | 08acbdd6fd736b90f8d725da5a0de4de2dd6de62 (diff) |
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 <keescook@chromium.org>
Cc: Silvio Cesare <silvio.cesare@gmail.com>
Cc: stable@vger.kernel.org
Fixes: 1e51764a3c2ac ("UBIFS: add new flash file system")
Reported-by: Silvio Cesare <silvio.cesare@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r-- | fs/ubifs/journal.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 1406765c3ef9..cef0d76d490a 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c | |||
@@ -1393,7 +1393,16 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode, | |||
1393 | else if (err) | 1393 | else if (err) |
1394 | goto out_free; | 1394 | goto out_free; |
1395 | else { | 1395 | 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) | ||
1397 | dlen = 0; /* Nothing to do */ | 1406 | dlen = 0; /* Nothing to do */ |
1398 | else { | 1407 | else { |
1399 | err = truncate_data_node(c, inode, blk, dn, &dlen); | 1408 | err = truncate_data_node(c, inode, blk, dn, &dlen); |