Skip to content

Commit 363880c

Browse files
a3fsnitm
authored andcommitted
dm crypt: support using trusted keys
Commit 27f5411 ("dm crypt: support using encrypted keys") extended dm-crypt to allow use of "encrypted" keys along with "user" and "logon". Along the same lines, teach dm-crypt to support "trusted" keys as well. Signed-off-by: Ahmad Fatoum <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 831475c commit 363880c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Documentation/admin-guide/device-mapper/dm-crypt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Parameters::
6767
the value passed in <key_size>.
6868

6969
<key_type>
70-
Either 'logon', 'user' or 'encrypted' kernel key type.
70+
Either 'logon', 'user', 'encrypted' or 'trusted' kernel key type.
7171

7272
<key_description>
7373
The kernel keyring key description crypt target should look for

drivers/md/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ config DM_CRYPT
270270
tristate "Crypt target support"
271271
depends on BLK_DEV_DM
272272
depends on (ENCRYPTED_KEYS || ENCRYPTED_KEYS=n)
273+
depends on (TRUSTED_KEYS || TRUSTED_KEYS=n)
273274
select CRYPTO
274275
select CRYPTO_CBC
275276
select CRYPTO_ESSIV

drivers/md/dm-crypt.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/key-type.h>
3838
#include <keys/user-type.h>
3939
#include <keys/encrypted-type.h>
40+
#include <keys/trusted-type.h>
4041

4142
#include <linux/device-mapper.h>
4243

@@ -2452,6 +2453,22 @@ static int set_key_encrypted(struct crypt_config *cc, struct key *key)
24522453
return 0;
24532454
}
24542455

2456+
static int set_key_trusted(struct crypt_config *cc, struct key *key)
2457+
{
2458+
const struct trusted_key_payload *tkp;
2459+
2460+
tkp = key->payload.data[0];
2461+
if (!tkp)
2462+
return -EKEYREVOKED;
2463+
2464+
if (cc->key_size != tkp->key_len)
2465+
return -EINVAL;
2466+
2467+
memcpy(cc->key, tkp->key, cc->key_size);
2468+
2469+
return 0;
2470+
}
2471+
24552472
static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string)
24562473
{
24572474
char *new_key_string, *key_desc;
@@ -2484,6 +2501,10 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
24842501
!strncmp(key_string, "encrypted:", key_desc - key_string + 1)) {
24852502
type = &key_type_encrypted;
24862503
set_key = set_key_encrypted;
2504+
} else if (IS_ENABLED(CONFIG_TRUSTED_KEYS) &&
2505+
!strncmp(key_string, "trusted:", key_desc - key_string + 1)) {
2506+
type = &key_type_trusted;
2507+
set_key = set_key_trusted;
24872508
} else {
24882509
return -EINVAL;
24892510
}
@@ -3555,7 +3576,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
35553576

35563577
static struct target_type crypt_target = {
35573578
.name = "crypt",
3558-
.version = {1, 22, 0},
3579+
.version = {1, 23, 0},
35593580
.module = THIS_MODULE,
35603581
.ctr = crypt_ctr,
35613582
.dtr = crypt_dtr,

0 commit comments

Comments
 (0)