Skip to content

Commit b1cbabe

Browse files
committed
Merge tag 'for-7.2/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mikulas Patocka: - small cleanups in dm-vdo, dm-raid, dm-cache, dm-zoned-metadata - rework of dm-ima - introduce dm-inlinecrypt - fix wrong return value in dm-ioctl - fix rcu stall when polling * tag 'for-7.2/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm-zoned-metadata: Use strscpy() to copy device name dm cache: make smq background work limit configurable dm-inlinecrypt: add support for hardware-wrapped keys dm: limit target bio polling to one shot dm-ioctl: report an error if a device has no table dm: add documentation for dm-inlinecrypt target dm-inlinecrypt: add target for inline block device encryption block: export blk-crypto symbols required by dm-inlinecrypt dm-ima: use active table's size if available dm-ima: Fail more gracefully in dm_ima_measure_on_* dm-ima: Handle race between rename and table swap dm-ima: Fix issues with dm_ima_measure_on_device_rename dm-ima: remove new_map from dm_ima_measure_on_device_clear dm-ima: Fix UAF errors and measuring incorrect context dm-ima: don't copy the active table to the inactive table dm-ima: Remove status_flags from dm_ima_measure_on_table_load() dm-ima: remove broken last_target_measured logic dm-ima: remove dm_ima_reset_data() dm-raid: only requeue bios when dm is suspending dm vdo: use get_random_u32() where appropriate
2 parents ba9c792 + 55c99f2 commit b1cbabe

13 files changed

