[PATCH v2 3/4] ubifs: sprinkle ubifs_assert(c, !c->ro_mount) in hmac auth
Torben Hohn
torben.hohn at linutronix.de
Fri Jun 26 07:29:06 EDT 2020
make sure that the hmac ubifs authentication code, which
uses the hmac is only called, for rw mounts.
This allows to ensure that we are not in the new
read only authentication mode, when the hmac is accessed.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
fs/ubifs/auth.c | 1 +
fs/ubifs/gc.c | 1 +
fs/ubifs/journal.c | 8 ++++++++
fs/ubifs/replay.c | 1 +
fs/ubifs/sb.c | 1 +
fs/ubifs/super.c | 5 +++++
fs/ubifs/ubifs.h | 8 ++++++++
7 files changed, 25 insertions(+)
diff --git a/fs/ubifs/auth.c b/fs/ubifs/auth.c
index 52ce7a2218a5..15a1a18a42ed 100644
--- a/fs/ubifs/auth.c
+++ b/fs/ubifs/auth.c
@@ -570,6 +570,7 @@ int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac)
int err;
const char well_known_message[] = "UBIFS";
+ ubifs_assert(c, !c->ro_mount);
if (!ubifs_authenticated(c))
return 0;
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c
index 62cb3db44e6e..8009ceb362d2 100644
--- a/fs/ubifs/gc.c
+++ b/fs/ubifs/gc.c
@@ -410,6 +410,7 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb)
moved = 1;
}
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c) && moved) {
struct ubifs_auth_node *auth;
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index e5ec1afe1c66..5c23846f2d40 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -80,6 +80,7 @@ static inline void zero_trun_node_unused(struct ubifs_trun_node *trun)
static void ubifs_add_auth_dirt(struct ubifs_info *c, int lnum)
{
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c))
ubifs_add_dirt(c, lnum, ubifs_auth_node_sz(c));
}
@@ -278,7 +279,9 @@ static int write_head(struct ubifs_info *c, int jhead, void *buf, int len,
dbg_jnl("jhead %s, LEB %d:%d, len %d",
dbg_jhead(jhead), *lnum, *offs, len);
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c)) {
+
err = ubifs_hash_nodes(c, buf, len, c->jheads[jhead].log_hash);
if (err)
return err;
@@ -572,6 +575,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
len = aligned_dlen + aligned_ilen + UBIFS_INO_NODE_SZ;
/* Make sure to also account for extended attributes */
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c))
len += ALIGN(host_ui->data_len, 8) + ubifs_auth_node_sz(c);
else
@@ -778,6 +782,8 @@ int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
}
dlen = UBIFS_DATA_NODE_SZ + out_len;
+
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c))
write_len = ALIGN(dlen, 8) + auth_len;
else
@@ -860,6 +866,7 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode)
write_len += UBIFS_INO_NODE_SZ * ui->xattr_cnt;
}
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c))
write_len += ALIGN(ilen, 8) + ubifs_auth_node_sz(c);
else
@@ -1572,6 +1579,7 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
/* Must make reservation before allocating sequence numbers */
len = UBIFS_TRUN_NODE_SZ + UBIFS_INO_NODE_SZ;
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c))
len += ALIGN(dlen, 8) + ubifs_auth_node_sz(c);
else
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index b69ffac7e415..a3a37c196f56 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -595,6 +595,7 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
u8 hash[UBIFS_HASH_ARR_SZ];
u8 hmac[UBIFS_HMAC_ARR_SZ];
+ ubifs_assert(c, !c->ro_mount);
if (!ubifs_authenticated(c))
return sleb->nodes_cnt;
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c
index d898ea5edd7c..c2104235fb56 100644
--- a/fs/ubifs/sb.c
+++ b/fs/ubifs/sb.c
@@ -176,6 +176,7 @@ static int create_default_filesystem(struct ubifs_info *c)
sup_flags |= UBIFS_FLG_BIGLPT;
sup_flags |= UBIFS_FLG_DOUBLE_HASH;
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c)) {
sup_flags |= UBIFS_FLG_AUTHENTICATION;
sup->hash_algo = cpu_to_le16(c->auth_hash_algo);
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 13175da14464..b41ca9ee5763 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -1447,6 +1447,7 @@ static int mount_ubifs(struct ubifs_info *c)
}
if (c->need_recovery) {
+ ubifs_assert(c, !c->ro_mount);
if (!ubifs_authenticated(c)) {
err = ubifs_recover_size(c, true);
if (err)
@@ -1457,6 +1458,7 @@ static int mount_ubifs(struct ubifs_info *c)
if (err)
goto out_orphans;
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c)) {
err = ubifs_recover_size(c, false);
if (err)
@@ -1703,6 +1705,8 @@ static int ubifs_remount_rw(struct ubifs_info *c)
err = ubifs_write_rcvrd_mst_node(c);
if (err)
goto out;
+
+ ubifs_assert(c, !c->ro_mount);
if (!ubifs_authenticated(c)) {
err = ubifs_recover_size(c, true);
if (err)
@@ -1788,6 +1792,7 @@ static int ubifs_remount_rw(struct ubifs_info *c)
if (err)
goto out;
+ ubifs_assert(c, !c->ro_mount);
if (ubifs_authenticated(c)) {
err = ubifs_recover_size(c, false);
if (err)
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 80e2800927ec..79880cf0e1a0 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1650,6 +1650,8 @@ int __ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
static inline int ubifs_node_insert_hmac(const struct ubifs_info *c, void *buf,
int len, int ofs_hmac)
{
+ ubifs_assert(c, !c->ro_mount);
+
if (ubifs_authenticated(c))
return __ubifs_node_insert_hmac(c, buf, len, ofs_hmac);
else
@@ -1661,6 +1663,8 @@ int __ubifs_node_verify_hmac(const struct ubifs_info *c, const void *buf,
static inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
const void *buf, int len, int ofs_hmac)
{
+ ubifs_assert(c, !c->ro_mount);
+
if (ubifs_authenticated(c))
return __ubifs_node_verify_hmac(c, buf, len, ofs_hmac);
else
@@ -1677,6 +1681,8 @@ static inline int ubifs_node_verify_hmac(const struct ubifs_info *c,
*/
static inline int ubifs_auth_node_sz(const struct ubifs_info *c)
{
+ ubifs_assert(c, !c->ro_mount);
+
if (ubifs_authenticated(c))
return sizeof(struct ubifs_auth_node) + c->hmac_desc_len;
else
@@ -1694,6 +1700,8 @@ static inline int ubifs_shash_copy_state(const struct ubifs_info *c,
struct shash_desc *src,
struct shash_desc *target)
{
+ ubifs_assert(c, !c->ro_mount);
+
if (ubifs_authenticated(c))
return __ubifs_shash_copy_state(c, src, target);
else
--
2.20.1
More information about the linux-mtd
mailing list