Skip to content

Commit 5125cfd

Browse files
saschahauerrichardweinberger
authored andcommitted
ubifs: Format changes for authentication support
This patch adds the changes to the on disk format needed for authentication support. We'll add: * a HMAC covering super block node * a HMAC covering the master node * a hash over the root index node to the master node * a hash over the LPT to the master node * a flag to the filesystem flag indicating the filesystem is authenticated * an authentication node necessary to authenticate the nodes written to the journal heads while they are written. * a HMAC of a well known message to the super block node to be able to check if the correct key is provided And finally, not visible in this patch, nevertheless explained here: * hashes over the referenced child nodes in each branch of a index node Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent fd61500 commit 5125cfd

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

fs/ubifs/debug.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ const char *dbg_ntype(int type)
165165
return "commit start node";
166166
case UBIFS_ORPH_NODE:
167167
return "orphan node";
168+
case UBIFS_AUTH_NODE:
169+
return "auth node";
168170
default:
169171
return "unknown node";
170172
}
@@ -542,6 +544,10 @@ void ubifs_dump_node(const struct ubifs_info *c, const void *node)
542544
(unsigned long long)le64_to_cpu(orph->inos[i]));
543545
break;
544546
}
547+
case UBIFS_AUTH_NODE:
548+
{
549+
break;
550+
}
545551
default:
546552
pr_err("node type %d was not recognized\n",
547553
(int)ch->node_type);

fs/ubifs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ static int init_constants_early(struct ubifs_info *c)
579579
c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ;
580580
c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ;
581581
c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ;
582+
c->ranges[UBIFS_AUTH_NODE].len = UBIFS_AUTH_NODE_SZ;
582583

583584
c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ;
584585
c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ;

