Skip to content

Commit 9355a9e

Browse files
Satya Tangiralasnitm
authored andcommitted
dm: support key eviction from keyslot managers of underlying devices
Now that device mapper supports inline encryption, add the ability to evict keys from all underlying devices. When an upper layer requests a key eviction, we simply iterate through all underlying devices and evict that key from each device. Co-developed-by: Eric Biggers <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Satya Tangirala <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent aa6ce87 commit 9355a9e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

block/blk-crypto.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,4 @@ int blk_crypto_evict_key(struct request_queue *q,
409409
*/
410410
return blk_crypto_fallback_evict_key(key);
411411
}
412+
EXPORT_SYMBOL_GPL(blk_crypto_evict_key);

drivers/md/dm-table.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,58 @@ struct dm_keyslot_manager {
12141214
struct mapped_device *md;
12151215
};
12161216

1217+
struct dm_keyslot_evict_args {
1218+
const struct blk_crypto_key *key;
1219+
int err;
1220+
};
1221+
1222+
static int dm_keyslot_evict_callback(struct dm_target *ti, struct dm_dev *dev,
1223+
sector_t start, sector_t len, void *data)
1224+
{
1225+
struct dm_keyslot_evict_args *args = data;
1226+
int err;
1227+
1228+
err = blk_crypto_evict_key(bdev_get_queue(dev->bdev), args->key);
1229+
if (!args->err)
1230+
args->err = err;
1231+
/* Always try to evict the key from all devices. */
1232+
return 0;
1233+
}
1234+
1235+
/*
1236+
* When an inline encryption key is evicted from a device-mapper device, evict
1237+
* it from all the underlying devices.
1238+
*/
1239+
static int dm_keyslot_evict(struct blk_keyslot_manager *ksm,
1240+
const struct blk_crypto_key *key, unsigned int slot)
1241+
{
1242+
struct dm_keyslot_manager *dksm = container_of(ksm,
1243+
struct dm_keyslot_manager,
1244+
ksm);
1245+
struct mapped_device *md = dksm->md;
1246+
struct dm_keyslot_evict_args args = { key };
1247+
struct dm_table *t;
1248+
int srcu_idx;
1249+
int i;
1250+
struct dm_target *ti;
1251+
1252+
t = dm_get_live_table(md, &srcu_idx);
1253+
if (!t)
1254+
return 0;
1255+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1256+
ti = dm_table_get_target(t, i);
1257+
if (!ti->type->iterate_devices)
1258+
continue;
1259+
ti->type->iterate_devices(ti, dm_keyslot_evict_callback, &args);
1260+
}
1261+
dm_put_live_table(md, srcu_idx);
1262+
return args.err;
1263+
}
1264+
1265+
static struct blk_ksm_ll_ops dm_ksm_ll_ops = {
1266+
.keyslot_evict = dm_keyslot_evict,
1267+
};
1268+
12171269
static int device_intersect_crypto_modes(struct dm_target *ti,
12181270
struct dm_dev *dev, sector_t start,
12191271
sector_t len, void *data)
@@ -1270,6 +1322,7 @@ static int dm_table_construct_keyslot_manager(struct dm_table *t)
12701322

12711323
ksm = &dksm->ksm;
12721324
blk_ksm_init_passthrough(ksm);
1325+
ksm->ksm_ll_ops = dm_ksm_ll_ops;
12731326
ksm->max_dun_bytes_supported = UINT_MAX;
12741327
memset(ksm->crypto_modes_supported, 0xFF,
12751328
sizeof(ksm->crypto_modes_supported));

0 commit comments

Comments
 (0)