@@ -286,6 +286,7 @@ enum {
286
286
#define UBIFS_IDX_NODE_SZ sizeof(struct ubifs_idx_node)
287
287
#define UBIFS_CS_NODE_SZ sizeof(struct ubifs_cs_node)
288
288
#define UBIFS_ORPH_NODE_SZ sizeof(struct ubifs_orph_node)
289
+ #define UBIFS_AUTH_NODE_SZ sizeof(struct ubifs_auth_node)
289
290
/* Extended attribute entry nodes are identical to directory entry nodes */
290
291
#define UBIFS_XENT_NODE_SZ UBIFS_DENT_NODE_SZ
291
292
/* Only this does not have to be multiple of 8 bytes */
@@ -300,6 +301,12 @@ enum {
300
301
/* The largest UBIFS node */
301
302
#define UBIFS_MAX_NODE_SZ UBIFS_MAX_INO_NODE_SZ
302
303
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
+
303
310
/*
304
311
* xattr name of UBIFS encryption context, we don't use a prefix
305
312
* nor a long name to not waste space on the flash.
@@ -365,6 +372,7 @@ enum {
365
372
* UBIFS_IDX_NODE: index node
366
373
* UBIFS_CS_NODE: commit start node
367
374
* UBIFS_ORPH_NODE: orphan node
375
+ * UBIFS_AUTH_NODE: authentication node
368
376
* UBIFS_NODE_TYPES_CNT: count of supported node types
369
377
*
370
378
* Note, we index arrays by these numbers, so keep them low and contiguous.
@@ -384,6 +392,7 @@ enum {
384
392
UBIFS_IDX_NODE ,
385
393
UBIFS_CS_NODE ,
386
394
UBIFS_ORPH_NODE ,
395
+ UBIFS_AUTH_NODE ,
387
396
UBIFS_NODE_TYPES_CNT ,
388
397
};
389
398
@@ -421,15 +430,19 @@ enum {
421
430
* UBIFS_FLG_DOUBLE_HASH: store a 32bit cookie in directory entry nodes to
422
431
* support 64bit cookies for lookups by hash
423
432
* UBIFS_FLG_ENCRYPTION: this filesystem contains encrypted files
433
+ * UBIFS_FLG_AUTHENTICATION: this filesystem contains hashes for authentication
424
434
*/
425
435
enum {
426
436
UBIFS_FLG_BIGLPT = 0x02 ,
427
437
UBIFS_FLG_SPACE_FIXUP = 0x04 ,
428
438
UBIFS_FLG_DOUBLE_HASH = 0x08 ,
429
439
UBIFS_FLG_ENCRYPTION = 0x10 ,
440
+ UBIFS_FLG_AUTHENTICATION = 0x20 ,
430
441
};
431
442
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)
433
446
434
447
/**
435
448
* struct ubifs_ch - common header node.
@@ -633,6 +646,10 @@ struct ubifs_pad_node {
633
646
* @time_gran: time granularity in nanoseconds
634
647
* @uuid: UUID generated when the file system image was created
635
648
* @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)
636
653
*/
637
654
struct ubifs_sb_node {
638
655
struct ubifs_ch ch ;
@@ -660,7 +677,10 @@ struct ubifs_sb_node {
660
677
__le32 time_gran ;
661
678
__u8 uuid [16 ];
662
679
__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 ];
664
684
} __packed ;
665
685
666
686
/**
@@ -695,6 +715,9 @@ struct ubifs_sb_node {
695
715
* @empty_lebs: number of empty logical eraseblocks
696
716
* @idx_lebs: number of indexing logical eraseblocks
697
717
* @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
698
721
* @padding: reserved for future, zeroes
699
722
*/
700
723
struct ubifs_mst_node {
@@ -727,7 +750,10 @@ struct ubifs_mst_node {
727
750
__le32 empty_lebs ;
728
751
__le32 idx_lebs ;
729
752
__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 ];
731
757
} __packed ;
732
758
733
759
/**
@@ -746,12 +772,26 @@ struct ubifs_ref_node {
746
772
__u8 padding [28 ];
747
773
} __packed ;
748
774
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
+
749
785
/**
750
786
* struct ubifs_branch - key/reference/length branch
751
787
* @lnum: LEB number of the target node
752
788
* @offs: offset within @lnum
753
789
* @len: target node length
754
790
* @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.
755
795
*/
756
796
struct ubifs_branch {
757
797
__le32 lnum ;
0 commit comments