Skip to content

Commit 1f9fc0b

Browse files
Mikulas Patockasnitm
authored andcommitted
dm integrity: use version 2 for separate metadata
Use version "2" in the superblock when data and metadata devices are separate, so that the device is not accidentally read by older kernel version. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 356d9d5 commit 1f9fc0b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/md/dm-integrity.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
*/
4545

4646
#define SB_MAGIC "integrt"
47-
#define SB_VERSION 1
47+
#define SB_VERSION_1 1
48+
#define SB_VERSION_2 2
4849
#define SB_SECTORS 8
4950
#define MAX_SECTORS_PER_BLOCK 8
5051

@@ -414,6 +415,14 @@ static void wraparound_section(struct dm_integrity_c *ic, unsigned *sec_ptr)
414415
*sec_ptr -= ic->journal_sections;
415416
}
416417

418+
static void sb_set_version(struct dm_integrity_c *ic)
419+
{
420+
if (ic->meta_dev)
421+
ic->sb->version = SB_VERSION_2;
422+
else
423+
ic->sb->version = SB_VERSION_1;
424+
}
425+
417426
static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags)
418427
{
419428
struct dm_io_request io_req;
@@ -2432,7 +2441,6 @@ static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sec
24322441

24332442
memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT);
24342443
memcpy(ic->sb->magic, SB_MAGIC, 8);
2435-
ic->sb->version = SB_VERSION;
24362444
ic->sb->integrity_tag_size = cpu_to_le16(ic->tag_size);
24372445
ic->sb->log2_sectors_per_block = __ffs(ic->sectors_per_block);
24382446
if (ic->journal_mac_alg.alg_string)
@@ -2489,6 +2497,8 @@ static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sec
24892497

24902498
ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors);
24912499

2500+
sb_set_version(ic);
2501+
24922502
return 0;
24932503
}
24942504

@@ -3193,7 +3203,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
31933203
should_write_sb = true;
31943204
}
31953205

3196-
if (ic->sb->version != SB_VERSION) {
3206+
if (!ic->sb->version || ic->sb->version > SB_VERSION_2) {
31973207
r = -EINVAL;
31983208
ti->error = "Unknown version";
31993209
goto bad;

0 commit comments

Comments
 (0)