Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp783416iob; Wed, 18 May 2022 12:54:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw99q6capQ3mNfOS5JWi6I4rWJ2ug9/vzX7uAorXyfjz+2QkNsYPmtu/t/tY9gEqEKfdJqu X-Received: by 2002:a17:903:2d0:b0:14d:8a8d:cb1 with SMTP id s16-20020a17090302d000b0014d8a8d0cb1mr1282138plk.50.1652903674396; Wed, 18 May 2022 12:54:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652903674; cv=none; d=google.com; s=arc-20160816; b=jS5+5yFVRMASfXp5xvPSxbjv9e0dI5T0M9OzJQ+jFk6lerSSY/nDkxZFiKylV78wNk yaQ5LOsjIUKZGGoi95lgnCXjyqMrWwIQwitaQE/W141bN6Ziw3QLVE+QmoMnz0Czzmkd L4W8HR1SCIM/ehnR18m2GQueyKJjk48/1Q/uvqknrlcFyV6ezaE6oIlKerjlVsmsn4En 2nMbQMYnUbjyJXhnww53NVgQXYEj7eUx1LvyPXDctxyrjMCGpHBdNBHhar5Y0lGzTIV1 MfMcX42x1TiwfmXxgtYNKZCcHWsjl3vg6jU3d6nRU3WWBFFFYS/liY/0WNsgtiI94zVT Qutg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=5q8BLVP39pZEp8vGRlvu+IzyMqb+h/dIvWxZHWF016Q=; b=zwCHMsZXaqpWhcL2hab4SAXS4KoVdV2uHYUn7/BHuYwpU5dkN0EyNgopFQycx+Usgm 1X/qZqVQ6Zb42trAhHMnSuf7BnxDEzEo11BNUhm13T4/QTb4D9frtqKp7t+knudDjWSk rK+rhXkX6RsB8pTfWWrsNZr9fatFC3oSVPQApCCU9BoFZR6DC6JoJqE3Ixljizwv4zBo sGzczmvZIhw5CpNjhYawGY0cXMtx4b8Rcg/kTvNmIEUrSZL7FAM1xwTm+WCvXQMj7LHK 1LsrYp7ZLum31H0EIAXFOAcQzHQ+IxebtE0KFSwQOXaRFuisdVcC8Mkyjoq/xBOmbwQO qg/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x2-20020a170902ec8200b00161d49abce7si1058655plg.140.2022.05.18.12.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 12:54:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 84C4D19FB20; Wed, 18 May 2022 12:52:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242104AbiERTwd (ORCPT + 99 others); Wed, 18 May 2022 15:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242086AbiERTw0 (ORCPT ); Wed, 18 May 2022 15:52:26 -0400 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E341F16D5D1 for ; Wed, 18 May 2022 12:52:23 -0700 (PDT) Received: by mail-qk1-f170.google.com with SMTP id bs17so2351783qkb.0 for ; Wed, 18 May 2022 12:52:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5q8BLVP39pZEp8vGRlvu+IzyMqb+h/dIvWxZHWF016Q=; b=Q9GC79T/P96mMBftqYaeHmEiNtVD0xcPB1RfmbdbEzYUZOHgMNFOBzMr6QLlvBUi5k K/veBn0ZQMMuDP4Wpw+1dRPlV+OREh22ihdj/N54gGfacUBSPm7CBN+RjjBZMursYPG4 GbN4DPLNnk+mR0XjZatvAxSHR/HfonAiX8LJt6SOtB/CkXm05pwSodnEikisJE39sil8 Iod67fIYSWcJdyda0+rqWnKpxv5P/njec9qth+fTKfx/ZL2piT291VI9SpsJ6RyOWvI5 p9IgooYQGvhgIeeH2lvZItBzIZQIZkWTJTPTi5QMrh1my/++btKklxdSabOKxo+1L6lN L8bA== X-Gm-Message-State: AOAM530xyX0omhQ/ovF7sj1yWObP5ayKMQqcd9Mlem/B5YS06B8/2kyS mftM7ebYupnB/hz6GuQNbDCv X-Received: by 2002:a05:620a:414b:b0:6a0:5c30:66fb with SMTP id k11-20020a05620a414b00b006a05c3066fbmr826967qko.53.1652903543069; Wed, 18 May 2022 12:52:23 -0700 (PDT) Received: from localhost (pool-68-160-176-52.bstnma.fios.verizon.net. [68.160.176.52]) by smtp.gmail.com with ESMTPSA id v14-20020a05622a188e00b002f8f406338fsm87014qtc.42.2022.05.18.12.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 12:52:22 -0700 (PDT) Date: Wed, 18 May 2022 15:52:21 -0400 From: Mike Snitzer To: Matthias Kaehlcke Cc: Alasdair Kergon , Kees Cook , James Morris , "Serge E . Hallyn" , dm-devel@redhat.com, Douglas Anderson , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu , linux-security-module@vger.kernel.org Subject: Re: [PATCH v4 1/3] dm: Add verity helpers for LoadPin Message-ID: References: <20220517233457.1123309-1-mka@chromium.org> <20220517163437.v4.1.I3e928575a23481121e73286874c4c2bdb403355d@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220517163437.v4.1.I3e928575a23481121e73286874c4c2bdb403355d@changeid> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 17 2022 at 7:34P -0400, Matthias Kaehlcke wrote: > LoadPin limits loading of kernel modules, firmware and certain > other files to a 'pinned' file system (typically a read-only > rootfs). To provide more flexibility LoadPin is being extended > to also allow loading these files from trusted dm-verity > devices. For that purpose LoadPin can be provided with a list > of verity root digests that it should consider as trusted. > > Add a bunch of helpers to allow LoadPin to check whether a DM > device is a trusted verity device. The new functions broadly > fall in two categories: those that need access to verity > internals (like the root digest), and the 'glue' between > LoadPin and verity. The new file dm-verity-loadpin.c contains > the glue functions. > > Signed-off-by: Matthias Kaehlcke > --- > > Changes in v4: > - a trusted verity device must have a single target of > type 'verity' > - share list of verity digests with loadpin, deleted > dm_verity_loadpin_set_trusted_root_digests() > - dm_verity_loadpin_is_md_trusted() is now dm_verity_loadpin_is_sb_trusted(), > it receives a super_block instead of mapped_device. Updated kernel doc. > - changed struct trusted_root_digest to have an unsized > u8 array instead of a pointer > - extend 'dm-verity-objs' instead of 'dm-mod-objs' > > Changes in v3: > - none > > Changes in v2: > - none > > drivers/md/Makefile | 6 +++ > drivers/md/dm-verity-loadpin.c | 74 +++++++++++++++++++++++++++++++ > drivers/md/dm-verity-target.c | 33 ++++++++++++++ > drivers/md/dm-verity.h | 4 ++ > include/linux/dm-verity-loadpin.h | 27 +++++++++++ > 5 files changed, 144 insertions(+) > create mode 100644 drivers/md/dm-verity-loadpin.c > create mode 100644 include/linux/dm-verity-loadpin.h > > diff --git a/drivers/md/Makefile b/drivers/md/Makefile > index 0454b0885b01..71771901c823 100644 > --- a/drivers/md/Makefile > +++ b/drivers/md/Makefile > @@ -108,6 +108,12 @@ ifeq ($(CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG),y) > dm-verity-objs += dm-verity-verify-sig.o > endif > > +ifeq ($(CONFIG_DM_VERITY),y) > +ifeq ($(CONFIG_SECURITY_LOADPIN),y) > +dm-verity-objs += dm-verity-loadpin.o > +endif > +endif > + > ifeq ($(CONFIG_DM_AUDIT),y) > dm-mod-objs += dm-audit.o > endif > diff --git a/drivers/md/dm-verity-loadpin.c b/drivers/md/dm-verity-loadpin.c > new file mode 100644 > index 000000000000..3226fbe4a1fe > --- /dev/null > +++ b/drivers/md/dm-verity-loadpin.c > @@ -0,0 +1,74 @@ > +// SPDX-License-Identifier: GPL-2.0-only > + > +#include > +#include > +#include > + > +#include "dm.h" > +#include "dm-verity.h" > + > +#define DM_MSG_PREFIX "verity-loadpin" > + > +LIST_HEAD(loadpin_trusted_verity_root_digests); > + > +static bool is_trusted_verity_target(struct dm_target *ti) > +{ > + u8 *root_digest; > + unsigned int digest_size; > + struct trusted_root_digest *trd; > + bool trusted = false; > + > + if (!dm_is_verity_target(ti)) > + return false; > + > + if (dm_verity_get_root_digest(ti, &root_digest, &digest_size)) > + return false; > + > + list_for_each_entry(trd, &loadpin_trusted_verity_root_digests, node) { > + if ((trd->len == digest_size) && > + !memcmp(trd->data, root_digest, digest_size)) { > + trusted = true; > + break; > + } > + } > + > + kfree(root_digest); > + > + return trusted; > +} > + > +/* > + * Determines whether the file system of a superblock is located on > + * a verity device that is trusted by LoadPin. > + */ > +bool dm_verity_loadpin_is_sb_trusted(struct super_block *sb) > +{ > + struct mapped_device *md; > + struct dm_table *table; > + struct dm_target *ti; > + int srcu_idx; > + bool trusted = false; > + > + if (list_empty(&loadpin_trusted_verity_root_digests)) > + return false; > + > + md = dm_get_md(sb->s_bdev->bd_dev); > + if (!md) > + return false; > + > + table = dm_get_live_table(md, &srcu_idx); > + > + if (dm_table_get_num_targets(table) != 1) > + goto out; > + > + ti = dm_table_get_target(table, 0); > + > + if (is_trusted_verity_target(ti)) > + trusted = true; > + > +out: > + dm_put_live_table(md, srcu_idx); > + dm_put(md); > + > + return trusted; > +} Not seeing why passing a super_block a block layer interface was chosen. Please pass the super_block's block_device and rename to dm_verity_loadpin_is_bdev_trusted() Thanks, Mike