From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: richard@nod.at, david@sigma-star.at, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] ubifs: Harden ubifs_jnl_write_inode()
Date: Fri, 22 Jan 2021 22:22:29 +0100 [thread overview]
Message-ID: <20210122212229.17072-5-richard@nod.at> (raw)
In-Reply-To: <20210122212229.17072-1-richard@nod.at>
Make sure that ubifs_jnl_write_inode() cannot be abused and will
not write less data then expected.
Signed-off-by: Richard Weinberger <richard@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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2021-01-22 21:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-22 21:22 [PATCH 0/4] Assorted UBIFS fixes Richard Weinberger
2021-01-22 21:22 ` [PATCH 1/4] ubifs: Correctly set inode size in ubifs_link() Richard Weinberger
2021-01-23 2:35 ` Zhihao Cheng
2021-01-22 21:22 ` [PATCH 2/4] ubifs: Don't add fscrypt context to xattrs Richard Weinberger
2021-01-22 21:22 ` [PATCH 3/4] ubifs: Update directory size when creating whiteouts Richard Weinberger
2021-01-23 2:45 ` Zhihao Cheng
2021-01-23 10:05 ` Richard Weinberger
2021-01-25 1:05 ` Zhihao Cheng
2021-01-25 7:55 ` Richard Weinberger
2021-01-25 9:31 ` Zhihao Cheng
2021-01-22 21:22 ` Richard Weinberger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210122212229.17072-5-richard@nod.at \
--to=richard@nod.at \
--cc=david@sigma-star.at \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox