From patchwork Thu Aug 12 14:57:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michael_Wei=C3=9F?= X-Patchwork-Id: 12434863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77959C4338F for ; Fri, 13 Aug 2021 06:41:12 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3FA560E93 for ; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E3FA560E93 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-554-6kPgpzuWMwuaV4WqLv2DMA-1; Fri, 13 Aug 2021 02:41:09 -0400 X-MC-Unique: 6kPgpzuWMwuaV4WqLv2DMA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10E311082922; Fri, 13 Aug 2021 06:41:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E67360C9D; Fri, 13 Aug 2021 06:41:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F29E5181A0F2; Fri, 13 Aug 2021 06:41:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CF3e2i011480 for ; Thu, 12 Aug 2021 11:03:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55B7420AE82B; Thu, 12 Aug 2021 15:03:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50B6520AE835 for ; Thu, 12 Aug 2021 15:03:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF80118A6534 for ; Thu, 12 Aug 2021 15:03:38 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.187]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-84hih3YZM-28Hvm1kGbGVA-1; Thu, 12 Aug 2021 11:03:35 -0400 X-MC-Unique: 84hih3YZM-28Hvm1kGbGVA-1 Received: from weisslap.aisec.fraunhofer.de ([178.27.102.95]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M3lgJ-1mET0X338V-000uGk; Thu, 12 Aug 2021 16:58:14 +0200 From: =?utf-8?q?Michael_Wei=C3=9F?= To: michael.weiss@aisec.fraunhofer.de Date: Thu, 12 Aug 2021 16:57:42 +0200 Message-Id: <20210812145748.4460-2-michael.weiss@aisec.fraunhofer.de> In-Reply-To: <20210812145748.4460-1-michael.weiss@aisec.fraunhofer.de> References: <20210812145748.4460-1-michael.weiss@aisec.fraunhofer.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VRlAlfDB5Lnf+BVBMonU0Eg2eot1RoGDcs0IiBT5nDnqj9aaHft dcSLO6WONK888uP9aJqK6Aqb7ZQiPNlpUJu7M7xc4+bfDDsm3kxMGF1syUIKvVExAOAS0zo nwfgdVRl4NvB4ox9dfl4dEhENW7JEr4Vv4lV6bu39wfwADLoMcUIPK0LFtBy2DC9O/Mppvk /3X0q9IUYsRk56eLtLtbA== X-UI-Out-Filterresults: notjunk:1;V03:K0:DnlpQKNvJJQ=:KffVPKphi5VzcyJXqM25G7 w78eYYosa3qJNrzWTt6CA7LDELC4HrQRaZPJNNkVAMLQXRBfXMFPgOneB78KaD3tNYWHRjZ5J tGjJlq95R5T9Apkkaw9wWK4neeaJLzCCG1pvWUcROb0ysQdljZIx8nm6AjBbCcWELTQHy0exV 32lD7nDWDdSKsafgqJiw9u28OpsLszm3ObJpDLu5XKjaS6Co2PWDdvgzZYeMUdHdz6ag0LqX6 MK0WoqHrOmGE5UIuWUPV0m9I0DS8UZOLcEOUJWeVb1abpV25TWICO4TTVhweiUEjVjC5qDN1/ w3WMxy2skgKR5+XREXSG+pybsDIkYhTTJZJ/FmmwAqkeJ+aObL+fZz1SxMHcG+hHTElhcUfyk 1MtSnbzkV7PiVh2vr2WLAnksb/almelqdjipa1CkEkr967qjS17+atHbLkGbKvAkLC8Og58MW VGmLlx4P24uaWw45P988VPjYrAPFyiaxdMiV5u06RxUPS5WqwzDPhFgNkXi4vcx878UDZX7Tn PTJ9zaYg/k9FXZrwKJM+49kqUQZk11DNUglKDvdkMsesOnz2G9sHoyBV4oiqNjHTQf3+4xWpZ L/fQWGS74Hc+vsgNdOYHpl78wpCu3tOwis5N7KQ1xxeKGOlKeE60ZpTlp6FrAx6/SD3BfU6R3 CfUDAkNAI7EC1DW6g8HzfEaudCHcj3VlONH22BBf9mVnEjt8y+pQHxcbitCn0Xl7fY6KTlt0Y 9Ptu+JqYaH2/hqyXNORxQzpehGLmAPIRNL/wtwK3HNRQsdbRQanTYv49AtkAFSyNrDLScXZgK lL+IJtOMq9w86AOT85ZYJTRYFhQ8fKbIc+PysZOYZVT8shZP6fuSenAjXZoLfQ0kZTqfODvmB 3/rSnJWUdhY5t/INAgIQ== X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Fri, 13 Aug 2021 02:36:56 -0400 Cc: Paul Moore , Mike Snitzer , linux-kernel@vger.kernel.org, Eric Paris , linux-raid@vger.kernel.org, Song Liu , dm-devel@redhat.com, linux-audit@redhat.com, Alasdair Kergon Subject: [dm-devel] [PATCH 1/3] dm: introduce audit event module for device mapper X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com To be able to send auditing events to user space, we introduce a generic dm-audit module. It provides helper functions to emit audit events through the kernel audit subsystem. We claim the AUDIT_DM type=1336 out of the audit event messages range in the corresponding userspace api in 'include/uapi/linux/audit.h' for those events. Following commits to device mapper targets actually will make use of this to emit those events in relevant cases. Signed-off-by: Michael Weiß --- drivers/md/Kconfig | 10 +++++++ drivers/md/Makefile | 4 +++ drivers/md/dm-audit.c | 59 ++++++++++++++++++++++++++++++++++++++ drivers/md/dm-audit.h | 33 +++++++++++++++++++++ include/uapi/linux/audit.h | 2 ++ 5 files changed, 108 insertions(+) create mode 100644 drivers/md/dm-audit.c create mode 100644 drivers/md/dm-audit.h diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index 0602e82a9516..fd54c713a03e 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -608,6 +608,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 @@ -640,4 +641,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 loging of several security relevant events in the + particular device-mapper targets, especially the integrity target. + endif # MD diff --git a/drivers/md/Makefile b/drivers/md/Makefile index a74aaf8b1445..4cd47623c742 100644 --- a/drivers/md/Makefile +++ b/drivers/md/Makefile @@ -103,3 +103,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 diff --git a/drivers/md/dm-audit.c b/drivers/md/dm-audit.c new file mode 100644 index 000000000000..c7e5824821bb --- /dev/null +++ b/drivers/md/dm-audit.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Creating audit records for mapped devices. + * + * Copyright (C) 2021 Fraunhofer AISEC. All rights reserved. + * + * Authors: Michael Weiß + */ + +#include +#include +#include +#include +#include + +#include "dm-audit.h" +#include "dm-core.h" + +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; + + if (audit_enabled == AUDIT_OFF) + return; + + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_DM); + if (unlikely(!ab)) + return; + + audit_log_format(ab, "module=%s dev=%d:%d op=%s sector=%llu res=%d", + dm_msg_prefix, MAJOR(bio->bi_bdev->bd_dev), + MINOR(bio->bi_bdev->bd_dev), op, sector, result); + audit_log_end(ab); +} +EXPORT_SYMBOL_GPL(dm_audit_log_bio); + +void dm_audit_log_target(const char *dm_msg_prefix, const char *op, + struct dm_target *ti, int result) +{ + struct audit_buffer *ab; + struct mapped_device *md = dm_table_get_md(ti->table); + + if (audit_enabled == AUDIT_OFF) + return; + + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_DM); + if (unlikely(!ab)) + return; + + audit_log_format(ab, "module=%s dev=%s op=%s", + dm_msg_prefix, dm_device_name(md), op); + + if (!result && !strcmp("ctr", op)) + audit_log_format(ab, " error_msg='%s'", ti->error); + audit_log_format(ab, " res=%d", result); + audit_log_end(ab); +} +EXPORT_SYMBOL_GPL(dm_audit_log_target); diff --git a/drivers/md/dm-audit.h b/drivers/md/dm-audit.h new file mode 100644 index 000000000000..9db4955d32e1 --- /dev/null +++ b/drivers/md/dm-audit.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Creating audit records for mapped devices. + * + * Copyright (C) 2021 Fraunhofer AISEC. All rights reserved. + * + * Authors: Michael Weiß + */ + +#ifndef DM_AUDIT_H +#define DM_AUDIT_H + +#include + +#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); +void dm_audit_log_target(const char *dm_msg_prefix, const char *op, + struct dm_target *ti, int 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); +{ +} +#endif + +#endif diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index daa481729e9b..9d766fcbcf62 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -118,6 +118,7 @@ #define AUDIT_TIME_ADJNTPVAL 1333 /* NTP value adjustment */ #define AUDIT_BPF 1334 /* BPF subsystem */ #define AUDIT_EVENT_LISTENER 1335 /* Task joined multicast read socket */ +#define AUDIT_DM 1336 /* Device Mapper events */ #define AUDIT_AVC 1400 /* SE Linux avc denial or grant */ #define AUDIT_SELINUX_ERR 1401 /* Internal SE Linux Errors */ @@ -140,6 +141,7 @@ #define AUDIT_MAC_CALIPSO_ADD 1418 /* NetLabel: add CALIPSO DOI entry */ #define AUDIT_MAC_CALIPSO_DEL 1419 /* NetLabel: del CALIPSO DOI entry */ + #define AUDIT_FIRST_KERN_ANOM_MSG 1700 #define AUDIT_LAST_KERN_ANOM_MSG 1799 #define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */ From patchwork Thu Aug 12 14:57:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michael_Wei=C3=9F?= X-Patchwork-Id: 12434867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50B73C4320A for ; Fri, 13 Aug 2021 06:41:20 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6CF3A610CC for ; Fri, 13 Aug 2021 06:41:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6CF3A610CC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-r3Y-Ng49M2yHcpMKNpHeWA-1; Fri, 13 Aug 2021 02:41:17 -0400 X-MC-Unique: r3Y-Ng49M2yHcpMKNpHeWA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9AB2D185302E; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DEC360C9F; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 50C8E181A0F8; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CF3gIJ011488 for ; Thu, 12 Aug 2021 11:03:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EB021054591; Thu, 12 Aug 2021 15:03:44 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3608F1054596 for ; Thu, 12 Aug 2021 15:03:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF1C7800882 for ; Thu, 12 Aug 2021 15:03:37 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.130]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-eITL0zw2MdKc5-LpDTV6mQ-1; Thu, 12 Aug 2021 11:03:34 -0400 X-MC-Unique: eITL0zw2MdKc5-LpDTV6mQ-1 Received: from weisslap.aisec.fraunhofer.de ([178.27.102.95]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M1pk0-1mGP571gUa-002HB7; Thu, 12 Aug 2021 16:58:17 +0200 From: =?utf-8?q?Michael_Wei=C3=9F?= To: michael.weiss@aisec.fraunhofer.de Date: Thu, 12 Aug 2021 16:57:43 +0200 Message-Id: <20210812145748.4460-3-michael.weiss@aisec.fraunhofer.de> In-Reply-To: <20210812145748.4460-1-michael.weiss@aisec.fraunhofer.de> References: <20210812145748.4460-1-michael.weiss@aisec.fraunhofer.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:rOLBkevwnsuHTTeZxM6wyt3brTUugDPPIMca4NeT5aNr5Kik2K3 hbgMjJU3VBouB/E3nUPL+YruThvT5ydbySJdhQQjp8WZ+i8fV4e7zNcqUaHlGg+3mWghOU6 K6p+C/8Q3QwxaneRe71C77r9c3+iVHn6DpNPthcNFIqMrXD2v78B6HcfF7hF20FXqZFmQ/r XqHpyX2+hQc8xP0Czd8+A== X-UI-Out-Filterresults: notjunk:1;V03:K0:S4KgAIov8XM=:jjXaBNeDppYlEFwBwqqD5h cVTX2wU2kko4f65fsbkYHa4q00So1PFco7YG4QqQ1167rNKM+C5u+2vDl3FIlxo5o5TDN+grJ T+2pXAHRlUn0EjUGKZ62qrh5aODFzLpvQqQwRj0ZvtAghA3DgAv66nebNHs4Q/dE9e4bJzPdD 4Lcs5nw9ABj9pnA+i0ZvaJsHPifwcLSt/xj0AfXPxByZH3t7ejwlqnXecTJ6Gt4hd5fxmiS2T 89NKBvLvPcV9vMO/e5PD+Uns9WNnJ6cHCcrhWWi6rNCvomh3tSrPsHOWZgoyyGX30ImLzbBHg 0E5gPgFHcA0MLRtaUpXT6uzRQeu8I7c8IfG4Q1wdQoU+Hbn+fx6g6kPCNJcZcP8+ySpIIe2EA lVc/gc9swemKWRDCQDYIRhw8TlqYwLqaI7WOYR6d0DkHPbboRi/D6O5ZLPoaXTmLT/MU3sVL3 ImFKqKCDK+7zecy1fZcK5l5bBuK+AXJP6/SbkTmhbOBbk8NFfF549xPRukqOpNBv5n4YY4z3N /qLcieFJ4c69v9Wxq7FKY+K8gaskb7xzhwi6pMertvUVJ50IoLKNajmte3l1oe7wM/f5P3/1E wpP3IP+HnZ5S0rnYjbRWYfmQMoIqPm2Y7CYXdYoP0F7u4JcZ13KDIGjJ7K+kvmv0EXja4JYtn XB/fgdD17zivyvg11I1K/PATElZHeJiDwCNQh6WTbX8k7JX/h3iJwqtpXkfa8KGLFG1nreFJN Qux3JmsAuddC9mCurDw52GFSIRP7s4CdDDfV8fS3IoDgzpso9f40dKGHHU54Wor3RCPvk5iEg 6ihVUCZ197f27p9GabC6aO8gSuxwpY5cXQt0p+Uo/O2q1eRqYj1dz7RH7SxY1mUhO55ridl3C HslFQm6OewPdNE2rf51A== X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Fri, 13 Aug 2021 02:36:56 -0400 Cc: Paul Moore , Mike Snitzer , linux-kernel@vger.kernel.org, Eric Paris , linux-raid@vger.kernel.org, Song Liu , dm-devel@redhat.com, linux-audit@redhat.com, Alasdair Kergon Subject: [dm-devel] [PATCH 2/3] dm integrity: log audit events for dm-integrity target X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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ß --- drivers/md/dm-integrity.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 20f2510db1f6..fbbb4c3f16cb 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -23,6 +23,8 @@ #include #include +#include "dm-audit.h" + #define DM_MSG_PREFIX "integrity" #define DEFAULT_INTERLEAVE_SECTORS 32768 @@ -539,6 +541,7 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr) } if (memcmp((__u8 *)ic->sb + (1 << SECTOR_SHIFT) - size, result, size)) { dm_integrity_io_error(ic, "superblock mac", -EILSEQ); + dm_audit_log_target(DM_MSG_PREFIX, "mac-superblock", ic->ti, 0); return -EILSEQ; } } @@ -876,8 +879,10 @@ static void rw_section_mac(struct dm_integrity_c *ic, unsigned section, bool wr) if (likely(wr)) memcpy(&js->mac, result + (j * JOURNAL_MAC_PER_SECTOR), JOURNAL_MAC_PER_SECTOR); else { - if (memcmp(&js->mac, result + (j * JOURNAL_MAC_PER_SECTOR), JOURNAL_MAC_PER_SECTOR)) + if (memcmp(&js->mac, result + (j * JOURNAL_MAC_PER_SECTOR), JOURNAL_MAC_PER_SECTOR)) { dm_integrity_io_error(ic, "journal mac", -EILSEQ); + dm_audit_log_target(DM_MSG_PREFIX, "mac-journal", ic->ti, 0); + } } } } @@ -1782,10 +1787,15 @@ static void integrity_metadata(struct work_struct *w) if (unlikely(r)) { if (r > 0) { char b[BDEVNAME_SIZE]; - DMERR_LIMIT("%s: Checksum failed at sector 0x%llx", bio_devname(bio, b), - (sector - ((r + ic->tag_size - 1) / ic->tag_size))); + sector_t s; + + s = sector - ((r + ic->tag_size - 1) / ic->tag_size); + DMERR_LIMIT("%s: Checksum failed at sector 0x%llx", + bio_devname(bio, b), s); r = -EILSEQ; atomic64_inc(&ic->number_of_mismatches); + dm_audit_log_bio(DM_MSG_PREFIX, "integrity-checksum", + bio, s, 0); } if (likely(checksums != checksums_onstack)) kfree(checksums); @@ -1991,6 +2001,8 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio, if (unlikely(memcmp(checksums_onstack, journal_entry_tag(ic, je), ic->tag_size))) { DMERR_LIMIT("Checksum failed when reading from journal, at sector 0x%llx", logical_sector); + dm_audit_log_bio(DM_MSG_PREFIX, "journal-checksum", + bio, logical_sector, 0); } } #endif @@ -2534,8 +2546,10 @@ static void do_journal_write(struct dm_integrity_c *ic, unsigned write_start, integrity_sector_checksum(ic, sec + ((l - j) << ic->sb->log2_sectors_per_block), (char *)access_journal_data(ic, i, l), test_tag); - if (unlikely(memcmp(test_tag, journal_entry_tag(ic, je2), ic->tag_size))) + if (unlikely(memcmp(test_tag, journal_entry_tag(ic, je2), ic->tag_size))) { dm_integrity_io_error(ic, "tag mismatch when replaying journal", -EILSEQ); + dm_audit_log_target(DM_MSG_PREFIX, "integrity-replay-journal", ic->ti, 0); + } } journal_entry_set_unused(je2); @@ -4490,9 +4504,11 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv) if (ic->discard) ti->num_discard_bios = 1; + dm_audit_log_target(DM_MSG_PREFIX, "ctr", ti, 1); return 0; bad: + dm_audit_log_target(DM_MSG_PREFIX, "ctr", ti, 0); dm_integrity_dtr(ti); return r; } @@ -4566,6 +4582,7 @@ static void dm_integrity_dtr(struct dm_target *ti) free_alg(&ic->journal_mac_alg); kfree(ic); + dm_audit_log_target(DM_MSG_PREFIX, "dtr", ti, 1); } static struct target_type integrity_target = { From patchwork Thu Aug 12 14:57:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michael_Wei=C3=9F?= X-Patchwork-Id: 12434865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBD58C4338F for ; Fri, 13 Aug 2021 06:41:19 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 05C8A610CD for ; Fri, 13 Aug 2021 06:41:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 05C8A610CD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-kfkZefDBNnij680JDMyHQw-1; Fri, 13 Aug 2021 02:41:16 -0400 X-MC-Unique: kfkZefDBNnij680JDMyHQw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C81F11008065; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3CCE2B3A5; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7889C4A7C9; Fri, 13 Aug 2021 06:41:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CF3iGp011495 for ; Thu, 12 Aug 2021 11:03:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id B67902094D05; Thu, 12 Aug 2021 15:03:45 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B16EC2094D36 for ; Thu, 12 Aug 2021 15:03:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9743118A653A for ; Thu, 12 Aug 2021 15:03:45 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-Dq4AUA8UPFu6jooFHHYDIQ-1; Thu, 12 Aug 2021 11:03:41 -0400 X-MC-Unique: Dq4AUA8UPFu6jooFHHYDIQ-1 Received: from weisslap.aisec.fraunhofer.de ([178.27.102.95]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mwwhv-1n3GJb0gg7-00yNa2; Thu, 12 Aug 2021 16:58:20 +0200 From: =?utf-8?q?Michael_Wei=C3=9F?= To: michael.weiss@aisec.fraunhofer.de Date: Thu, 12 Aug 2021 16:57:44 +0200 Message-Id: <20210812145748.4460-4-michael.weiss@aisec.fraunhofer.de> In-Reply-To: <20210812145748.4460-1-michael.weiss@aisec.fraunhofer.de> References: <20210812145748.4460-1-michael.weiss@aisec.fraunhofer.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:hi75DlmNC+gK0CXxDU0sjhTTyi1egVdFtYQsJdIqde10JuGW9jT TPsDrRNsncuUh69Pvfji/1XP0HPWq+lq4I/9TE5MXLvZ7i8SwSZsjqd+ROBtQVpLZ9IWRti 0J39VfLCltB8admoIpZQFSyP3cQaFVpTaYQsnl0QKyngMYvvlRlJxzVCusRAc/4FwxzoDbO klNlxcmjVhKgcKpfg6j+w== X-UI-Out-Filterresults: notjunk:1;V03:K0:OMKJiFCoaiQ=:MNg8iq5mB8F24eGYw49PmB Svc/aMssE1J3zFzYHJ7aWl6UPunR54ICA+kMjj4o0g5I32jNBBnAOwRCMw0JCgbcS7q9y73qO qOprtRAZ6nCvkTc/xuTqBEmqwflzOJ72aO4zD2MnyA8REviPV57B8wuf9ZxFZitLCD5VRUMX4 BdEI/ZVxUDMOmTMRsCOUOTZ7673CmmflbTfnM3tcX8jlCaT1XTTMV0XoD6bYpPlDCh7mPGsNj 5xjyVpNd6ZDqpZIpJmIwM5rHI9fgiBv9ILLOpRO4WYk/PAo8ZJ9kK5KEcN20NveLAs2dT6/f0 Wrz23405tx4og2x8CwHCb9ac0haCdz207VCqUuElZY/MzXftOM6DDxVcLQ/ZBDufRjH4BtoDs YAYZp6IXaaiUdU5EzKxUyWLPEa9jQRsrG0u+j6Eo/1a4Qipy9vMsAaG7gxGcRj7xqlef7F2Zk wWOxcLXja5OrIi1/44jHjvv+zHxDuavXOu6q/6WAI+7aXX5SW1qjhbkx8LG0keIHTsT/sSAu9 XTXeWWFLGwkdBjJ39T7W82+NDlyTfY08GGIqO+JNd5DjIpvA0u4Ei9eeIeUU3zHEzLjPWEl4k uKLfdyzo9/tbRseTxY0wWfSKwvXJasM/NP7RWwKtmCzs5b8HWFj265NCM9bRUboX6uxwKE9HO zV62yQ3wtS/Tct+Oy9Kq7VYDQ7RsL1I3TZTqe56EfNQW30aNAXdlLiY5yR6/uoqif12L/hBd9 KcBOBzmqkNQT9fORmgvNBaR94rPl/PFxsIw23K6L/R7FDX7m+N48hvJLUd6sSq8CEDc8bJpEe iUoaJ0TwRmIFzhaNpd3VdsCRUms3cNp5UA60nGRqlMOmBm48+cOlrQgBgK6zVUyCQ4taA9Bdi zOtkJwM5h/FlWTXJmocA== X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Fri, 13 Aug 2021 02:36:56 -0400 Cc: Paul Moore , Mike Snitzer , linux-kernel@vger.kernel.org, Eric Paris , linux-raid@vger.kernel.org, Song Liu , dm-devel@redhat.com, linux-audit@redhat.com, Alasdair Kergon Subject: [dm-devel] [PATCH 3/3] dm crypt: log aead integrity violations to audit subsystem X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Since dm-crypt target can be stacked on dm-integrity targets to provide authenticated encryption, integrity violations are recognized here during aead computation. We use the dm-audit submodule to signal those events to user space, too. The construction and destruction of crypt device mappings are also logged as audit events. Signed-off-by: Michael Weiß --- drivers/md/dm-crypt.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 50f4cbd600d5..343aef4dcf5e 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -41,6 +41,8 @@ #include +#include "dm-audit.h" + #define DM_MSG_PREFIX "crypt" /* @@ -1122,6 +1124,7 @@ static bool crypt_integrity_hmac(struct crypt_config *cc) return crypt_integrity_aead(cc) && cc->key_mac_size; } + /* Get sg containing data */ static struct scatterlist *crypt_get_sg_data(struct crypt_config *cc, struct scatterlist *sg) @@ -1362,8 +1365,12 @@ static int crypt_convert_block_aead(struct crypt_config *cc, if (r == -EBADMSG) { char b[BDEVNAME_SIZE]; - DMERR_LIMIT("%s: INTEGRITY AEAD ERROR, sector %llu", bio_devname(ctx->bio_in, b), - (unsigned long long)le64_to_cpu(*sector)); + sector_t s = le64_to_cpu(*sector); + + DMERR_LIMIT("%s: INTEGRITY AEAD ERROR, sector %llu", + bio_devname(ctx->bio_in, b), s); + dm_audit_log_bio(DM_MSG_PREFIX, "integrity-aead", + ctx->bio_in, s, 0); } if (!r && cc->iv_gen_ops && cc->iv_gen_ops->post) @@ -2173,8 +2180,12 @@ static void kcryptd_async_done(struct crypto_async_request *async_req, if (error == -EBADMSG) { char b[BDEVNAME_SIZE]; - DMERR_LIMIT("%s: INTEGRITY AEAD ERROR, sector %llu", bio_devname(ctx->bio_in, b), - (unsigned long long)le64_to_cpu(*org_sector_of_dmreq(cc, dmreq))); + sector_t s = le64_to_cpu(*org_sector_of_dmreq(cc, dmreq)); + + DMERR_LIMIT("%s: INTEGRITY AEAD ERROR, sector %llu", + bio_devname(ctx->bio_in, b), s); + dm_audit_log_bio(DM_MSG_PREFIX, "integrity-aead", + ctx->bio_in, s, 0); io->error = BLK_STS_PROTECTION; } else if (error < 0) io->error = BLK_STS_IOERR; @@ -2729,6 +2740,8 @@ static void crypt_dtr(struct dm_target *ti) dm_crypt_clients_n--; crypt_calculate_pages_per_client(); spin_unlock(&dm_crypt_clients_lock); + + dm_audit_log_target(DM_MSG_PREFIX, "dtr", ti, 1); } static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode) @@ -3357,9 +3370,11 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_flush_bios = 1; ti->limit_swap_bios = true; + dm_audit_log_target(DM_MSG_PREFIX, "ctr", ti, 1); return 0; bad: + dm_audit_log_target(DM_MSG_PREFIX, "ctr", ti, 0); crypt_dtr(ti); return ret; }