diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-09-07 08:36:43 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2018-10-23 07:48:57 -0400 |
commit | 104115a3eb54e7e804cd4ef1d6426c0b8aaaeb60 (patch) | |
tree | f71f1b6e06ffd7050d2bde6a4c59fc2c109879f7 | |
parent | e158e02ff70038936d374928a5484f16daa4c7d4 (diff) |
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: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r-- | fs/ubifs/sb.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index 7f0967771c9f..ac1ed5ad126d 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c | |||
@@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
87 | __le64 tmp_le64; | 87 | __le64 tmp_le64; |
88 | __le32 tmp_le32; | 88 | __le32 tmp_le32; |
89 | struct timespec64 ts; | 89 | struct timespec64 ts; |
90 | u8 hash[UBIFS_HASH_ARR_SZ]; | ||
90 | u8 hash_lpt[UBIFS_HASH_ARR_SZ]; | 91 | u8 hash_lpt[UBIFS_HASH_ARR_SZ]; |
91 | 92 | ||
92 | /* Some functions called from here depend on the @c->key_len filed */ | 93 | /* 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 | sup_flags |= UBIFS_FLG_BIGLPT; | 178 | sup_flags |= UBIFS_FLG_BIGLPT; |
178 | sup_flags |= UBIFS_FLG_DOUBLE_HASH; | 179 | sup_flags |= UBIFS_FLG_DOUBLE_HASH; |
179 | 180 | ||
181 | if (ubifs_authenticated(c)) { | ||
182 | sup_flags |= UBIFS_FLG_AUTHENTICATION; | ||
183 | sup->hash_algo = cpu_to_le16(c->auth_hash_algo); | ||
184 | err = ubifs_hmac_wkm(c, sup->hmac_wkm); | ||
185 | if (err) | ||
186 | goto out; | ||
187 | } else { | ||
188 | sup->hash_algo = 0xffff; | ||
189 | } | ||
190 | |||
180 | sup->ch.node_type = UBIFS_SB_NODE; | 191 | sup->ch.node_type = UBIFS_SB_NODE; |
181 | sup->key_hash = UBIFS_KEY_HASH_R5; | 192 | sup->key_hash = UBIFS_KEY_HASH_R5; |
182 | sup->flags = cpu_to_le32(sup_flags); | 193 | sup->flags = cpu_to_le32(sup_flags); |
@@ -235,6 +246,7 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
235 | mst->empty_lebs = cpu_to_le32(main_lebs - 2); | 246 | mst->empty_lebs = cpu_to_le32(main_lebs - 2); |
236 | mst->idx_lebs = cpu_to_le32(1); | 247 | mst->idx_lebs = cpu_to_le32(1); |
237 | mst->leb_cnt = cpu_to_le32(c->leb_cnt); | 248 | mst->leb_cnt = cpu_to_le32(c->leb_cnt); |
249 | ubifs_copy_hash(c, hash_lpt, mst->hash_lpt); | ||
238 | 250 | ||
239 | /* Calculate lprops statistics */ | 251 | /* Calculate lprops statistics */ |
240 | tmp64 = main_bytes; | 252 | tmp64 = main_bytes; |
@@ -307,25 +319,33 @@ static int create_default_filesystem(struct ubifs_info *c) | |||
307 | 319 | ||
308 | cs->ch.node_type = UBIFS_CS_NODE; | 320 | cs->ch.node_type = UBIFS_CS_NODE; |
309 | 321 | ||
310 | err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0); | 322 | err = ubifs_write_node_hmac(c, sup, UBIFS_SB_NODE_SZ, 0, 0, |
323 | offsetof(struct ubifs_sb_node, hmac)); | ||
311 | if (err) | 324 | if (err) |
312 | goto out; | 325 | goto out; |
313 | 326 | ||
314 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0); | 327 | err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, |
328 | main_first + DEFAULT_DATA_LEB, 0); | ||
315 | if (err) | 329 | if (err) |
316 | goto out; | 330 | goto out; |
317 | 331 | ||
318 | err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, | 332 | ubifs_node_calc_hash(c, ino, hash); |
319 | 0); | 333 | ubifs_copy_hash(c, hash, ubifs_branch_hash(c, br)); |
334 | |||
335 | err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0); | ||
320 | if (err) | 336 | if (err) |
321 | goto out; | 337 | goto out; |
322 | 338 | ||
323 | err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0); | 339 | ubifs_node_calc_hash(c, idx, hash); |
340 | ubifs_copy_hash(c, hash, mst->hash_root_idx); | ||
341 | |||
342 | err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0, | ||
343 | offsetof(struct ubifs_mst_node, hmac)); | ||
324 | if (err) | 344 | if (err) |
325 | goto out; | 345 | goto out; |
326 | 346 | ||
327 | err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, | 347 | err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, |
328 | main_first + DEFAULT_DATA_LEB, 0); | 348 | 0, offsetof(struct ubifs_mst_node, hmac)); |
329 | if (err) | 349 | if (err) |
330 | goto out; | 350 | goto out; |
331 | 351 | ||