fs/ubifs/ubifs-media.h

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ enum {
286286
#define UBIFS_IDX_NODE_SZ sizeof(struct ubifs_idx_node)
287287
#define UBIFS_CS_NODE_SZ sizeof(struct ubifs_cs_node)
288288
#define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node)
289+
#define UBIFS_AUTH_NODE_SZ sizeof(struct ubifs_auth_node)
289290
/* Extended attribute entry nodes are identical to directory entry nodes */
290291
#define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ
291292
/* Only this does not have to be multiple of 8 bytes */
@@ -300,6 +301,12 @@ enum {
300301
/* The largest UBIFS node */
301302
#define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ
302303

304+
/* The maxmimum size of a hash, enough for sha512 */
305+
#define UBIFS_MAX_HASH_LEN 64
306+
307+
/* The maxmimum size of a hmac, enough for hmac(sha512) */
308+
#define UBIFS_MAX_HMAC_LEN 64
309+
303310
/*
304311
* xattr name of UBIFS encryption context, we don't use a prefix
305312
* nor a long name to not waste space on the flash.
@@ -365,6 +372,7 @@ enum {
365372
* UBIFS_IDX_NODE: index node
366373
* UBIFS_CS_NODE: commit start node
367374
* UBIFS_ORPH_NODE: orphan node
375+
* UBIFS_AUTH_NODE: authentication node
368376
* UBIFS_NODE_TYPES_CNT: count of supported node types
369377
*
370378
* Note, we index arrays by these numbers, so keep them low and contiguous.
@@ -384,6 +392,7 @@ enum {
384392
UBIFS_IDX_NODE,
385393
UBIFS_CS_NODE,
386394
UBIFS_ORPH_NODE,
395+
UBIFS_AUTH_NODE,
387396
UBIFS_NODE_TYPES_CNT,
388397
};
389398

@@ -421,15 +430,19 @@ enum {
421430
* UBIFS_FLG_DOUBLE_HASH: store a 32bit cookie in directory entry nodes to
422431
* support 64bit cookies for lookups by hash
423432
* UBIFS_FLG_ENCRYPTION: this filesystem contains encrypted files
433+
* UBIFS_FLG_AUTHENTICATION: this filesystem contains hashes for authentication
424434
*/
425435
enum {
426436
UBIFS_FLG_BIGLPT = 0x02,
427437
UBIFS_FLG_SPACE_FIXUP = 0x04,
428438
UBIFS_FLG_DOUBLE_HASH = 0x08,
429439
UBIFS_FLG_ENCRYPTION = 0x10,
440+
UBIFS_FLG_AUTHENTICATION = 0x20,
430441
};
431442

432-
#define UBIFS_FLG_MASK (UBIFS_FLG_BIGLPT|UBIFS_FLG_SPACE_FIXUP|UBIFS_FLG_DOUBLE_HASH|UBIFS_FLG_ENCRYPTION)
443+
#define UBIFS_FLG_MASK (UBIFS_FLG_BIGLPT | UBIFS_FLG_SPACE_FIXUP | \
444+
UBIFS_FLG_DOUBLE_HASH | UBIFS_FLG_ENCRYPTION | \
445+
UBIFS_FLG_AUTHENTICATION)
433446

434447
/**
435448
* struct ubifs_ch - common header node.
@@ -633,6 +646,10 @@ struct ubifs_pad_node {
633646
* @time_gran: time granularity in nanoseconds
634647
* @uuid: UUID generated when the file system image was created
635648
* @ro_compat_version: UBIFS R/O compatibility version
649+
* @hmac: HMAC to authenticate the superblock node
650+
* @hmac_wkm: HMAC of a well known message (the string "UBIFS") as a convenience
651+
* to the user to check if the correct key is passed.
652+
* @hash_algo: The hash algo used for this filesystem (one of enum hash_algo)
636653
*/
637654
struct ubifs_sb_node {
638655
struct ubifs_ch ch;
@@ -660,7 +677,10 @@ struct ubifs_sb_node {
660677
__le32 time_gran;
661678
__u8 uuid[16];
662679
__le32 ro_compat_version;
663-
__u8 padding2[3968];
680+
__u8 hmac[UBIFS_MAX_HMAC_LEN];
681+
__u8 hmac_wkm[UBIFS_MAX_HMAC_LEN];
682+
__le16 hash_algo;
683+
__u8 padding2[3838];
664684
} __packed;
665685

666686
/**
@@ -695,6 +715,9 @@ struct ubifs_sb_node {
695715
* @empty_lebs: number of empty logical eraseblocks
696716
* @idx_lebs: number of indexing logical eraseblocks
697717
* @leb_cnt: count of LEBs used by file-system
718+
* @hash_root_idx: the hash of the root index node
719+
* @hash_lpt: the hash of the LPT
720+
* @hmac: HMAC to authenticate the master node
698721
* @padding: reserved for future, zeroes
699722
*/
700723
struct ubifs_mst_node {
@@ -727,7 +750,10 @@ struct ubifs_mst_node {
727750
__le32 empty_lebs;
728751
__le32 idx_lebs;
729752
__le32 leb_cnt;
730-
__u8 padding[344];
753+
__u8 hash_root_idx[UBIFS_MAX_HASH_LEN];
754+
__u8 hash_lpt[UBIFS_MAX_HASH_LEN];
755+
__u8 hmac[UBIFS_MAX_HMAC_LEN];
756+
__u8 padding[152];
731757
} __packed;
732758

733759
/**
@@ -746,12 +772,26 @@ struct ubifs_ref_node {
746772
__u8 padding[28];
747773
} __packed;
748774

775+
/**
776+
* struct ubifs_auth_node - node for authenticating other nodes
777+
* @ch: common header
778+
* @hmac: The HMAC
779+
*/
780+
struct ubifs_auth_node {
781+
struct ubifs_ch ch;
782+
__u8 hmac[];
783+
} __packed;
784+
749785
/**
750786
* struct ubifs_branch - key/reference/length branch
751787
* @lnum: LEB number of the target node
752788
* @offs: offset within @lnum
753789
* @len: target node length
754790
* @key: key
791+
*
792+
* In an authenticated UBIFS we have the hash of the referenced node after @key.
793+
* This can't be added to the struct type definition because @key is a
794+
* dynamically sized element already.
755795
*/
756796
struct ubifs_branch {
757797
__le32 lnum;

0 commit comments

Comments
 (0)