Message ID | 1696457386-3010-13-git-send-email-wufan@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp433266vqb; Wed, 4 Oct 2023 15:15:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF6oTecpVcW7xXtXj5fHiRuniG/nxcVnvwbdi82eUX+liw74aOUrfyTfgvqmraIxJ55Njx X-Received: by 2002:a05:6808:2918:b0:3ae:5e6a:46d4 with SMTP id ev24-20020a056808291800b003ae5e6a46d4mr3254656oib.37.1696457700512; Wed, 04 Oct 2023 15:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696457700; cv=none; d=google.com; s=arc-20160816; b=vELotsyxvPgR4E5i/V3Us8dAN4bUclsXm1APW78hFBgppQ/cD3ypMb+f5Oo+8I1rn2 2SpKmdObWO2CSM64N9y8190ywQofmtuNkaA5vIqAC0CGslEKQWXCjzQU2noIzQ9dYfjj Akk2B1X7j64DzxqW0O3dgp7VkdU/BQooQ/ibRmhABu8xFEdjkoKbLqMY480BrsMqrOfr pgcLefz6txT/zAbLC0CH75S0omjdNJMH32lja7PApyvna+kk2YPKrGiYBkHgpRy+v+Cz 3AWQtSXoZlzK9IF7Mr5nGqcF61FEjZWLRLVt9zxs9pmz3iDT1lE+/oUAYQiE9TV+AQa/ IQWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=eJS+kBKHSIzGbwwv49yX5DCUKZVKLPE/A7wfEDIcA9E=; fh=PhRfb9k/VCaD3nhvPFELAdaSNFsaoc654VPOTTQHJlA=; b=SH79KNgjyR3xXdaAwiBdeDcyoRnFPwG8Ll4qSaUOFdAbFwlWdxwHydIhq4Jea40XOP A5YRa+VM//p3Yl56/hfMQ1JB5kqSseA5hUsJxFxKjGiqQ2PVYlxxe75AN7pDlgni/gpW XnF+LK394tSPwIbB6uLPna9CkxK82l3i4A8+3OhHuQytMO7hZv86tYmrdPElWgmOz7G/ B0HmmRTIPcDEyLEi9WG4Xn2BjHMdjrDXUpTWjiWMNaRnj9KIeyYrxSWwXjK2Nnw2T799 mCmWfCxPChjT+pAaeXqkObsY3AWUqwf9UQNwjMu15+Dz4CpKgwMNw/TMsYLUp8SgX/5b WeUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=kivRmiQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id bv71-20020a632e4a000000b00565eb0b4f33si83933pgb.224.2023.10.04.15.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:15:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=kivRmiQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9465481D55DC; Wed, 4 Oct 2023 15:14:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240200AbjJDWLL (ORCPT <rfc822;ezelljr.billy@gmail.com> + 19 others); Wed, 4 Oct 2023 18:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233563AbjJDWJ5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 4 Oct 2023 18:09:57 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 811D3E4; Wed, 4 Oct 2023 15:09:54 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1052) id D315F20B74D8; Wed, 4 Oct 2023 15:09:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D315F20B74D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1696457390; bh=eJS+kBKHSIzGbwwv49yX5DCUKZVKLPE/A7wfEDIcA9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kivRmiQvs0LNuyzLsMCEEVEdqNtf6L5xl16co++lbJNojj2N7CnDAjy+8HfjVqa3s DI8XBOrh8ocu5/dAKmmJnSU0tv9SUOOLCgLQQKevgS84tyQYx8ciXVaHBv2Q7ijzXh hX5dxUtiY48KK7vGUG+7aj/jEn3ihq7B4AgdN2lw= From: Fan Wu <wufan@linux.microsoft.com> To: corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, eparis@redhat.com, paul@paul-moore.com Cc: linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, audit@vger.kernel.org, roberto.sassu@huawei.com, linux-kernel@vger.kernel.org, Fan Wu <wufan@linux.microsoft.com> Subject: [RFC PATCH v11 12/19] dm: add finalize hook to target_type Date: Wed, 4 Oct 2023 15:09:39 -0700 Message-Id: <1696457386-3010-13-git-send-email-wufan@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1696457386-3010-1-git-send-email-wufan@linux.microsoft.com> References: <1696457386-3010-1-git-send-email-wufan@linux.microsoft.com> X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 04 Oct 2023 15:14:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778864830057361340 X-GMAIL-MSGID: 1778864830057361340 |
Series |
Integrity Policy Enforcement LSM (IPE)
|
|
Commit Message
Fan Wu
Oct. 4, 2023, 10:09 p.m. UTC
This patch adds a target finalize hook.
The hook is triggered just before activating an inactive table of a
mapped device. If it returns an error the __bind get cancelled.
The dm-verity target will use this hook to attach the dm-verity's
roothash metadata to the block_device struct of the mapped device.
Signed-off-by: Fan Wu <wufan@linux.microsoft.com>
---
v1-v10:
+ Not present
---
drivers/md/dm.c | 12 ++++++++++++
include/linux/device-mapper.h | 7 +++++++
2 files changed, 19 insertions(+)
Comments
On Oct 4, 2023 Fan Wu <wufan@linux.microsoft.com> wrote: > > This patch adds a target finalize hook. > > The hook is triggered just before activating an inactive table of a > mapped device. If it returns an error the __bind get cancelled. > > The dm-verity target will use this hook to attach the dm-verity's > roothash metadata to the block_device struct of the mapped device. > > Signed-off-by: Fan Wu <wufan@linux.microsoft.com> > --- > v1-v10: > + Not present > --- > drivers/md/dm.c | 12 ++++++++++++ > include/linux/device-mapper.h | 7 +++++++ > 2 files changed, 19 insertions(+) We need an ACK and confirmation from Alasdair and/or Mike that this is the right approach. > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > index 64a1f306c96c..3be9cc35306d 100644 > --- a/drivers/md/dm.c > +++ b/drivers/md/dm.c > @@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, > goto out; > } > > + for (unsigned int i = 0; i < t->num_targets; i++) { > + struct dm_target *ti = dm_table_get_target(t, i); > + > + if (ti->type->finalize) { > + ret = ti->type->finalize(ti); > + if (ret) { > + old_map = ERR_PTR(ret); > + goto out; > + } > + } > + } > + > old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); > rcu_assign_pointer(md->map, (void *)t); > md->immutable_target_type = dm_table_get_immutable_target_type(t); > diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h > index 69d0435c7ebb..4040e84a8ec7 100644 > --- a/include/linux/device-mapper.h > +++ b/include/linux/device-mapper.h > @@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff, > */ > typedef size_t (*dm_dax_recovery_write_fn)(struct dm_target *ti, pgoff_t pgoff, > void *addr, size_t bytes, struct iov_iter *i); > +/* > + * Returns: > + * < 0 : error > + * = 0 : success > + */ > +typedef int (*dm_finalize_fn) (struct dm_target *target); > > void dm_error(const char *message); > > @@ -209,6 +215,7 @@ struct target_type { > dm_dax_direct_access_fn direct_access; > dm_dax_zero_page_range_fn dax_zero_page_range; > dm_dax_recovery_write_fn dax_recovery_write; > + dm_finalize_fn finalize; > > /* For internal device-mapper use. */ > struct list_head list; > -- > 2.25.1 -- paul-moore.com
On Mon, Oct 23, 2023 at 11:52 PM Paul Moore <paul@paul-moore.com> wrote: > On Oct 4, 2023 Fan Wu <wufan@linux.microsoft.com> wrote: > > > > This patch adds a target finalize hook. > > > > The hook is triggered just before activating an inactive table of a > > mapped device. If it returns an error the __bind get cancelled. > > > > The dm-verity target will use this hook to attach the dm-verity's > > roothash metadata to the block_device struct of the mapped device. > > > > Signed-off-by: Fan Wu <wufan@linux.microsoft.com> > > --- > > v1-v10: > > + Not present > > --- > > drivers/md/dm.c | 12 ++++++++++++ > > include/linux/device-mapper.h | 7 +++++++ > > 2 files changed, 19 insertions(+) > > We need an ACK and confirmation from Alasdair and/or Mike that this > is the right approach. A gentle ping with a reminder ... For reference, the full patchset can be found on lore at the link below: https://lore.kernel.org/linux-security-module/1696457386-3010-1-git-send-email-wufan@linux.microsoft.com/ > > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > > index 64a1f306c96c..3be9cc35306d 100644 > > --- a/drivers/md/dm.c > > +++ b/drivers/md/dm.c > > @@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, > > goto out; > > } > > > > + for (unsigned int i = 0; i < t->num_targets; i++) { > > + struct dm_target *ti = dm_table_get_target(t, i); > > + > > + if (ti->type->finalize) { > > + ret = ti->type->finalize(ti); > > + if (ret) { > > + old_map = ERR_PTR(ret); > > + goto out; > > + } > > + } > > + } > > + > > old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); > > rcu_assign_pointer(md->map, (void *)t); > > md->immutable_target_type = dm_table_get_immutable_target_type(t); > > diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h > > index 69d0435c7ebb..4040e84a8ec7 100644 > > --- a/include/linux/device-mapper.h > > +++ b/include/linux/device-mapper.h > > @@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff, > > */ > > typedef size_t (*dm_dax_recovery_write_fn)(struct dm_target *ti, pgoff_t pgoff, > > void *addr, size_t bytes, struct iov_iter *i); > > +/* > > + * Returns: > > + * < 0 : error > > + * = 0 : success > > + */ > > +typedef int (*dm_finalize_fn) (struct dm_target *target); > > > > void dm_error(const char *message); > > > > @@ -209,6 +215,7 @@ struct target_type { > > dm_dax_direct_access_fn direct_access; > > dm_dax_zero_page_range_fn dax_zero_page_range; > > dm_dax_recovery_write_fn dax_recovery_write; > > + dm_finalize_fn finalize; > > > > /* For internal device-mapper use. */ > > struct list_head list; > > -- > > 2.25.1
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 64a1f306c96c..3be9cc35306d 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2239,6 +2239,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, goto out; } + for (unsigned int i = 0; i < t->num_targets; i++) { + struct dm_target *ti = dm_table_get_target(t, i); + + if (ti->type->finalize) { + ret = ti->type->finalize(ti); + if (ret) { + old_map = ERR_PTR(ret); + goto out; + } + } + } + old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); rcu_assign_pointer(md->map, (void *)t); md->immutable_target_type = dm_table_get_immutable_target_type(t); diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 69d0435c7ebb..4040e84a8ec7 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff, */ typedef size_t (*dm_dax_recovery_write_fn)(struct dm_target *ti, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i); +/* + * Returns: + * < 0 : error + * = 0 : success + */ +typedef int (*dm_finalize_fn) (struct dm_target *target); void dm_error(const char *message); @@ -209,6 +215,7 @@ struct target_type { dm_dax_direct_access_fn direct_access; dm_dax_zero_page_range_fn dax_zero_page_range; dm_dax_recovery_write_fn dax_recovery_write; + dm_finalize_fn finalize; /* For internal device-mapper use. */ struct list_head list;