Commit 104115a3 authored by Sascha Hauer's avatar Sascha Hauer Committed by Richard Weinberger

ubifs: Add hashes and HMACs to default filesystem

This patch calculates the necessary hashes and HMACs for the default
filesystem so that the dynamically created default fs can be
authenticated.
Signed-off-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent e158e02f
...@@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c) ...@@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c)
__le64 tmp_le64; __le64 tmp_le64;
__le32 tmp_le32; __le32 tmp_le32;
struct timespec64 ts; struct timespec64 ts;
u8 hash[UBIFS_HASH_ARR_SZ];
u8 hash_lpt[UBIFS_HASH_ARR_SZ]; u8 hash_lpt[UBIFS_HASH_ARR_SZ];
/* Some functions called from here depend on the @c->key_len filed */ /* Some functions called from here depend on the @c->key_len filed */
...@@ -177,6 +178,16 @@ static int create_default_filesystem(struct ubifs_info *c) ...@@ -177,6 +178,16 @@ static int create_default_filesystem(struct ubifs_info *c)
sup_flags |= UBIFS_FLG_BIGLPT; sup_flags |= UBIFS_FLG_BIGLPT;
sup_flags |= UBIFS_FLG_DOUBLE_HASH; sup_flags |= UBIFS_FLG_DOUBLE_HASH;
if (ubifs_authenticated(c)) {
sup_flags |= UBIFS_FLG_AUTHENTICATION;
sup->hash_algo = cpu_to_le16(c->auth_hash_algo);
err = ubifs_hmac_wkm(c, sup->hmac_wkm);
if (err)
goto out;
} else {
sup->hash_algo = 0xffff;
}
sup->ch.node_type = UBIFS_SB_NODE; sup->ch.node_type = UBIFS_SB_NODE;
sup->key_hash = UBIFS_KEY_HASH_R5; sup->key_hash = UBIFS_KEY_HASH_R5;
sup->flags = cpu_to_le32(sup_flags); sup->flags = cpu_to_le32(sup_flags);
...@@ -235,6 +246,7 @@ static int create_default_filesystem(struct ubifs_info *c) ...@@ -235,6 +246,7 @@ static int create_default_filesystem(struct ubifs_info *c)
mst->empty_lebs = cpu_to_le32(main_lebs - 2); mst->empty_lebs = cpu_to_le32(main_lebs - 2);
mst->idx_lebs = cpu_to_le32(1); mst->idx_lebs = cpu_to_le32(1);
mst->leb_cnt = cpu_to_le32(c->leb_cnt); mst->leb_cnt = cpu_to_le32(c->leb_cnt);
ubifs_copy_hash(c, hash_lpt, mst->hash_lpt);
/* Calculate lprops statistics */ /* Calculate lprops statistics */
tmp64 = main_bytes; tmp64 = main_bytes;
...@@ -307,25 +319,33 @@ static int create_default_filesystem(struct ubifs_info *c) ...@@ -307,25 +319,33 @@ static int create_default_filesystem(struct ubifs_info *c)
cs->ch.node_type = UBIFS_CS_NODE; cs->ch.node_type = UBIFS_CS_NODE;
err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0); err = ubifs_write_node_hmac(c, sup, UBIFS_SB_NODE_SZ, 0, 0,
offsetof(struct ubifs_sb_node, hmac));
if (err) if (err)
goto out; goto out;
err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0); err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ,
main_first + DEFAULT_DATA_LEB, 0);
if (err) if (err)
goto out; goto out;
err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, ubifs_node_calc_hash(c, ino, hash);
0); 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) if (err)
goto out; goto out;
err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0); ubifs_node_calc_hash(c, idx, hash);
ubifs_copy_hash(c, hash, mst->hash_root_idx);
err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0,
offsetof(struct ubifs_mst_node, hmac));
if (err) if (err)
goto out; goto out;
err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1,
main_first + DEFAULT_DATA_LEB, 0); 0, offsetof(struct ubifs_mst_node, hmac));
if (err) if (err)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment