summaryrefslogtreecommitdiffstats
path: root/fs/ubifs
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2018-07-01 23:20:51 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-09-09 19:56:00 +0200
commitf6d7acc1d9cae277b0379e8209eaefe59a3fbf79 (patch)
tree07dca588f9469737b5bec4722a855e0b42a96e31 /fs/ubifs
parent3259dd7176e4d98248f2dcc94f540dbca051ff42 (diff)
downloadlinux-stable-f6d7acc1d9cae277b0379e8209eaefe59a3fbf79.tar.gz
linux-stable-f6d7acc1d9cae277b0379e8209eaefe59a3fbf79.tar.bz2
linux-stable-f6d7acc1d9cae277b0379e8209eaefe59a3fbf79.zip
ubifs: Check data node size before truncate
commit 95a22d2084d72ea067d8323cc85677dba5d97cae 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 <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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/ubifs')
-rw-r--r--fs/ubifs/journal.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index 04c4ec6483e5..b2419c855b47 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -1388,7 +1388,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);