Skip to content

Commit d8a2277

Browse files
saschahauerrichardweinberger
authored andcommitted
ubifs: Enable authentication support
With the preparations all being done this patch now enables authentication support for UBIFS. Authentication is enabled when the newly introduced auth_key and auth_hash_name mount options are passed. auth_key provides the key which is used for authentication whereas auth_hash_name provides the hashing algorithm used for this FS. Passing these options make authentication mandatory and only UBIFS images that can be authenticated with the given key are allowed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 1e76592 commit d8a2277

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Documentation/filesystems/ubifs.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ chk_data_crc do not skip checking CRCs on data nodes
9191
compr=none override default compressor and set it to "none"
9292
compr=lzo override default compressor and set it to "lzo"
9393
compr=zlib override default compressor and set it to "zlib"
94+
auth_key= specify the key used for authenticating the filesystem.
95+
Passing this option makes authentication mandatory.
96+
The passed key must be present in the kernel keyring
97+
and must be of type 'logon'
98+
auth_hash_name= The hash algorithm used for authentication. Used for
99+
both hashing and for creating HMACs. Typical values
100+
include "sha256" or "sha512"
94101

95102

96103
Quick usage instructions

fs/ubifs/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,13 @@ config UBIFS_FS_SECURITY
8686
the extended attribute support in advance.
8787

8888
If you are not using a security module, say N.
89+
90+
config UBIFS_FS_AUTHENTICATION
91+
bool "UBIFS authentication support"
92+
select CRYPTO_HMAC
93+
help
94+
Enable authentication support for UBIFS. This feature offers protection
95+
against offline changes for both data and metadata of the filesystem.
96+
If you say yes here you should also select a hashing algorithm such as
97+
sha256, these are not selected automatically since there are many
98+
different options.

fs/ubifs/super.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ 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;
582+
c->ranges[UBIFS_AUTH_NODE].min_len = UBIFS_AUTH_NODE_SZ;
583+
c->ranges[UBIFS_AUTH_NODE].max_len = UBIFS_AUTH_NODE_SZ +
584+
UBIFS_MAX_HMAC_LEN;
583585

584586
c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ;
585587
c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ;
@@ -935,6 +937,8 @@ static int check_volume_empty(struct ubifs_info *c)
935937
* Opt_no_chk_data_crc: do not check CRCs when reading data nodes
936938
* Opt_override_compr: override default compressor
937939
* Opt_assert: set ubifs_assert() action
940+
* Opt_auth_key: The key name used for authentication
941+
* Opt_auth_hash_name: The hash type used for authentication
938942
* Opt_err: just end of array marker
939943
*/
940944
enum {
@@ -946,6 +950,8 @@ enum {
946950
Opt_no_chk_data_crc,
947951
Opt_override_compr,
948952
Opt_assert,
953+
Opt_auth_key,
954+
Opt_auth_hash_name,
949955
Opt_ignore,
950956
Opt_err,
951957
};
@@ -958,6 +964,8 @@ static const match_table_t tokens = {
958964
{Opt_chk_data_crc, "chk_data_crc"},
959965
{Opt_no_chk_data_crc, "no_chk_data_crc"},
960966
{Opt_override_compr, "compr=%s"},
967+
{Opt_auth_key, "auth_key=%s"},
968+
{Opt_auth_hash_name, "auth_hash_name=%s"},
961969
{Opt_ignore, "ubi=%s"},
962970
{Opt_ignore, "vol=%s"},
963971
{Opt_assert, "assert=%s"},
@@ -1081,6 +1089,16 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
10811089
kfree(act);
10821090
break;
10831091
}
1092+
case Opt_auth_key:
1093+
c->auth_key_name = kstrdup(args[0].from, GFP_KERNEL);
1094+
if (!c->auth_key_name)
1095+
return -ENOMEM;
1096+
break;
1097+
case Opt_auth_hash_name:
1098+
c->auth_hash_name = kstrdup(args[0].from, GFP_KERNEL);
1099+
if (!c->auth_hash_name)
1100+
return -ENOMEM;
1101+
break;
10841102
case Opt_ignore:
10851103
break;
10861104
default:
@@ -1260,6 +1278,19 @@ static int mount_ubifs(struct ubifs_info *c)
12601278

12611279
c->mounting = 1;
12621280

1281+
if (c->auth_key_name) {
1282+
if (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) {
1283+
err = ubifs_init_authentication(c);
1284+
if (err)
1285+
goto out_free;
1286+
} else {
1287+
ubifs_err(c, "auth_key_name, but UBIFS is built without"
1288+
" authentication support");
1289+
err = -EINVAL;
1290+
goto out_free;
1291+
}
1292+
}
1293+
12631294
err = ubifs_read_superblock(c);
12641295
if (err)
12651296
goto out_free;
@@ -1577,7 +1608,10 @@ static void ubifs_umount(struct ubifs_info *c)
15771608
free_wbufs(c);
15781609
free_orphans(c);
15791610
ubifs_lpt_free(c, 0);
1611+
ubifs_exit_authentication(c);
15801612

1613+
kfree(c->auth_key_name);
1614+
kfree(c->auth_hash_name);
15811615
kfree(c->cbuf);
15821616
kfree(c->rcvrd_mst_node);
15831617
kfree(c->mst_node);

0 commit comments

Comments
 (0)