Skip to content

Commit 82bb859

Browse files
quitschbosnitm
authored andcommitted
dm integrity: log audit events for dm-integrity target
dm-integrity signals integrity violations by returning I/O errors to user space. To identify integrity violations by a controlling instance, the kernel audit subsystem can be used to emit audit events to user space. We use the new dm-audit submodule allowing to emit audit events on relevant I/O errors. The construction and destruction of integrity device mappings are also relevant for auditing a system. Thus, those events are also logged as audit events. Signed-off-by: Michael Weiß <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 2cc1ae4 commit 82bb859

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

drivers/md/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ config DM_INTEGRITY
610610
select CRYPTO
611611
select CRYPTO_SKCIPHER
612612
select ASYNC_XOR
613+
select DM_AUDIT if AUDIT
613614
help
614615
This device-mapper target emulates a block device that has
615616
additional per-sector tags that can be used for storing

drivers/md/dm-integrity.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <linux/async_tx.h>
2424
#include <linux/dm-bufio.h>
2525

26+
#include "dm-audit.h"
27+
2628
#define DM_MSG_PREFIX "integrity"
2729

2830
#define DEFAULT_INTERLEAVE_SECTORS 32768
@@ -539,6 +541,7 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr)
539541
}
540542
if (memcmp((__u8 *)ic->sb + (1 << SECTOR_SHIFT) - size, result, size)) {
541543
dm_integrity_io_error(ic, "superblock mac", -EILSEQ);
544+
dm_audit_log_target(DM_MSG_PREFIX, "mac-superblock", ic->ti, 0);
542545
return -EILSEQ;
543546
}
544547
}
@@ -876,8 +879,10 @@ static void rw_section_mac(struct dm_integrity_c *ic, unsigned section, bool wr)
876879
if (likely(wr))
877880
memcpy(&js->mac, result + (j * JOURNAL_MAC_PER_SECTOR), JOURNAL_MAC_PER_SECTOR);
878881
else {
879-
if (memcmp(&js->mac, result + (j * JOURNAL_MAC_PER_SECTOR), JOURNAL_MAC_PER_SECTOR))
882+
if (memcmp(&js->mac, result + (j * JOURNAL_MAC_PER_SECTOR), JOURNAL_MAC_PER_SECTOR)) {
880883
dm_integrity_io_error(ic, "journal mac", -EILSEQ);
884+
dm_audit_log_target(DM_MSG_PREFIX, "mac-journal", ic->ti, 0);
885+
}
881886
}
882887
}
883888
}
@@ -1782,10 +1787,15 @@ static void integrity_metadata(struct work_struct *w)
17821787
if (unlikely(r)) {
17831788
if (r > 0) {
17841789
char b[BDEVNAME_SIZE];
1785-
DMERR_LIMIT("%s: Checksum failed at sector 0x%llx", bio_devname(bio, b),
1786-
(sector - ((r + ic->tag_size - 1) / ic->tag_size)));
1790+
sector_t s;
1791+
1792+
s = sector - ((r + ic->tag_size - 1) / ic->tag_size);
1793+
DMERR_LIMIT("%s: Checksum failed at sector 0x%llx",
1794+
bio_devname(bio, b), s);
17871795
r = -EILSEQ;
17881796
atomic64_inc(&ic->number_of_mismatches);
1797+
dm_audit_log_bio(DM_MSG_PREFIX, "integrity-checksum",
1798+
bio, s, 0);
17891799
}
17901800
if (likely(checksums != checksums_onstack))
17911801
kfree(checksums);
@@ -1991,6 +2001,8 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio,
19912001
if (unlikely(memcmp(checksums_onstack, journal_entry_tag(ic, je), ic->tag_size))) {
19922002
DMERR_LIMIT("Checksum failed when reading from journal, at sector 0x%llx",
19932003
logical_sector);
2004+
dm_audit_log_bio(DM_MSG_PREFIX, "journal-checksum",
2005+
bio, logical_sector, 0);
19942006
}
19952007
}
19962008
#endif
@@ -2534,8 +2546,10 @@ static void do_journal_write(struct dm_integrity_c *ic, unsigned write_start,
25342546

25352547
integrity_sector_checksum(ic, sec + ((l - j) << ic->sb->log2_sectors_per_block),
25362548
(char *)access_journal_data(ic, i, l), test_tag);
2537-
if (unlikely(memcmp(test_tag, journal_entry_tag(ic, je2), ic->tag_size)))
2549+
if (unlikely(memcmp(test_tag, journal_entry_tag(ic, je2), ic->tag_size))) {
25382550
dm_integrity_io_error(ic, "tag mismatch when replaying journal", -EILSEQ);
2551+
dm_audit_log_target(DM_MSG_PREFIX, "integrity-replay-journal", ic->ti, 0);
2552+
}
25392553
}
25402554

25412555
journal_entry_set_unused(je2);
@@ -4514,9 +4528,11 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
45144528
if (ic->discard)
45154529
ti->num_discard_bios = 1;
45164530

4531+
dm_audit_log_ctr(DM_MSG_PREFIX, ti, 1);
45174532
return 0;
45184533

45194534
bad:
4535+
dm_audit_log_ctr(DM_MSG_PREFIX, ti, 0);
45204536
dm_integrity_dtr(ti);
45214537
return r;
45224538
}
@@ -4590,6 +4606,7 @@ static void dm_integrity_dtr(struct dm_target *ti)
45904606
free_alg(&ic->journal_mac_alg);
45914607

45924608
kfree(ic);
4609+
dm_audit_log_dtr(DM_MSG_PREFIX, ti, 1);
45934610
}
45944611

45954612
static struct target_type integrity_target = {

0 commit comments

Comments
 (0)