From: Zhihao Cheng <chengzhihao1@huawei.com>
To: <shao.mingyin@zte.com.cn>, <richard@nod.at>,
<linux-mtd@lists.infradead.org>
Cc: <linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH 3/3] ubifs: check node hash calculation errors
Date: Mon, 2 Nov 2026 21:41:43 +0800 [thread overview]
Message-ID: <2bf579ac-cc55-b88a-3ce5-9214d8434909@huawei.com> (raw)
In-Reply-To: <202611022014201140sh13oFtWkIgBr7UQKyMK@zte.com.cn>
在 2026/11/2 20:14, shao.mingyin@zte.com.cn 写道:
> ubifs_node_calc_hash() can fail when authentication is enabled and the
> 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@vger.kernel.org
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> ---
> 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);
> .
>
prev parent reply other threads:[~2026-11-02 13:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 11:50 [PATCH 0/3] ubifs: fix an auth node leak and two error-handling bugs shao.mingyin
2026-11-02 12:12 ` [PATCH 1/3] ubifs: gc: fix authentication node leak shao.mingyin
2026-11-02 12:13 ` [PATCH 2/3] ubifs: xattr: preserve the encryption flag when creation fails shao.mingyin
2026-11-02 12:14 ` [PATCH 3/3] ubifs: check node hash calculation errors shao.mingyin
2026-11-02 13:41 ` Zhihao Cheng [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=2bf579ac-cc55-b88a-3ce5-9214d8434909@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=shao.mingyin@zte.com.cn \
--cc=stable@vger.kernel.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
all inboxes | Powered by JetHome®