ubifs: Check data node size before truncate
authorRichard Weinberger <richard@nod.at>
Sun, 1 Jul 2018 21:20:51 +0000 (23:20 +0200)
committerRichard Weinberger <richard@nod.at>
Tue, 14 Aug 2018 22:25:20 +0000 (00:25 +0200)
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>
fs/ubifs/journal.c

index 1406765c3ef9c6979ccc195d9c64dc0eff8c8562..cef0d76d490aa242b4757cddbc9594e6a3ebcb0d 100644 (file)
@@ -1393,7 +1393,16 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
                else if (err)
                        goto out_free;
                else {
-                       if (le32_to_cpu(dn->size) <= dlen)
+                       int dn_len = le32_to_cpu(dn->size);
+
+                       if (dn_len <= 0 || dn_len > UBIFS_BLOCK_SIZE) {
+                               ubifs_err(c, "bad data node (block %u, inode %lu)",
+                                         blk, inode->i_ino);
+                               ubifs_dump_node(c, dn);
+                               goto out_free;
+                       }
+
+                       if (dn_len <= dlen)
                                dlen = 0; /* Nothing to do */
                        else {
                                err = truncate_data_node(c, inode, blk, dn, &dlen);