Commit c183e170 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'for-5.16/dm-changes' of...

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
parents 37259498 7552750d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -610,6 +610,7 @@ config DM_INTEGRITY
	select CRYPTO
	select CRYPTO_SKCIPHER
	select ASYNC_XOR
	select DM_AUDIT if AUDIT
	help
	  This device-mapper target emulates a block device that has
	  additional per-sector tags that can be used for storing
@@ -642,4 +643,13 @@ config DM_ZONED

	  If unsure, say N.

config DM_AUDIT
	bool "DM audit events"
	depends on AUDIT
	help
	  Generate audit events for device-mapper.

	  Enables audit logging of several security relevant events in the
	  particular device-mapper targets, especially the integrity target.

endif # MD
+4 −0
Original line number Diff line number Diff line
@@ -107,3 +107,7 @@ endif
ifeq ($(CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG),y)
dm-verity-objs			+= dm-verity-verify-sig.o
endif

ifeq ($(CONFIG_DM_AUDIT),y)
dm-mod-objs			+= dm-audit.o
endif

drivers/md/dm-audit.c

0 → 100644
+84 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * Creating audit records for mapped devices.
 *
 * Copyright (C) 2021 Fraunhofer AISEC. All rights reserved.
 *
 * Authors: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
 */

#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);

drivers/md/dm-audit.h

0 → 100644
+66 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Creating audit records for mapped devices.
 *
 * Copyright (C) 2021 Fraunhofer AISEC. All rights reserved.
 *
 * Authors: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
 */

#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
+0 −1
Original line number Diff line number Diff line
@@ -2082,7 +2082,6 @@ static void __exit dm_bufio_exit(void)
	int bug = 0;

	cancel_delayed_work_sync(&dm_bufio_cleanup_old_work);
	flush_workqueue(dm_bufio_wq);
	destroy_workqueue(dm_bufio_wq);

	if (dm_bufio_client_count) {
Loading