[PATCH 4/4] ubifs: Harden ubifs_jnl_write_inode()
Richard Weinberger
richard at nod.at
Fri Jan 22 16:22:29 EST 2021
Make sure that ubifs_jnl_write_inode() cannot be abused and will
not write less data then expected.
Signed-off-by: Richard Weinberger <richard at nod.at>
---
fs/ubifs/journal.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index 03410ae0813a..1b28fcc5b9fe 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -844,10 +844,12 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode)
struct ubifs_ino_node *ino, *ino_start;
struct ubifs_inode *ui = ubifs_inode(inode);
int sync = 0, write_len = 0, ilen = UBIFS_INO_NODE_SZ;
- int last_reference = !inode->i_nlink;
+ int last_reference = !inode->i_nlink, xattr_inos_written = 0;
int kill_xattrs = ui->xattr_cnt && last_reference;
u8 hash[UBIFS_HASH_ARR_SZ];
+ ubifs_assert(c, !ui->xattr);
+
dbg_jnl("ino %lu, nlink %u", inode->i_ino, inode->i_nlink);
/*
@@ -917,12 +919,14 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode)
pack_inode(c, ino, xino, 0);
ino = (void *)ino + UBIFS_INO_NODE_SZ;
iput(xino);
+ xattr_inos_written++;
kfree(pxent);
pxent = xent;
key_read(c, &xent->key, &key);
}
kfree(pxent);
+ ubifs_assert(c, xattr_inos_written == ui->xattr_cnt);
}
pack_inode(c, ino, inode, 1);
--
2.26.2
More information about the linux-mtd
mailing list