Skip to content

Commit 074c446

Browse files
quitschboMike Snitzer
authored andcommitted
dm verity: emit audit events on verification failure and more
dm-verity 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. Analogous to dm-integrity, we also use the dm-audit submodule allowing to emit audit events on verification failures of metadata and data blocks as well as if max corrupted errors are reached. The construction and destruction of verity device mappings are also relevant for auditing a system. Thus, those events are also logged as audit events. Tested by starting a container with the container manager (cmld) of GyroidOS which uses a dm-verity protected rootfs image root.img mapped to /dev/mapper/<uuid>-root. One block was manipulated in the underlying image file and repeated reads of the verity device were performed again until the max corrupted errors is reached, e.g.: dd if=/dev/urandom of=root.img bs=512 count=1 seek=1000 for i in range {1..101}; do \ dd if=/dev/mapper/<uuid>-root of=/dev/null bs=4096 \ count=1 skip=1000 \ done The resulting audit log looks as follows: type=DM_CTRL msg=audit(1677618791.876:962): module=verity op=ctr ppid=4876 pid=29102 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=44 comm="cmld" exe="/usr/sbin/cml/cmld" subj=unconfined dev=254:3 error_msg='success' res=1 type=DM_EVENT msg=audit(1677619463.786:1074): module=verity op=verify-data dev=7:0 sector=1000 res=0 ... type=DM_EVENT msg=audit(1677619596.727:1162): module=verity op=verify-data dev=7:0 sector=1000 res=0 type=DM_EVENT msg=audit(1677619596.731:1163): module=verity op=max-corrupted-errors dev=254:3 sector=? res=0 Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de> Acked-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent e8c5d45 commit 074c446

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

drivers/md/dm-verity-target.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "dm-verity.h"
1717
#include "dm-verity-fec.h"
1818
#include "dm-verity-verify-sig.h"
19+
#include "dm-audit.h"
1920
#include <linux/module.h>
2021
#include <linux/reboot.h>
2122
#include <linux/scatterlist.h>
@@ -248,8 +249,10 @@ static int verity_handle_err(struct dm_verity *v, enum verity_block_type type,
248249
DMERR_LIMIT("%s: %s block %llu is corrupted", v->data_dev->name,
249250
type_str, block);
250251

251-
if (v->corrupted_errs == DM_VERITY_MAX_CORRUPTED_ERRS)
252+
if (v->corrupted_errs == DM_VERITY_MAX_CORRUPTED_ERRS) {
252253
DMERR("%s: reached maximum errors", v->data_dev->name);
254+
dm_audit_log_target(DM_MSG_PREFIX, "max-corrupted-errors", v->ti, 0);
255+
}
253256

254257
snprintf(verity_env, DM_VERITY_ENV_LENGTH, "%s=%d,%llu",
255258
DM_VERITY_ENV_VAR_NAME, type, block);
@@ -340,6 +343,11 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
340343
else if (verity_handle_err(v,
341344
DM_VERITY_BLOCK_TYPE_METADATA,
342345
hash_block)) {
346+
struct bio *bio =
347+
dm_bio_from_per_bio_data(io,
348+
v->ti->per_io_data_size);
349+
dm_audit_log_bio(DM_MSG_PREFIX, "verify-metadata", bio,
350+
block, 0);
343351
r = -EIO;
344352
goto release_ret_r;
345353
}
@@ -590,8 +598,11 @@ static int verity_verify_io(struct dm_verity_io *io)
590598
return -EIO;
591599
}
592600
if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA,
593-
cur_block))
601+
cur_block)) {
602+
dm_audit_log_bio(DM_MSG_PREFIX, "verify-data",
603+
bio, cur_block, 0);
594604
return -EIO;
605+
}
595606
}
596607
}
597608

@@ -975,6 +986,8 @@ static void verity_dtr(struct dm_target *ti)
975986
static_branch_dec(&use_tasklet_enabled);
976987

977988
kfree(v);
989+
990+
dm_audit_log_dtr(DM_MSG_PREFIX, ti, 1);
978991
}
979992

980993
static int verity_alloc_most_once(struct dm_verity *v)
@@ -1429,11 +1442,14 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv)
14291442

14301443
verity_verify_sig_opts_cleanup(&verify_args);
14311444

1445+
dm_audit_log_ctr(DM_MSG_PREFIX, ti, 1);
1446+
14321447
return 0;
14331448

14341449
bad:
14351450

14361451
verity_verify_sig_opts_cleanup(&verify_args);
1452+
dm_audit_log_ctr(DM_MSG_PREFIX, ti, 0);
14371453
verity_dtr(ti);
14381454

14391455
return r;

0 commit comments

Comments
 (0)