Skip to content

Commit fe75a21

Browse files
committed
Merge tag 'for-5.11/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - Fix DM integrity crash if "recalculate" used without "internal_hash" - Fix DM integrity "recalculate" support to prevent recalculating checksums if we use internal_hash or journal_hash with a key (e.g. HMAC). Use of crypto as a means to prevent malicious corruption requires further changes and was never a design goal for dm-integrity's primary usecase of detecting accidental corruption. - Fix a benign dm-crypt copy-and-paste bug introduced as part of a fix that was merged for 5.11-rc4. - Fix DM core's dm_get_device() to avoid filesystem lookup to get block device (if possible). * tag 'for-5.11/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm: avoid filesystem lookup in dm_get_dev_t() dm crypt: fix copy and paste bug in crypt_alloc_req_aead dm integrity: conditionally disable "recalculate" feature dm integrity: fix a crash if "recalculate" used without "internal_hash"
2 parents faba877 + 809b1e4 commit fe75a21

4 files changed

Lines changed: 54 additions & 11 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,20 @@ bitmap_flush_interval:number
177177
The bitmap flush interval in milliseconds. The metadata buffers
178178
are synchronized when this interval expires.
179179

180+
allow_discards
181+
Allow block discard requests (a.k.a. TRIM) for the integrity device.
182+
Discards are only allowed to devices using internal hash.
183+
180184
fix_padding
181185
Use a smaller padding of the tag area that is more
182186
space-efficient. If this option is not present, large padding is
183187
used - that is for compatibility with older kernels.
184188

185-
allow_discards
186-
Allow block discard requests (a.k.a. TRIM) for the integrity device.
187-
Discards are only allowed to devices using internal hash.
189+
legacy_recalculate
190+
Allow recalculating of volumes with HMAC keys. This is disabled by
191+
default for security reasons - an attacker could modify the volume,
192+
set recalc_sector to zero, and the kernel would not detect the
193+
modification.
188194

189195
The journal mode (D/J), buffer_sectors, journal_watermark, commit_time and
190196
allow_discards can be changed when reloading the target (load an inactive

drivers/md/dm-crypt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,9 @@ static int crypt_alloc_req_skcipher(struct crypt_config *cc,
14811481
static int crypt_alloc_req_aead(struct crypt_config *cc,
14821482
struct convert_context *ctx)
14831483
{
1484-
if (!ctx->r.req) {
1485-
ctx->r.req = mempool_alloc(&cc->req_pool, in_interrupt() ? GFP_ATOMIC : GFP_NOIO);
1486-
if (!ctx->r.req)
1484+
if (!ctx->r.req_aead) {
1485+
ctx->r.req_aead = mempool_alloc(&cc->req_pool, in_interrupt() ? GFP_ATOMIC : GFP_NOIO);
1486+
if (!ctx->r.req_aead)
14871487
return -ENOMEM;
14881488
}
14891489

drivers/md/dm-integrity.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ struct dm_integrity_c {
257257
bool journal_uptodate;
258258
bool just_formatted;
259259
bool recalculate_flag;
260-
bool fix_padding;
261260
bool discard;
261+
bool fix_padding;
262+
bool legacy_recalculate;
262263

263264
struct alg_spec internal_hash_alg;
264265
struct alg_spec journal_crypt_alg;
@@ -386,6 +387,14 @@ static int dm_integrity_failed(struct dm_integrity_c *ic)
386387
return READ_ONCE(ic->failed);
387388
}
388389

390+
static bool dm_integrity_disable_recalculate(struct dm_integrity_c *ic)
391+
{
392+
if ((ic->internal_hash_alg.key || ic->journal_mac_alg.key) &&
393+
!ic->legacy_recalculate)
394+
return true;
395+
return false;
396+
}
397+
389398
static commit_id_t dm_integrity_commit_id(struct dm_integrity_c *ic, unsigned i,
390399
unsigned j, unsigned char seq)
391400
{
@@ -3140,6 +3149,7 @@ static void dm_integrity_status(struct dm_target *ti, status_type_t type,
31403149
arg_count += !!ic->journal_crypt_alg.alg_string;
31413150
arg_count += !!ic->journal_mac_alg.alg_string;
31423151
arg_count += (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0;
3152+
arg_count += ic->legacy_recalculate;
31433153
DMEMIT("%s %llu %u %c %u", ic->dev->name, ic->start,
31443154
ic->tag_size, ic->mode, arg_count);
31453155
if (ic->meta_dev)
@@ -3163,6 +3173,8 @@ static void dm_integrity_status(struct dm_target *ti, status_type_t type,
31633173
}
31643174
if ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0)
31653175
DMEMIT(" fix_padding");
3176+
if (ic->legacy_recalculate)
3177+
DMEMIT(" legacy_recalculate");
31663178

31673179
#define EMIT_ALG(a, n) \
31683180
do { \
@@ -3792,7 +3804,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
37923804
unsigned extra_args;
37933805
struct dm_arg_set as;
37943806
static const struct dm_arg _args[] = {
3795-
{0, 15, "Invalid number of feature args"},
3807+
{0, 16, "Invalid number of feature args"},
37963808
};
37973809
unsigned journal_sectors, interleave_sectors, buffer_sectors, journal_watermark, sync_msec;
37983810
bool should_write_sb;
@@ -3940,6 +3952,8 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
39403952
ic->discard = true;
39413953
} else if (!strcmp(opt_string, "fix_padding")) {
39423954
ic->fix_padding = true;
3955+
} else if (!strcmp(opt_string, "legacy_recalculate")) {
3956+
ic->legacy_recalculate = true;
39433957
} else {
39443958
r = -EINVAL;
39453959
ti->error = "Invalid argument";
@@ -4235,6 +4249,20 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
42354249
r = -ENOMEM;
42364250
goto bad;
42374251
}
4252+
} else {
4253+
if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) {
4254+
ti->error = "Recalculate can only be specified with internal_hash";
4255+
r = -EINVAL;
4256+
goto bad;
4257+
}
4258+
}
4259+
4260+
if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) &&
4261+
le64_to_cpu(ic->sb->recalc_sector) < ic->provided_data_sectors &&
4262+
dm_integrity_disable_recalculate(ic)) {
4263+
ti->error = "Recalculating with HMAC is disabled for security reasons - if you really need it, use the argument \"legacy_recalculate\"";
4264+
r = -EOPNOTSUPP;
4265+
goto bad;
42384266
}
42394267

42404268
ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev,

drivers/md/dm-table.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,23 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
363363
{
364364
int r;
365365
dev_t dev;
366+
unsigned int major, minor;
367+
char dummy;
366368
struct dm_dev_internal *dd;
367369
struct dm_table *t = ti->table;
368370

369371
BUG_ON(!t);
370372

371-
dev = dm_get_dev_t(path);
372-
if (!dev)
373-
return -ENODEV;
373+
if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) {
374+
/* Extract the major/minor numbers */
375+
dev = MKDEV(major, minor);
376+
if (MAJOR(dev) != major || MINOR(dev) != minor)
377+
return -EOVERFLOW;
378+
} else {
379+
dev = dm_get_dev_t(path);
380+
if (!dev)
381+
return -ENODEV;
382+
}
374383

375384
dd = find_device(&t->devices, dev);
376385
if (!dd) {

0 commit comments

Comments
 (0)