Lines changed: 1201 additions & 304 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
==============
2+
dm-inlinecrypt
3+
==============
4+
5+
Device-Mapper's "inlinecrypt" target provides transparent encryption of block devices
6+
using the inline encryption hardware.
7+
8+
For a more detailed description of inline encryption, see:
9+
https://docs.kernel.org/block/inline-encryption.html
10+
11+
Parameters::
12+
13+
<cipher> <key> <iv_offset> <device path> \
14+
<offset> [<#opt_params> <opt_params>]
15+
16+
<cipher>
17+
Encryption cipher type.
18+
19+
The cipher specifications format is::
20+
21+
cipher
22+
23+
Examples::
24+
25+
aes-xts-plain64
26+
27+
The cipher type corresponds to the encryption modes supported by
28+
inline crypto in the block layer. Currently, only
29+
BLK_ENCRYPTION_MODE_AES_256_XTS (i.e. aes-xts-plain64) is supported.
30+
31+
<key>
32+
Key used for encryption. It is encoded either as a hexadecimal number
33+
or it can be passed as <key_string> prefixed with single colon
34+
character (':') for keys residing in kernel keyring service.
35+
You can only use key sizes that are valid for the selected cipher.
36+
Note that the size in bytes of a valid key must be in bellow range.
37+
38+
[BLK_CRYPTO_KEY_TYPE_RAW, BLK_CRYPTO_KEY_TYPE_HW_WRAPPED]
39+
40+
<key_string>
41+
The kernel keyring key is identified by string in following format:
42+
<key_size>:<keyring_type>:<key_description>.
43+
44+
<key_size>
45+
The encryption key size in bytes. The kernel key payload size must match
46+
the value passed in <key_size>.
47+
48+
<keyring_type>
49+
The type of the key inside the kernel keyring. It can be either 'logon',
50+
or 'trusted' kernel key type.
51+
52+
<key_description>
53+
The kernel keyring key description inlinecrypt target should look for
54+
when loading key of <keyring_type>.
55+
56+
<iv_offset>
57+
The IV offset is a sector count that is added to the sector number
58+
before creating the IV.
59+
60+
<device path>
61+
This is the device that is going to be used as backend and contains the
62+
encrypted data. You can specify it as a path like /dev/xxx or a device
63+
number <major>:<minor>.
64+
65+
<offset>
66+
Starting sector within the device where the encrypted data begins.
67+
68+
<#opt_params>
69+
Number of optional parameters. If there are no optional parameters,
70+
the optional parameters section can be skipped or #opt_params can be zero.
71+
Otherwise #opt_params is the number of following arguments.
72+
73+
Example of optional parameters section:
74+
keytype:raw allow_discards sector_size:4096 iv_large_sectors
75+
76+
<key_type>
77+
The type of the key as seen by the block layer, either standard or
78+
hardware-wrapped. The string is supplied in the table as <keytype:raw>
79+
or <keytype:hw-wrapped>.
80+
81+
allow_discards
82+
Block discard requests (a.k.a. TRIM) are passed through the inlinecrypt
83+
device. The default is to ignore discard requests.
84+
85+
WARNING: Assess the specific security risks carefully before enabling this
86+
option. For example, allowing discards on encrypted devices may lead to
87+
the leak of information about the ciphertext device (filesystem type,
88+
used space etc.) if the discarded blocks can be located easily on the
89+
device later.
90+
91+
sector_size:<bytes>
92+
Use <bytes> as the encryption unit instead of 512 bytes sectors.
93+
This option can be in range 512 - 4096 bytes and must be power of two.
94+
Virtual device will announce this size as a minimal IO and logical sector.
95+
96+
iv_large_sectors
97+
Use <sector_size>-based sector numbers for IV generation instead of
98+
512-byte sectors.
99+
100+
For dm-inlinecrypt, this flag must be specified when <sector_size>
101+
is larger than 512 bytes. The legacy 512-byte-based IV behavior is
102+
not supported.
103+
104+
When specified, if <sector_size> is 4096 bytes, plain64 IV for the
105+
second sector will be 1, and <iv_offset> must be a multiple of
106+
<sector_size> (in 512-byte units).
107+
108+
Example scripts
109+
===============
110+
Currently, dm-inlinecrypt devices must be set up directly using dmsetup.
111+
There is no userspace support yet to integrate dm-inlinecrypt with LUKS
112+
or cryptsetup. In particular, cryptsetup currently only supports
113+
dm-crypt, and cannot be used to create dm-inlinecrypt mappings.
114+
115+
The following examples demonstrate how to create dm-inlinecrypt devices
116+
using dmsetup
117+
118+
::
119+
120+
#!/bin/sh
121+
# Create a inlinecrypt device using dmsetup
122+
dmsetup create inlinecrypt1 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe 0 0 $1 0 1 keytype:raw"
123+
124+
::
125+
126+
#!/bin/sh
127+
# Create a inlinecrypt device using dmsetup when encryption key is stored in keyring service
128+
dmsetup create inlinecrypt2 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 :64:logon:fde:dminlinecrypt_test_key 0 0 $1 0 1 keytype:raw"
129+

Documentation/admin-guide/device-mapper/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Device Mapper
1515
dm-flakey
1616
dm-ima
1717
dm-init
18+
dm-inlinecrypt
1819
dm-integrity
1920
dm-io
2021
dm-log

block/blk-crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void bio_crypt_set_ctx(struct bio *bio, const struct blk_crypto_key *key,
116116

117117
bio->bi_crypt_context = bc;
118118
}
119+
EXPORT_SYMBOL_GPL(bio_crypt_set_ctx);
119120

120121
void __bio_crypt_free_ctx(struct bio *bio)
121122
{
@@ -348,6 +349,7 @@ int blk_crypto_init_key(struct blk_crypto_key *blk_key,
348349

349350
return 0;
350351
}
352+
EXPORT_SYMBOL_GPL(blk_crypto_init_key);
351353

352354
bool blk_crypto_config_supported_natively(struct block_device *bdev,
353355
const struct blk_crypto_config *cfg)
@@ -398,6 +400,7 @@ int blk_crypto_start_using_key(struct block_device *bdev,
398400
}
399401
return blk_crypto_fallback_start_using_mode(key->crypto_cfg.crypto_mode);
400402
}
403+
EXPORT_SYMBOL_GPL(blk_crypto_start_using_key);
401404

402405
/**
403406
* blk_crypto_evict_key() - Evict a blk_crypto_key from a block_device

drivers/md/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ config DM_CRYPT
315315

316316
If unsure, say N.
317317

318+
config DM_INLINECRYPT
319+
tristate "Inline encryption target support"
320+
depends on BLK_DEV_DM
321+
depends on (KEYS || KEYS=n)
322+
depends on BLK_INLINE_ENCRYPTION
323+
help
324+
This device-mapper target is similar to dm-crypt, but it uses the
325+
blk-crypto API instead of the regular crypto API. This allows it to
326+
take advantage of inline encryption hardware such as that commonly
327+
built into UFS host controllers.
328+
318329
config DM_SNAPSHOT
319330
tristate "Snapshot target"
320331
depends on BLK_DEV_DM

drivers/md/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ obj-$(CONFIG_DM_UNSTRIPED) += dm-unstripe.o
5555
obj-$(CONFIG_DM_BUFIO) += dm-bufio.o
5656
obj-$(CONFIG_DM_BIO_PRISON) += dm-bio-prison.o
5757
obj-$(CONFIG_DM_CRYPT) += dm-crypt.o
58+
obj-$(CONFIG_DM_INLINECRYPT) += dm-inlinecrypt.o
5859
obj-$(CONFIG_DM_DELAY) += dm-delay.o
5960
obj-$(CONFIG_DM_DUST) += dm-dust.o
6061
obj-$(CONFIG_DM_FLAKEY) += dm-flakey.o

drivers/md/dm-cache-policy-smq.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121

2222
/*----------------------------------------------------------------*/
2323

24+
/*
25+
* Maximum number of concurrent background work items (promotions,
26+
* demotions, writebacks) that can be queued in the background tracker.
27+
* Tuneable via the module parameter smq_max_background_work.
28+
* Only affects newly created cache devices.
29+
*/
30+
static unsigned int smq_max_background_work = 4096;
31+
module_param(smq_max_background_work, uint, 0644);
32+
MODULE_PARM_DESC(smq_max_background_work, "Max concurrent background work items");
33+
2434
/*
2535
* Safe division functions that return zero on divide by zero.
2636
*/
@@ -1820,7 +1830,7 @@ __smq_create(dm_cblock_t cache_size, sector_t origin_size, sector_t cache_block_
18201830
mq->next_hotspot_period = jiffies;
18211831
mq->next_cache_period = jiffies;
18221832

1823-
mq->bg_work = btracker_create(4096); /* FIXME: hard coded value */
1833+
mq->bg_work = btracker_create(max(1u, smq_max_background_work));
18241834
if (!mq->bg_work)
18251835
goto bad_btracker;
18261836

0 commit comments

Comments
 (0)