forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'for-5.16/dm-changes' of git://git.kernel.org/pub/scm/linux…
…/kernel/git/device-mapper/linux-dm Pull device mapper updates from Mike Snitzer: - Add DM core support for emitting audit events through the audit subsystem. Also enhance both the integrity and crypt targets to emit events to via dm-audit. - Various other simple code improvements and cleanups. * tag 'for-5.16/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm table: log table creation error code dm: make workqueue names device-specific dm writecache: Make use of the helper macro kthread_run() dm crypt: Make use of the helper macro kthread_run() dm verity: use bvec_kmap_local in verity_for_bv_block dm log writes: use memcpy_from_bvec in log_writes_map dm integrity: use bvec_kmap_local in __journal_read_write dm integrity: use bvec_kmap_local in integrity_metadata dm: add add_disk() error handling dm: Remove redundant flush_workqueue() calls dm crypt: log aead integrity violations to audit subsystem dm integrity: log audit events for dm-integrity target dm: introduce audit event module for device mapper
- Loading branch information
Showing
14 changed files
with
221 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Creating audit records for mapped devices. | ||
* | ||
* Copyright (C) 2021 Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Authors: Michael Weiß <[email protected]> | ||
*/ | ||
|
||
#include <linux/audit.h> | ||
#include <linux/module.h> | ||
#include <linux/device-mapper.h> | ||
#include <linux/bio.h> | ||
#include <linux/blkdev.h> | ||
|
||
#include "dm-audit.h" | ||
#include "dm-core.h" | ||
|
||
static struct audit_buffer *dm_audit_log_start(int audit_type, | ||
const char *dm_msg_prefix, | ||
const char *op) | ||
{ | ||
struct audit_buffer *ab; | ||
|
||
if (audit_enabled == AUDIT_OFF) | ||
return NULL; | ||
|
||
ab = audit_log_start(audit_context(), GFP_KERNEL, audit_type); | ||
if (unlikely(!ab)) | ||
return NULL; | ||
|
||
audit_log_format(ab, "module=%s op=%s", dm_msg_prefix, op); | ||
return ab; | ||
} | ||
|
||
void dm_audit_log_ti(int audit_type, const char *dm_msg_prefix, const char *op, | ||
struct dm_target *ti, int result) | ||
{ | ||
struct audit_buffer *ab = NULL; | ||
struct mapped_device *md = dm_table_get_md(ti->table); | ||
int dev_major = dm_disk(md)->major; | ||
int dev_minor = dm_disk(md)->first_minor; | ||
|
||
switch (audit_type) { | ||
case AUDIT_DM_CTRL: | ||
ab = dm_audit_log_start(audit_type, dm_msg_prefix, op); | ||
if (unlikely(!ab)) | ||
return; | ||
audit_log_task_info(ab); | ||
audit_log_format(ab, " dev=%d:%d error_msg='%s'", dev_major, | ||
dev_minor, !result ? ti->error : "success"); | ||
break; | ||
case AUDIT_DM_EVENT: | ||
ab = dm_audit_log_start(audit_type, dm_msg_prefix, op); | ||
if (unlikely(!ab)) | ||
return; | ||
audit_log_format(ab, " dev=%d:%d sector=?", dev_major, | ||
dev_minor); | ||
break; | ||
default: /* unintended use */ | ||
return; | ||
} | ||
|
||
audit_log_format(ab, " res=%d", result); | ||
audit_log_end(ab); | ||
} | ||
EXPORT_SYMBOL_GPL(dm_audit_log_ti); | ||
|
||
void dm_audit_log_bio(const char *dm_msg_prefix, const char *op, | ||
struct bio *bio, sector_t sector, int result) | ||
{ | ||
struct audit_buffer *ab; | ||
int dev_major = MAJOR(bio->bi_bdev->bd_dev); | ||
int dev_minor = MINOR(bio->bi_bdev->bd_dev); | ||
|
||
ab = dm_audit_log_start(AUDIT_DM_EVENT, dm_msg_prefix, op); | ||
if (unlikely(!ab)) | ||
return; | ||
|
||
audit_log_format(ab, " dev=%d:%d sector=%llu res=%d", | ||
dev_major, dev_minor, sector, result); | ||
audit_log_end(ab); | ||
} | ||
EXPORT_SYMBOL_GPL(dm_audit_log_bio); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Creating audit records for mapped devices. | ||
* | ||
* Copyright (C) 2021 Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Authors: Michael Weiß <[email protected]> | ||
*/ | ||
|
||
#ifndef DM_AUDIT_H | ||
#define DM_AUDIT_H | ||
|
||
#include <linux/device-mapper.h> | ||
#include <linux/audit.h> | ||
|
||
#ifdef CONFIG_DM_AUDIT | ||
void dm_audit_log_bio(const char *dm_msg_prefix, const char *op, | ||
struct bio *bio, sector_t sector, int result); | ||
|
||
/* | ||
* dm_audit_log_ti() is not intended to be used directly in dm modules, | ||
* the wrapper functions below should be called by dm modules instead. | ||
*/ | ||
void dm_audit_log_ti(int audit_type, const char *dm_msg_prefix, const char *op, | ||
struct dm_target *ti, int result); | ||
|
||
static inline void dm_audit_log_ctr(const char *dm_msg_prefix, | ||
struct dm_target *ti, int result) | ||
{ | ||
dm_audit_log_ti(AUDIT_DM_CTRL, dm_msg_prefix, "ctr", ti, result); | ||
} | ||
|
||
static inline void dm_audit_log_dtr(const char *dm_msg_prefix, | ||
struct dm_target *ti, int result) | ||
{ | ||
dm_audit_log_ti(AUDIT_DM_CTRL, dm_msg_prefix, "dtr", ti, result); | ||
} | ||
|
||
static inline void dm_audit_log_target(const char *dm_msg_prefix, const char *op, | ||
struct dm_target *ti, int result) | ||
{ | ||
dm_audit_log_ti(AUDIT_DM_EVENT, dm_msg_prefix, op, ti, result); | ||
} | ||
#else | ||
static inline void dm_audit_log_bio(const char *dm_msg_prefix, const char *op, | ||
struct bio *bio, sector_t sector, | ||
int result) | ||
{ | ||
} | ||
static inline void dm_audit_log_target(const char *dm_msg_prefix, | ||
const char *op, struct dm_target *ti, | ||
int result) | ||
{ | ||
} | ||
static inline void dm_audit_log_ctr(const char *dm_msg_prefix, | ||
struct dm_target *ti, int result) | ||
{ | ||
} | ||
|
||
static inline void dm_audit_log_dtr(const char *dm_msg_prefix, | ||
struct dm_target *ti, int result) | ||
{ | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.