Re: [PATCH 3/3] ubifs: check node hash calculation errors
From: Zhihao Cheng
Date: Mon Nov 02 2026 - 09:11:38 EST
在 2026/11/2 20:14, shao.mingyin@xxxxxxxxxx 写道:
ubifs_node_calc_hash() can fail when authentication is enabled and theReviewed-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
crypto operation fails. Five calls ignore the return value and use the
uninitialized stack buffer as the node hash: replay_bud() stores it in
the replay entry, make_idx_node() and write_index() copy it into the
parent branch or the index root, and create_default_filesystem() copies
it into an index branch and into the master node. Verifying those nodes
later then fails with a hash mismatch.
Propagate the error from all five call sites.
Fixes: 16a26b20d2af ("ubifs: authentication: Add hashes to index nodes")
Fixes: 104115a3eb54 ("ubifs: Add hashes and HMACs to default filesystem")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index 263045e05cf1..442493dc18c6 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -730,7 +730,9 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b)
goto out_dump;
}
- ubifs_node_calc_hash(c, snod->node, hash);
+ err = ubifs_node_calc_hash(c, snod->node, hash);
+ if (err)
+ goto out;
if (snod->sqnum > c->max_sqnum)
c->max_sqnum = snod->sqnum;
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c
index e7693b94e5b5..1c176be261e0 100644
--- a/fs/ubifs/sb.c
+++ b/fs/ubifs/sb.c
@@ -329,14 +329,18 @@ static int create_default_filesystem(struct ubifs_info *c)
if (err)
goto out;
- ubifs_node_calc_hash(c, ino, hash);
+ err = ubifs_node_calc_hash(c, ino, hash);
+ if (err)
+ goto out;
ubifs_copy_hash(c, hash, ubifs_branch_hash(c, br));
err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0);
if (err)
goto out;
- ubifs_node_calc_hash(c, idx, hash);
+ err = ubifs_node_calc_hash(c, idx, hash);
+ if (err)
+ goto out;
ubifs_copy_hash(c, hash, mst->hash_root_idx);
err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0,
diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c
index 7bf2672062a2..1a62739c3731 100644
--- a/fs/ubifs/tnc_commit.c
+++ b/fs/ubifs/tnc_commit.c
@@ -52,7 +52,9 @@ static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx,
}
}
ubifs_prepare_node(c, idx, len, 0);
- ubifs_node_calc_hash(c, idx, hash);
+ err = ubifs_node_calc_hash(c, idx, hash);
+ if (err)
+ return err;
znode->lnum = lnum;
znode->offs = offs;
@@ -887,7 +889,9 @@ static int write_index(struct ubifs_info *c)
}
len = ubifs_idx_node_sz(c, znode->child_cnt);
ubifs_prepare_node(c, idx, len, 0);
- ubifs_node_calc_hash(c, idx, hash);
+ err = ubifs_node_calc_hash(c, idx, hash);
+ if (err)
+ return err;
mutex_lock(&c->tnc_mutex);
.