diff options
author | Zhihao Cheng <chengzhihao1@huawei.com> | 2024-11-11 16:37:02 +0800 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2024-11-11 10:32:45 +0100 |
commit | f3dc08f6d88e89262433f0582a7750f6ff6791ae (patch) | |
tree | d88638e383bb5bd7f3ca2ae6f82e0ea2da357096 /ubifs-utils/libubifs/replay.c | |
parent | 711dcc3da36538c0d9d8a75eb33205b6d2708175 (diff) |
ubifs-utils: Adapt recovery subsystem in libubifs
Adapt recovery subsystem(replay.c, recovery.c) in libubifs, compared with
linux kernel implementations:
1. Remove authentication related implementations
(eg. authenticate_sleb_hash), authentication is not supported in fsck
for now.
2. Add explicit type conversions(const char *) to avoid compiling
warnings.
3. Replace implementations of inode_fix_size() with ubifs_assert(0),
authentication is not supported in fsck, so this function won't
be invoked.
4. Remove unused ubifs_clean_lebs() and ubifs_write_rcvrd_mst_node().
5. Adapt fix_unclean_leb/recover_head/fix_size_in_place to ignore
%-EBADMSG, subsequent steps will check nodes in lpt/main area
carefully.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubifs-utils/libubifs/replay.c')
-rw-r--r-- | ubifs-utils/libubifs/replay.c | 90 |
1 files changed, 14 insertions, 76 deletions
diff --git a/ubifs-utils/libubifs/replay.c b/ubifs-utils/libubifs/replay.c index c59d47f..b1d0164 100644 --- a/ubifs-utils/libubifs/replay.c +++ b/ubifs-utils/libubifs/replay.c @@ -20,9 +20,14 @@ * larger is the journal, the more memory its index may consume. */ +#include "linux_err.h" +#include "bitops.h" +#include "kmem.h" #include "ubifs.h" -#include <linux/list_sort.h> -#include <crypto/hash.h> +#include "defs.h" +#include "debug.h" +#include "key.h" +#include "misc.h" /** * struct replay_entry - replay list entry. @@ -485,7 +490,8 @@ int ubifs_validate_entry(struct ubifs_info *c, if (le32_to_cpu(dent->ch.len) != nlen + UBIFS_DENT_NODE_SZ + 1 || dent->type >= UBIFS_ITYPES_CNT || nlen > UBIFS_MAX_NLEN || dent->name[nlen] != 0 || - (key_type == UBIFS_XENT_KEY && strnlen(dent->name, nlen) != nlen) || + (key_type == UBIFS_XENT_KEY && + strnlen((const char *)dent->name, nlen) != nlen) || le64_to_cpu(dent->inum) > MAX_INUM) { ubifs_err(c, "bad %s node", key_type == UBIFS_DENT_KEY ? "directory entry" : "extended attribute entry"); @@ -558,19 +564,6 @@ static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud) return data == 0xFFFFFFFF; } -/* authenticate_sleb_hash is split out for stack usage */ -static int noinline_for_stack -authenticate_sleb_hash(struct ubifs_info *c, - struct shash_desc *log_hash, u8 *hash) -{ - SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm); - - hash_desc->tfm = c->hash_tfm; - - ubifs_shash_copy_state(c, log_hash, hash_desc); - return crypto_shash_final(hash_desc, hash); -} - /** * authenticate_sleb - authenticate one scan LEB * @c: UBIFS file-system description object @@ -588,69 +581,14 @@ authenticate_sleb_hash(struct ubifs_info *c, * that could be authenticated or a negative error code. */ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb, - struct shash_desc *log_hash, int is_last) + __unused struct shash_desc *log_hash, + __unused int is_last) { - int n_not_auth = 0; - struct ubifs_scan_node *snod; - int n_nodes = 0; - int err; - u8 hash[UBIFS_HASH_ARR_SZ]; - u8 hmac[UBIFS_HMAC_ARR_SZ]; - if (!ubifs_authenticated(c)) return sleb->nodes_cnt; - list_for_each_entry(snod, &sleb->nodes, list) { - - n_nodes++; - - if (snod->type == UBIFS_AUTH_NODE) { - struct ubifs_auth_node *auth = snod->node; - - err = authenticate_sleb_hash(c, log_hash, hash); - if (err) - goto out; - - err = crypto_shash_tfm_digest(c->hmac_tfm, hash, - c->hash_len, hmac); - if (err) - goto out; - - err = ubifs_check_hmac(c, auth->hmac, hmac); - if (err) { - err = -EPERM; - goto out; - } - n_not_auth = 0; - } else { - err = crypto_shash_update(log_hash, snod->node, - snod->len); - if (err) - goto out; - n_not_auth++; - } - } - - /* - * A powercut can happen when some nodes were written, but not yet - * the corresponding authentication node. This may only happen on - * the last bud though. - */ - if (n_not_auth) { - if (is_last) { - dbg_mnt("%d unauthenticated nodes found on LEB %d, Ignoring them", - n_not_auth, sleb->lnum); - err = 0; - } else { - dbg_mnt("%d unauthenticated nodes found on non-last LEB %d", - n_not_auth, sleb->lnum); - err = -EPERM; - } - } else { - err = 0; - } -out: - return err ? err : n_nodes - n_not_auth; + // To be implemented + return -EINVAL; } /** @@ -768,7 +706,7 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b) goto out_dump; err = insert_dent(c, lnum, snod->offs, snod->len, hash, - &snod->key, dent->name, + &snod->key, (const char *)dent->name, le16_to_cpu(dent->nlen), snod->sqnum, !le64_to_cpu(dent->inum), &used); break; |