From nobody Mon May 11 02:06:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87030C4332F for ; Mon, 18 Apr 2022 21:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237880AbiDRVS6 (ORCPT ); Mon, 18 Apr 2022 17:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347973AbiDRVSs (ORCPT ); Mon, 18 Apr 2022 17:18:48 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7E8D2CE26 for ; Mon, 18 Apr 2022 14:16:07 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id u2so21092145pgq.10 for ; Mon, 18 Apr 2022 14:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3NUaPl7T9VDjPF5pSPc597gsFG5v6iWsZQaLgLfeQww=; b=UBDOLR+Mh24DHdsNmC7ttDSdUYYhK71ZxlqJFIvEiPoTYFmr87XRbhqUuJe0zKDfii TXW8I3yWCcvYyiqCHPxV7WfB/4n0bNzymbHzIArdU4+e6O3lq47ucuRYaCgHGlvDjSGO B20sYxYIBFP2mUCRci3ZuhiR27q5GeyeAYpPg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3NUaPl7T9VDjPF5pSPc597gsFG5v6iWsZQaLgLfeQww=; b=YLYLx3Nxzmxyk8LLLm6hRYf4YUvS7aEpR9jOUBwDZhAXZHwtKkJHalxgYfDGN4dxDu 8LghyLxWLx+4CNVjWWv3kdU4cOR7bAOQ/lEHWgJgw04eUOqAgXwN3HPuxZzaBSo+I0Qc i9CvoTDfLkoNZYIUdHIlo7sl4/gIs6YSD5xTuq/2rujFISXHNvpYooYXddyAg+PgQELa 7q39mKEwLqTUJ9y0Pz+LhsPXslQo7BhJquHGzKJgQ33G2nLiJsOmw2Y9cSYuiIUlFmTm rS3hnH9/HN7rRYvAixcZoIT2GpGWxpSffdBEfRHQdmC9XaXB5YQcZibspZQxFoGccY7T JWyA== X-Gm-Message-State: AOAM531509mUKZM5LRnIKDXvLhs+Eac2e7YiYbYFkw5LxRzQuc2LzJ0F yhTAAzLMrjAB7NnXCxl4Qa4HBA== X-Google-Smtp-Source: ABdhPJyQQEFDCs5IVHAM/UnOWzfEHFGUzBQrHu06Pf6Bm6srYRBFZ5pue0X3KWczqh0V440cxpFgFA== X-Received: by 2002:a05:6a00:1786:b0:50a:7f5a:e280 with SMTP id s6-20020a056a00178600b0050a7f5ae280mr4803956pfg.25.1650316567469; Mon, 18 Apr 2022 14:16:07 -0700 (PDT) Received: from localhost ([2620:15c:202:201:6b32:a0a5:ec32:c287]) by smtp.gmail.com with UTF8SMTPSA id w13-20020a17090a5e0d00b001c7d4099670sm13858457pjf.28.2022.04.18.14.16.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Apr 2022 14:16:06 -0700 (PDT) From: Matthias Kaehlcke To: Alasdair Kergon , Mike Snitzer , Kees Cook , James Morris , "Serge E . Hallyn" Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , linux-security-module@vger.kernel.org, Douglas Anderson , dm-devel@redhat.com, Matthias Kaehlcke Subject: [PATCH 1/3] dm: Add verity helpers for LoadPin Date: Mon, 18 Apr 2022 14:15:57 -0700 Message-Id: <20220418141545.1.I3e928575a23481121e73286874c4c2bdb403355d@changeid> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418211559.3832724-1-mka@chromium.org> References: <20220418211559.3832724-1-mka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- drivers/md/Makefile | 6 +++ drivers/md/dm-verity-loadpin.c | 80 +++++++++++++++++++++++++++++++ drivers/md/dm-verity-target.c | 34 +++++++++++++ drivers/md/dm-verity.h | 4 ++ include/linux/dm-verity-loadpin.h | 27 +++++++++++ 5 files changed, 151 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..e12cd004d375 100644 --- a/drivers/md/Makefile +++ b/drivers/md/Makefile @@ -100,6 +100,12 @@ ifeq ($(CONFIG_IMA),y) dm-mod-objs +=3D dm-ima.o endif =20 +ifeq ($(CONFIG_DM_VERITY),y) +ifeq ($(CONFIG_SECURITY_LOADPIN),y) +dm-mod-objs +=3D dm-verity-loadpin.o +endif +endif + ifeq ($(CONFIG_DM_VERITY_FEC),y) dm-verity-objs +=3D dm-verity-fec.o endif diff --git a/drivers/md/dm-verity-loadpin.c b/drivers/md/dm-verity-loadpin.c new file mode 100644 index 000000000000..972ca93a2231 --- /dev/null +++ b/drivers/md/dm-verity-loadpin.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +#include "dm.h" +#include "dm-verity.h" + +static struct list_head *trusted_root_digests; + +/* + * Sets the root digests of verity devices which LoadPin considers as trus= ted. + * + * This function must only be called once. + */ +void dm_verity_loadpin_set_trusted_root_digests(struct list_head *digests) +{ + if (!trusted_root_digests) + trusted_root_digests =3D digests; + else + pr_warn("verity root digests trusted by LoadPin are already set!!!\n"); +} + +static bool is_trusted_verity_target(struct dm_target *ti) +{ + u8 *root_digest; + unsigned int digest_size; + struct trusted_root_digest *trd; + bool trusted =3D 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, trusted_root_digests, node) { + if ((trd->len =3D=3D digest_size) && + !memcmp(trd->data, root_digest, digest_size)) { + trusted =3D true; + break; + } + } + + kfree(root_digest); + + return trusted; +} + +/* + * Determines whether a mapped device is a verity device that is trusted + * by LoadPin. + */ +bool dm_verity_loadpin_is_md_trusted(struct mapped_device *md) +{ + int srcu_idx; + struct dm_table *table; + unsigned int num_targets; + bool trusted =3D false; + int i; + + if (!trusted_root_digests || list_empty(trusted_root_digests)) + return false; + + table =3D dm_get_live_table(md, &srcu_idx); + num_targets =3D dm_table_get_num_targets(table); + for (i =3D 0; i < num_targets; i++) { + struct dm_target *ti =3D dm_table_get_target(table, i); + + if (is_trusted_verity_target(ti)) { + trusted =3D true; + break; + } + } + + dm_put_live_table(md, srcu_idx); + + return trusted; +} diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 80133aae0db3..6bea9692cd39 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -16,9 +16,11 @@ #include "dm-verity.h" #include "dm-verity-fec.h" #include "dm-verity-verify-sig.h" +#include #include #include #include +#include =20 #define DM_MSG_PREFIX "verity" =20 @@ -1310,6 +1312,38 @@ static int verity_ctr(struct dm_target *ti, unsigned= argc, char **argv) return r; } =20 +/* + * Check whether a DM target is a verity target. + */ +bool dm_is_verity_target(struct dm_target *ti) +{ + return ti->type->module =3D=3D THIS_MODULE; +} +EXPORT_SYMBOL_GPL(dm_is_verity_target); + +/* + * Get the root digest of a verity target. + * + * Returns a copy of the root digests, the caller is responsible for + * freeing the memory of the digest. + */ +int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest, unsi= gned int *digest_size) +{ + struct dm_verity *v =3D ti->private; + + if (!dm_is_verity_target(ti)) + return -EINVAL; + + *root_digest =3D kmemdup(v->root_digest, v->digest_size, GFP_KERNEL); + if (*root_digest =3D=3D NULL) + return -ENOMEM; + + *digest_size =3D v->digest_size; + + return 0; +} +EXPORT_SYMBOL_GPL(dm_verity_get_root_digest); + static struct target_type verity_target =3D { .name =3D "verity", .version =3D {1, 8, 0}, diff --git a/drivers/md/dm-verity.h b/drivers/md/dm-verity.h index 4e769d13473a..c832cc3e3d24 100644 --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -129,4 +129,8 @@ extern int verity_hash(struct dm_verity *v, struct ahas= h_request *req, extern int verity_hash_for_block(struct dm_verity *v, struct dm_verity_io = *io, sector_t block, u8 *digest, bool *is_zero); =20 +extern bool dm_is_verity_target(struct dm_target *ti); +extern int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_diges= t, + unsigned int *digest_size); + #endif /* DM_VERITY_H */ diff --git a/include/linux/dm-verity-loadpin.h b/include/linux/dm-verity-lo= adpin.h new file mode 100644 index 000000000000..12a86911d05a --- /dev/null +++ b/include/linux/dm-verity-loadpin.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_DM_VERITY_LOADPIN_H +#define __LINUX_DM_VERITY_LOADPIN_H + +#include + +struct mapped_device; + +struct trusted_root_digest { + u8 *data; + unsigned int len; + struct list_head node; +}; + +#if IS_ENABLED(CONFIG_SECURITY_LOADPIN) && IS_BUILTIN(CONFIG_DM_VERITY) +void dm_verity_loadpin_set_trusted_root_digests(struct list_head *digests); +bool dm_verity_loadpin_is_md_trusted(struct mapped_device *md); +#else +static inline void dm_verity_loadpin_set_trusted_root_digests(struct list_= head *digests) {} +static inline bool dm_verity_loadpin_is_md_trusted(struct mapped_device *m= d) +{ + return false; +} +#endif + +#endif /* __LINUX_DM_LOADPIN_H */ --=20 2.36.0.rc0.470.gd361397f0d-goog From nobody Mon May 11 02:06:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C1EBC433FE for ; Mon, 18 Apr 2022 21:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347991AbiDRVTA (ORCPT ); Mon, 18 Apr 2022 17:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347986AbiDRVS5 (ORCPT ); Mon, 18 Apr 2022 17:18:57 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 097652CE2B for ; Mon, 18 Apr 2022 14:16:10 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id t4so21110378pgc.1 for ; Mon, 18 Apr 2022 14:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z7MNQdhfJevonqU1gbIMWRC7hAVlhGusKX2oocNDGwg=; b=FAuNNboCO/FPFJkwp5PqYbA8WCixhPEvKA7SW9KlYH7NB9BrlBhq3b1FZlX0I8Xvbm 7ci+OWsvOyoWgrqCnm7OdfTfdp+eBZlK1swkaGRRPb36gVeU4JmZDP5PrtFk+SNkh7Vv kagm8tkFyJYvDDNS7r2EcUUpbk25fGTC1fcYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z7MNQdhfJevonqU1gbIMWRC7hAVlhGusKX2oocNDGwg=; b=GDzEXjtcMuINzmzQj2f1ISMo2KdLYUx+Tp0WSTCSKF6CQJSdzgTGVtiv+v0MSCR0/X LDCEh17m8XU8uIHMn9q7e4Z7so+vJixh4sBCVi3sS+rPooSLDfgouiDV29+TDCeDRAV7 ocHjp1/jFumIXZxyshEo7OEWkTNiBEjIiLwvQ5aZFNsk8+fx5xu9QA8k297CDkiYXT3J eEn1og3HWjRaNqU+T95uTzrNA8UsUkxSig0ZBDJ8uKsmkgJOs6DJ00aNS5LNegRLVyzB i6iVzeHRz0/kUlPd8yK3q7olUgoGOOjLL87UVGqwK1F8kRoKAaowi/fczE9pA2xCyWb9 Sywg== X-Gm-Message-State: AOAM533fHdmu1dXR4tMpk8yNf5Z9CMrI6SRM+Yk/umN6URFNpYdriSw7 Ab3TPyfKedfcS4X0G1FWGhRuSQ== X-Google-Smtp-Source: ABdhPJx4kToyubC6lCeN87zCNmuEOzpd1tCZwNVPjLaJyswe8LBMciizDAJKihUrNCpdY9/hLsvQhQ== X-Received: by 2002:a05:6a00:a26:b0:4fd:f9dd:549c with SMTP id p38-20020a056a000a2600b004fdf9dd549cmr14275958pfh.42.1650316569446; Mon, 18 Apr 2022 14:16:09 -0700 (PDT) Received: from localhost ([2620:15c:202:201:6b32:a0a5:ec32:c287]) by smtp.gmail.com with UTF8SMTPSA id n24-20020aa79058000000b0050612d0fe01sm13406325pfo.2.2022.04.18.14.16.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Apr 2022 14:16:08 -0700 (PDT) From: Matthias Kaehlcke To: Alasdair Kergon , Mike Snitzer , Kees Cook , James Morris , "Serge E . Hallyn" Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , linux-security-module@vger.kernel.org, Douglas Anderson , dm-devel@redhat.com, Matthias Kaehlcke Subject: [PATCH 2/3] LoadPin: Enable loading from trusted dm-verity devices Date: Mon, 18 Apr 2022 14:15:58 -0700 Message-Id: <20220418141545.2.I01c67af41d2f6525c6d023101671d7339a9bc8b5@changeid> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418211559.3832724-1-mka@chromium.org> References: <20220418211559.3832724-1-mka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extend LoadPin to allow loading of kernel files from trusted dm-verity [1] devices. This change adds the concept of trusted verity devices to LoadPin. Userspace can use the new systl file 'loadpin/trusted_verity_root_digests' to provide LoadPin with a list of root digests from dm-verity devices that LoadPin should consider as trusted. When a kernel file is read LoadPin first checks (as usual) whether the file is located on the pinned root, if so the file can be loaded. Otherwise, if the verity extension is enabled, LoadPin determines whether the file is located on a verity backed device and whether the root digest of that device is in the list of trusted digests. The file can be loaded if the verity device has a trusted root digest. The list of trusted root digests can only be written once (typically at boot time), to limit the possiblity of attackers setting up rogue verity devices and marking them as trusted. Background: As of now LoadPin restricts loading of kernel files to a single pinned filesystem, typically the rootfs. This works for many systems, however it can result in a bloated rootfs (and OTA updates) on platforms where multiple boards with different hardware configurations use the same rootfs image. Especially when 'optional' files are large it may be preferable to download/install them only when they are actually needed by a given board. Chrome OS uses Downloadable Content (DLC) [2] to deploy certain 'packages' at runtime. As an example a DLC package could contain firmware for a peripheral that is not present on all boards. DLCs use dm-verity to verify the integrity of the DLC content. [1] https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity= .html [2] https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/dlcservic= e/docs/developer.md Signed-off-by: Matthias Kaehlcke Reported-by: kernel test robot --- security/loadpin/Kconfig | 11 +++ security/loadpin/loadpin.c | 168 ++++++++++++++++++++++++++++++++++++- 2 files changed, 178 insertions(+), 1 deletion(-) diff --git a/security/loadpin/Kconfig b/security/loadpin/Kconfig index 91be65dec2ab..cf3e6431e02d 100644 --- a/security/loadpin/Kconfig +++ b/security/loadpin/Kconfig @@ -18,3 +18,14 @@ config SECURITY_LOADPIN_ENFORCE If selected, LoadPin will enforce pinning at boot. If not selected, it can be enabled at boot with the kernel parameter "loadpin.enforce=3D1". + +config SECURITY_LOADPIN_VERITY + bool "Allow reading files from certain other filesystems that use dm-veri= ty" + depends on DM_VERITY=3Dy + help + If selected LoadPin can allow reading files from filesystems + that use dm-verity. A verity filesystem can be configured as + being trusted by LoadPin by writing its root digest to the + sysctl file 'trusted_verity_root_digests'. The sysctl file + can only be written once (typically at boot) and accepts a + list of comma separated digests. diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c index b12f7d986b1e..b9c174f8687d 100644 --- a/security/loadpin/loadpin.c +++ b/security/loadpin/loadpin.c @@ -18,6 +18,8 @@ #include #include /* current */ #include +#include +#include =20 static void report_load(const char *origin, struct file *file, char *opera= tion) { @@ -43,6 +45,10 @@ static char *exclude_read_files[READING_MAX_ID]; static int ignore_read_file_id[READING_MAX_ID] __ro_after_init; static struct super_block *pinned_root; static DEFINE_SPINLOCK(pinned_root_spinlock); +#ifdef CONFIG_SECURITY_LOADPIN_VERITY +static bool verity_digests_set; +static LIST_HEAD(trusted_verity_root_digests); +#endif =20 #ifdef CONFIG_SYSCTL =20 @@ -65,6 +71,144 @@ static struct ctl_table loadpin_sysctl_table[] =3D { { } }; =20 +#ifdef CONFIG_SECURITY_LOADPIN_VERITY + +static int proc_verity_root_digests(struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + struct trusted_root_digest *trd; + char *buf; + int rc; + + if (write) { + struct ctl_table tbl =3D *table; + char *p, *d; + + if (*ppos) + return -EINVAL; + + if (verity_digests_set) + return -EPERM; + + buf =3D kzalloc(tbl.maxlen, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + tbl.data =3D buf; + + rc =3D proc_dostring(&tbl, write, buffer, lenp, ppos); + if (rc) { + kfree(buf); + return rc; + } + + if (strlen(buf) =3D=3D 0) { + verity_digests_set =3D true; + return false; + } + + p =3D buf; + while ((d =3D strsep(&p, ",")) !=3D NULL) { + int len =3D strlen(d); + + if (len % 2) { + rc =3D -EINVAL; + goto err; + } + + len /=3D 2; + + trd =3D kzalloc(sizeof(*trd), GFP_KERNEL); + if (!trd) { + rc =3D -ENOMEM; + goto err; + } + + list_add_tail(&trd->node, &trusted_verity_root_digests); + + trd->data =3D kzalloc(len, GFP_KERNEL); + if (!trd->data) { + rc =3D -ENOMEM; + goto err; + } + + if (hex2bin(trd->data, d, len)) { + rc =3D -EINVAL; + goto err; + } + + trd->len =3D len; + } + + kfree(buf); + + if (!list_empty(&trusted_verity_root_digests)) { + dm_verity_loadpin_set_trusted_root_digests(&trusted_verity_root_digests= ); + verity_digests_set =3D true; + } + } else { + struct ctl_table tbl =3D { .maxlen =3D 0 }; + size_t off =3D 0; + + list_for_each_entry(trd, &trusted_verity_root_digests, node) { + /* two ASCII characters per byte and a comma / '\0' */ + tbl.maxlen +=3D (trd->len * 2) + 1; + } + + tbl.data =3D kzalloc(tbl.maxlen, GFP_KERNEL); + + list_for_each_entry(trd, &trusted_verity_root_digests, node) { + int i; + + if (off > 0) { + snprintf(tbl.data + off, tbl.maxlen - off, ","); + off++; + } + + for (i =3D 0; i < trd->len; i++) { + snprintf(tbl.data + off, tbl.maxlen - off, "%02x", trd->data[i]); + off +=3D 2; + } + } + + proc_dostring(&tbl, write, buffer, lenp, ppos); + kfree(tbl.data); + } + + return 0; + +err: + kfree(buf); + + { + struct trusted_root_digest *tmp; + + list_for_each_entry_safe(trd, tmp, &trusted_verity_root_digests, node) { + kfree(trd->data); + list_del(&trd->node); + kfree(trd); + } + } + + return rc; +} + +static struct ctl_table loadpin_sysctl_table_verity[] =3D { + { + .procname =3D "trusted_verity_root_digests", + .maxlen =3D SZ_4K, + .mode =3D 0644, + .proc_handler =3D proc_verity_root_digests, + }, + + { } +}; +#else + +static struct ctl_table loadpin_sysctl_table_verity[] =3D {}; + +#endif /* CONFIG_SECURITY_LOADPIN_VERITY */ + /* * This must be called after early kernel init, since then the rootdev * is available. @@ -118,6 +262,20 @@ static void loadpin_sb_free_security(struct super_bloc= k *mnt_sb) } } =20 +static bool loadpin_is_fs_trusted(struct super_block *sb) +{ + struct mapped_device *md =3D dm_get_md(sb->s_bdev->bd_dev); + bool trusted; + + if (!md) + return false; + + trusted =3D dm_verity_loadpin_is_md_trusted(md); + dm_put(md); + + return trusted; +} + static int loadpin_read_file(struct file *file, enum kernel_read_file_id i= d, bool contents) { @@ -174,7 +332,8 @@ static int loadpin_read_file(struct file *file, enum ke= rnel_read_file_id id, spin_unlock(&pinned_root_spinlock); } =20 - if (IS_ERR_OR_NULL(pinned_root) || load_root !=3D pinned_root) { + if (IS_ERR_OR_NULL(pinned_root) || + ((load_root !=3D pinned_root) && !loadpin_is_fs_trusted(load_root))) { if (unlikely(!enforce)) { report_load(origin, file, "pinning-ignored"); return 0; @@ -240,6 +399,13 @@ static int __init loadpin_init(void) enforce ? "" : "not "); parse_exclude(); security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin"); + + if (IS_ENABLED(CONFIG_SECURITY_LOADPIN_VERITY)) { + if (!register_sysctl_paths(loadpin_sysctl_path, + loadpin_sysctl_table_verity)) + pr_notice("sysctl registration failed!\n"); + } + return 0; } =20 --=20 2.36.0.rc0.470.gd361397f0d-goog From nobody Mon May 11 02:06:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95E01C433F5 for ; Mon, 18 Apr 2022 21:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348004AbiDRVTF (ORCPT ); Mon, 18 Apr 2022 17:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347990AbiDRVS5 (ORCPT ); Mon, 18 Apr 2022 17:18:57 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23D9D2D1C2 for ; Mon, 18 Apr 2022 14:16:12 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id bg24so14033902pjb.1 for ; Mon, 18 Apr 2022 14:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qm/BmS5rZykflggAWLelmGp8fWeLhZCgEzC+nt/A6s4=; b=jOGlGDc4Wz6w//dtoJeqZYjBwmgJ9X0uBmiWSlHHhhny2QoTzwVyv3a/QnVezngt8l 3ttINehXise0pulBtGu+lsTlr5/YM61z/YnIc3bJtEjb2TyAH4JhublL+rlgv5TvhhtK wp3ot4iekb0EvbU7nv54WtdXLzyXLG7sI6Sbs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qm/BmS5rZykflggAWLelmGp8fWeLhZCgEzC+nt/A6s4=; b=4p8aaoLNjAFgxOZC48mdBnYEih+B3xyON87De0uJr44uxvRMgLmB+tYg5eSZfhC2KM uI4o3ZvgK4YfkubDxjgLlXDg6qEV0DPKDybu3Ilec8yaHDht4QgYoWFsdkmA10/Omxrt ka3OSaCejdpfL7RT/sTPszfmp92UrCxspFyO50dhERpB3Dp5dhYc1OtVxBO4+8sflOU3 umY8CAZaFOccXN9gYWe3KNVBEWdOe+JvF3MsP1C/Hq3iDaOvOmBbq0hcnGR6VwBG+6eP h2jnat3lnDHAWyGZsC0xrSOyHnNbplKgzWBpPcxNncFcOZBhhUz8dmZxa5G8Aud6G5BX Nzxw== X-Gm-Message-State: AOAM532YTUxHyR43+XgOA4LgLWA7RTsLSQlIilqwQ8rAXmU61qXEyXHK bX1WgTAREMSZ0l6lkCXSaktanA== X-Google-Smtp-Source: ABdhPJwvT6hPqXjTca3Xc2+bb0JBOY7ovGiOak9BOvmgcSEBCUg/Tyd1ChxcMzkWocvs0mSZVqmGYw== X-Received: by 2002:a17:90b:4b01:b0:1d2:abf5:c83f with SMTP id lx1-20020a17090b4b0100b001d2abf5c83fmr4999347pjb.93.1650316571711; Mon, 18 Apr 2022 14:16:11 -0700 (PDT) Received: from localhost ([2620:15c:202:201:6b32:a0a5:ec32:c287]) by smtp.gmail.com with UTF8SMTPSA id d16-20020a17090a02d000b001cba39c88fcsm1487068pjd.0.2022.04.18.14.16.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Apr 2022 14:16:11 -0700 (PDT) From: Matthias Kaehlcke To: Alasdair Kergon , Mike Snitzer , Kees Cook , James Morris , "Serge E . Hallyn" Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Song Liu , linux-security-module@vger.kernel.org, Douglas Anderson , dm-devel@redhat.com, Matthias Kaehlcke Subject: [PATCH 3/3] dm: verity-loadpin: Use CONFIG_SECURITY_LOADPIN_VERITY for conditional compilation Date: Mon, 18 Apr 2022 14:15:59 -0700 Message-Id: <20220418141545.3.I5aca2dcc3b06de4bf53696cd21329dce8272b8aa@changeid> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog In-Reply-To: <20220418211559.3832724-1-mka@chromium.org> References: <20220418211559.3832724-1-mka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The verity glue for LoadPin is only needed when CONFIG_SECURITY_LOADPIN_VER= ITY is set, use this option for conditional compilation instead of the combo of CONFIG_DM_VERITY and CONFIG_SECURITY_LOADPIN. Signed-off-by: Matthias Kaehlcke --- drivers/md/Makefile | 7 +------ include/linux/dm-verity-loadpin.h | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/md/Makefile b/drivers/md/Makefile index e12cd004d375..a96441752ec7 100644 --- a/drivers/md/Makefile +++ b/drivers/md/Makefile @@ -83,6 +83,7 @@ obj-$(CONFIG_DM_LOG_WRITES) +=3D dm-log-writes.o obj-$(CONFIG_DM_INTEGRITY) +=3D dm-integrity.o obj-$(CONFIG_DM_ZONED) +=3D dm-zoned.o obj-$(CONFIG_DM_WRITECACHE) +=3D dm-writecache.o +obj-$(CONFIG_SECURITY_LOADPIN_VERITY) +=3D dm-verity-loadpin.o =20 ifeq ($(CONFIG_DM_INIT),y) dm-mod-objs +=3D dm-init.o @@ -100,12 +101,6 @@ ifeq ($(CONFIG_IMA),y) dm-mod-objs +=3D dm-ima.o endif =20 -ifeq ($(CONFIG_DM_VERITY),y) -ifeq ($(CONFIG_SECURITY_LOADPIN),y) -dm-mod-objs +=3D dm-verity-loadpin.o -endif -endif - ifeq ($(CONFIG_DM_VERITY_FEC),y) dm-verity-objs +=3D dm-verity-fec.o endif diff --git a/include/linux/dm-verity-loadpin.h b/include/linux/dm-verity-lo= adpin.h index 12a86911d05a..be63ac76f98d 100644 --- a/include/linux/dm-verity-loadpin.h +++ b/include/linux/dm-verity-loadpin.h @@ -13,7 +13,7 @@ struct trusted_root_digest { struct list_head node; }; =20 -#if IS_ENABLED(CONFIG_SECURITY_LOADPIN) && IS_BUILTIN(CONFIG_DM_VERITY) +#if IS_ENABLED(CONFIG_SECURITY_LOADPIN_VERITY) void dm_verity_loadpin_set_trusted_root_digests(struct list_head *digests); bool dm_verity_loadpin_is_md_trusted(struct mapped_device *md); #else --=20 2.36.0.rc0.470.gd361397f0d-goog