All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-04-26 21:31 ` Matthias Kaehlcke
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: linux-kernel, linux-security-module, dm-devel, linux-raid,
	Douglas Anderson, Song Liu, Matthias Kaehlcke

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) [1] 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 [2] to verify the
integrity of the DLC content.

This series extends LoadPin to allow loading of kernel files
from trusted dm-verity devices. It adds the concept of
trusted verity devices to LoadPin. Userspace can use the new
systl file 'loadpin/trusted_verity_root_digests_path' to
provide LoadPin with the path of a file with a list of root
digests from dm-verity devices that LoadPin should consider
as trusted. This file must be located on the pinned root.

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 path of the file with the trusted root digests can
only be written once, which is typically done at boot time.

[1] https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/dlcservice/docs/developer.md
[2] https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html

(no changes since v1)

Matthias Kaehlcke (3):
  dm: Add verity helpers for LoadPin
  LoadPin: Enable loading from trusted dm-verity devices
  dm: verity-loadpin: Use CONFIG_SECURITY_LOADPIN_VERITY for conditional
    compilation

 drivers/md/Makefile               |   1 +
 drivers/md/dm-verity-loadpin.c    |  80 ++++++++++++
 drivers/md/dm-verity-target.c     |  33 +++++
 drivers/md/dm-verity.h            |   4 +
 include/linux/dm-verity-loadpin.h |  27 ++++
 security/loadpin/Kconfig          |  16 +++
 security/loadpin/loadpin.c        | 200 +++++++++++++++++++++++++++++-
 7 files changed, 360 insertions(+), 1 deletion(-)
 create mode 100644 drivers/md/dm-verity-loadpin.c
 create mode 100644 include/linux/dm-verity-loadpin.h

-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dm-devel] [PATCH v2 0/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-04-26 21:31 ` Matthias Kaehlcke
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: dm-devel, linux-kernel, Douglas Anderson, linux-raid, Song Liu,
	linux-security-module, Matthias Kaehlcke

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) [1] 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 [2] to verify the
integrity of the DLC content.

This series extends LoadPin to allow loading of kernel files
from trusted dm-verity devices. It adds the concept of
trusted verity devices to LoadPin. Userspace can use the new
systl file 'loadpin/trusted_verity_root_digests_path' to
provide LoadPin with the path of a file with a list of root
digests from dm-verity devices that LoadPin should consider
as trusted. This file must be located on the pinned root.

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 path of the file with the trusted root digests can
only be written once, which is typically done at boot time.

[1] https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/dlcservice/docs/developer.md
[2] https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html

(no changes since v1)

Matthias Kaehlcke (3):
  dm: Add verity helpers for LoadPin
  LoadPin: Enable loading from trusted dm-verity devices
  dm: verity-loadpin: Use CONFIG_SECURITY_LOADPIN_VERITY for conditional
    compilation

 drivers/md/Makefile               |   1 +
 drivers/md/dm-verity-loadpin.c    |  80 ++++++++++++
 drivers/md/dm-verity-target.c     |  33 +++++
 drivers/md/dm-verity.h            |   4 +
 include/linux/dm-verity-loadpin.h |  27 ++++
 security/loadpin/Kconfig          |  16 +++
 security/loadpin/loadpin.c        | 200 +++++++++++++++++++++++++++++-
 7 files changed, 360 insertions(+), 1 deletion(-)
 create mode 100644 drivers/md/dm-verity-loadpin.c
 create mode 100644 include/linux/dm-verity-loadpin.h

-- 
2.36.0.rc2.479.g8af0fa9b8e-goog

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/3] dm: Add verity helpers for LoadPin
  2022-04-26 21:31 ` [dm-devel] " Matthias Kaehlcke
@ 2022-04-26 21:31   ` Matthias Kaehlcke
  -1 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: linux-kernel, linux-security-module, dm-devel, linux-raid,
	Douglas Anderson, Song Liu, Matthias Kaehlcke

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 <mka@chromium.org>
---

Changes in v2:
- none

 drivers/md/Makefile               |  6 +++
 drivers/md/dm-verity-loadpin.c    | 80 +++++++++++++++++++++++++++++++
 drivers/md/dm-verity-target.c     | 33 +++++++++++++
 drivers/md/dm-verity.h            |  4 ++
 include/linux/dm-verity-loadpin.h | 27 +++++++++++
 5 files changed, 150 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			+= dm-ima.o
 endif
 
+ifeq ($(CONFIG_DM_VERITY),y)
+ifeq ($(CONFIG_SECURITY_LOADPIN),y)
+dm-mod-objs			+= dm-verity-loadpin.o
+endif
+endif
+
 ifeq ($(CONFIG_DM_VERITY_FEC),y)
 dm-verity-objs			+= 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 <linux/list.h>
+#include <linux/kernel.h>
+#include <linux/dm-verity-loadpin.h>
+
+#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 trusted.
+ *
+ * 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 = 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 = 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 == digest_size) &&
+		    !memcmp(trd->data, root_digest, digest_size)) {
+			trusted = 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 = false;
+	int i;
+
+	if (!trusted_root_digests || list_empty(trusted_root_digests))
+		return false;
+
+	table = dm_get_live_table(md, &srcu_idx);
+	num_targets = dm_table_get_num_targets(table);
+	for (i = 0; i < num_targets; i++) {
+		struct dm_target *ti = dm_table_get_target(table, i);
+
+		if (is_trusted_verity_target(ti)) {
+			trusted = 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..0638e61dba51 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/reboot.h>
 #include <linux/scatterlist.h>
+#include <linux/string.h>
 
 #define DM_MSG_PREFIX			"verity"
 
@@ -1310,6 +1311,38 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 	return r;
 }
 
+/*
+ * Check whether a DM target is a verity target.
+ */
+bool dm_is_verity_target(struct dm_target *ti)
+{
+	return ti->type->module == 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, unsigned int *digest_size)
+{
+	struct dm_verity *v = ti->private;
+
+	if (!dm_is_verity_target(ti))
+		return -EINVAL;
+
+	*root_digest = kmemdup(v->root_digest, v->digest_size, GFP_KERNEL);
+	if (*root_digest == NULL)
+		return -ENOMEM;
+
+	*digest_size = v->digest_size;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dm_verity_get_root_digest);
+
 static struct target_type verity_target = {
 	.name		= "verity",
 	.version	= {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 ahash_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);
 
+extern bool dm_is_verity_target(struct dm_target *ti);
+extern int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest,
+				     unsigned int *digest_size);
+
 #endif /* DM_VERITY_H */
diff --git a/include/linux/dm-verity-loadpin.h b/include/linux/dm-verity-loadpin.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 <linux/list.h>
+
+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 *md)
+{
+	return false;
+}
+#endif
+
+#endif /* __LINUX_DM_LOADPIN_H */
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [dm-devel] [PATCH v2 1/3] dm: Add verity helpers for LoadPin
@ 2022-04-26 21:31   ` Matthias Kaehlcke
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: dm-devel, linux-kernel, Douglas Anderson, linux-raid, Song Liu,
	linux-security-module, Matthias Kaehlcke

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 <mka@chromium.org>
---

Changes in v2:
- none

 drivers/md/Makefile               |  6 +++
 drivers/md/dm-verity-loadpin.c    | 80 +++++++++++++++++++++++++++++++
 drivers/md/dm-verity-target.c     | 33 +++++++++++++
 drivers/md/dm-verity.h            |  4 ++
 include/linux/dm-verity-loadpin.h | 27 +++++++++++
 5 files changed, 150 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			+= dm-ima.o
 endif
 
+ifeq ($(CONFIG_DM_VERITY),y)
+ifeq ($(CONFIG_SECURITY_LOADPIN),y)
+dm-mod-objs			+= dm-verity-loadpin.o
+endif
+endif
+
 ifeq ($(CONFIG_DM_VERITY_FEC),y)
 dm-verity-objs			+= 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 <linux/list.h>
+#include <linux/kernel.h>
+#include <linux/dm-verity-loadpin.h>
+
+#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 trusted.
+ *
+ * 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 = 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 = 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 == digest_size) &&
+		    !memcmp(trd->data, root_digest, digest_size)) {
+			trusted = 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 = false;
+	int i;
+
+	if (!trusted_root_digests || list_empty(trusted_root_digests))
+		return false;
+
+	table = dm_get_live_table(md, &srcu_idx);
+	num_targets = dm_table_get_num_targets(table);
+	for (i = 0; i < num_targets; i++) {
+		struct dm_target *ti = dm_table_get_target(table, i);
+
+		if (is_trusted_verity_target(ti)) {
+			trusted = 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..0638e61dba51 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/reboot.h>
 #include <linux/scatterlist.h>
+#include <linux/string.h>
 
 #define DM_MSG_PREFIX			"verity"
 
@@ -1310,6 +1311,38 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 	return r;
 }
 
+/*
+ * Check whether a DM target is a verity target.
+ */
+bool dm_is_verity_target(struct dm_target *ti)
+{
+	return ti->type->module == 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, unsigned int *digest_size)
+{
+	struct dm_verity *v = ti->private;
+
+	if (!dm_is_verity_target(ti))
+		return -EINVAL;
+
+	*root_digest = kmemdup(v->root_digest, v->digest_size, GFP_KERNEL);
+	if (*root_digest == NULL)
+		return -ENOMEM;
+
+	*digest_size = v->digest_size;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dm_verity_get_root_digest);
+
 static struct target_type verity_target = {
 	.name		= "verity",
 	.version	= {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 ahash_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);
 
+extern bool dm_is_verity_target(struct dm_target *ti);
+extern int dm_verity_get_root_digest(struct dm_target *ti, u8 **root_digest,
+				     unsigned int *digest_size);
+
 #endif /* DM_VERITY_H */
diff --git a/include/linux/dm-verity-loadpin.h b/include/linux/dm-verity-loadpin.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 <linux/list.h>
+
+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 *md)
+{
+	return false;
+}
+#endif
+
+#endif /* __LINUX_DM_LOADPIN_H */
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
  2022-04-26 21:31 ` [dm-devel] " Matthias Kaehlcke
@ 2022-04-26 21:31   ` Matthias Kaehlcke
  -1 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: linux-kernel, linux-security-module, dm-devel, linux-raid,
	Douglas Anderson, Song Liu, Matthias Kaehlcke

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_path' to provide
LoadPin with the path of a file with a list of root digests
from dm-verity devices that LoadPin should consider as
trusted. This file must be located on the pinned root.

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 path of the file with the trusted root digests can
only be written once, which is typically done at boot time.

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/dlcservice/docs/developer.md

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
I'm still doubting what would be the best way to configure
the list of trusted digests. The approach in v2 of writing
a path through sysctl is flexible, but it also feels a bit
odd. I did some experiments with passing a file descriptor
through sysctl, but it's also odd and has its own issues.
Passing the list through a kernel parameter seems hacky.
A Kconfig string would work, but can be have issues when
the same config is used for different platforms, where
some may have trusted digests and others not.

Changes in v2:
- userspace now passes the path of the file with the verity digests
  via systcl, instead of the digests themselves
- renamed sysctl file to 'trusted_verity_root_digests_path'
- have CONFIG_SECURITY_LOADPIN_VERITY depend on CONFIG_SYSCTL
- updated Kconfig doc
- updated commit message

 security/loadpin/Kconfig   |  16 +++
 security/loadpin/loadpin.c | 200 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 215 insertions(+), 1 deletion(-)

diff --git a/security/loadpin/Kconfig b/security/loadpin/Kconfig
index 91be65dec2ab..20681dc4b8a5 100644
--- a/security/loadpin/Kconfig
+++ b/security/loadpin/Kconfig
@@ -18,3 +18,19 @@ 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=1".
+
+config SECURITY_LOADPIN_VERITY
+	bool "Allow reading files from certain other filesystems that use dm-verity"
+	depends on DM_VERITY=y && SYSCTL
+	help
+	  If selected LoadPin can allow reading files from filesystems
+	  that use dm-verity. LoadPin maintains a list of verity root
+	  digests it considers trusted. A verity backed filesystem is
+	  considered trusted if its root digest is found in the list
+	  of trusted digests.
+
+	  Userspace can populate the list of trusted digests by writing
+	  the path of a file with the digests to the syctl file
+	  'trusted_verity_root_digests_path'. The file must be located
+	  on the pinned root and contain a comma separated list of
+	  digests.
diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
index b12f7d986b1e..db10b7ff6efd 100644
--- a/security/loadpin/loadpin.c
+++ b/security/loadpin/loadpin.c
@@ -18,6 +18,8 @@
 #include <linux/path.h>
 #include <linux/sched.h>	/* current */
 #include <linux/string_helpers.h>
+#include <linux/device-mapper.h>
+#include <linux/dm-verity-loadpin.h>
 
 static void report_load(const char *origin, struct file *file, char *operation)
 {
@@ -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 LIST_HEAD(trusted_verity_root_digests);
+static const char *verity_digests_path;
+#endif
 
 #ifdef CONFIG_SYSCTL
 
@@ -65,6 +71,176 @@ static struct ctl_table loadpin_sysctl_table[] = {
 	{ }
 };
 
+#ifdef CONFIG_SECURITY_LOADPIN_VERITY
+
+static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
+			     bool contents);
+
+static int read_trusted_verity_root_digests(struct file *file)
+{
+	void *data;
+	char *p, *d;
+	int err, rc;
+
+	data = kzalloc(SZ_4K, GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	rc = kernel_read_file(file, 0, &data, SZ_4K - 1, NULL, READING_POLICY);
+	if (rc < 0)
+		return rc;
+
+	((char *)data)[rc] = '\0';
+
+	p = strim(data);
+	while ((d = strsep(&p, ",")) != NULL) {
+		int len = strlen(d);
+		struct trusted_root_digest *trd;
+
+		if (len % 2) {
+			err = -EPROTO;
+			goto free_mem;
+		}
+
+		len /= 2;
+
+		trd = kzalloc(sizeof(*trd), GFP_KERNEL);
+		if (!trd) {
+			err = -ENOMEM;
+			goto free_mem;
+		}
+
+		trd->data = kzalloc(len, GFP_KERNEL);
+		if (!trd->data) {
+			kfree(trd);
+			err = -ENOMEM;
+			goto free_mem;
+		}
+
+		if (hex2bin(trd->data, d, len)) {
+			kfree(trd);
+			err = -EPROTO;
+			goto free_mem;
+		}
+
+		list_add_tail(&trd->node, &trusted_verity_root_digests);
+
+		trd->len = len;
+	}
+
+	kfree(data);
+
+	return 0;
+
+free_mem:
+	kfree(data);
+
+	{
+		struct trusted_root_digest *trd, *tmp;
+
+		list_for_each_entry_safe(trd, tmp, &trusted_verity_root_digests, node) {
+			kfree(trd->data);
+			list_del(&trd->node);
+			kfree(trd);
+		}
+	}
+
+	return err;
+}
+
+static int proc_verity_digests(struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
+{
+	struct ctl_table tbl = *table;
+
+	if (write) {
+		int rc;
+		char *digests_path;
+		struct file *file;
+
+		if (*ppos)
+			return -EINVAL;
+
+		if (verity_digests_path != NULL)
+			return -EPERM;
+
+		digests_path = kzalloc(tbl.maxlen, GFP_KERNEL);
+		if (!digests_path)
+			return -ENOMEM;
+
+		tbl.data = digests_path;
+
+		rc = proc_dostring(&tbl, write, buffer, lenp, ppos);
+		if (rc) {
+			kfree(digests_path);
+			return rc;
+		}
+
+		/* only absolute paths are allowed */
+		if (digests_path[0] != '/') {
+			kfree(digests_path);
+			return -EINVAL;
+		}
+
+		file = filp_open(digests_path, O_RDONLY, 0);
+		if (IS_ERR(file)) {
+			int err = PTR_ERR(file);
+
+			if (err == -ENOENT) {
+				kfree(digests_path);
+				return -EINVAL;
+			}
+
+			return err;
+		}
+
+		/* verify the root digests stem from a trusted file system */
+		if (loadpin_read_file(file, READING_POLICY, true)) {
+			fput(file);
+			kfree(digests_path);
+			return -EPERM;
+		}
+
+		rc = read_trusted_verity_root_digests(file);
+		fput(file);
+		if (rc) {
+			kfree(digests_path);
+			return rc;
+		}
+
+		verity_digests_path = digests_path;
+	} else {
+		if (verity_digests_path) {
+			tbl.data = kzalloc(strlen(verity_digests_path) + 1, GFP_KERNEL);
+			strcpy(tbl.data, verity_digests_path);
+		} else {
+			tbl.data = kzalloc(1, GFP_KERNEL);
+		}
+
+		proc_dostring(&tbl, write, buffer, lenp, ppos);
+		kfree(tbl.data);
+	}
+
+	return 0;
+}
+
+static struct ctl_table loadpin_sysctl_table_verity_digests[] = {
+	{
+		.procname       = "trusted_verity_root_digests_path",
+		.maxlen         = SZ_256,
+		.mode           = 0644,
+		.proc_handler   = proc_verity_digests,
+	},
+
+	{ }
+};
+
+#else
+
+static struct ctl_table loadpin_sysctl_table_verity_digests[] = {};
+
+#endif /* CONFIG_SECURITY_LOADPIN_VERITY */
+
 /*
  * This must be called after early kernel init, since then the rootdev
  * is available.
@@ -118,6 +294,20 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb)
 	}
 }
 
+static bool loadpin_is_fs_trusted(struct super_block *sb)
+{
+	struct mapped_device *md = dm_get_md(sb->s_bdev->bd_dev);
+	bool trusted;
+
+	if (!md)
+		return false;
+
+	trusted = 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 id,
 			     bool contents)
 {
@@ -174,7 +364,8 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
 		spin_unlock(&pinned_root_spinlock);
 	}
 
-	if (IS_ERR_OR_NULL(pinned_root) || load_root != pinned_root) {
+	if (IS_ERR_OR_NULL(pinned_root) ||
+	    ((load_root != pinned_root) && !loadpin_is_fs_trusted(load_root))) {
 		if (unlikely(!enforce)) {
 			report_load(origin, file, "pinning-ignored");
 			return 0;
@@ -240,6 +431,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_digests))
+			pr_notice("sysctl registration failed!\n");
+	}
+
 	return 0;
 }
 
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [dm-devel] [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-04-26 21:31   ` Matthias Kaehlcke
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: dm-devel, linux-kernel, Douglas Anderson, linux-raid, Song Liu,
	linux-security-module, Matthias Kaehlcke

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_path' to provide
LoadPin with the path of a file with a list of root digests
from dm-verity devices that LoadPin should consider as
trusted. This file must be located on the pinned root.

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 path of the file with the trusted root digests can
only be written once, which is typically done at boot time.

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/dlcservice/docs/developer.md

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
I'm still doubting what would be the best way to configure
the list of trusted digests. The approach in v2 of writing
a path through sysctl is flexible, but it also feels a bit
odd. I did some experiments with passing a file descriptor
through sysctl, but it's also odd and has its own issues.
Passing the list through a kernel parameter seems hacky.
A Kconfig string would work, but can be have issues when
the same config is used for different platforms, where
some may have trusted digests and others not.

Changes in v2:
- userspace now passes the path of the file with the verity digests
  via systcl, instead of the digests themselves
- renamed sysctl file to 'trusted_verity_root_digests_path'
- have CONFIG_SECURITY_LOADPIN_VERITY depend on CONFIG_SYSCTL
- updated Kconfig doc
- updated commit message

 security/loadpin/Kconfig   |  16 +++
 security/loadpin/loadpin.c | 200 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 215 insertions(+), 1 deletion(-)

diff --git a/security/loadpin/Kconfig b/security/loadpin/Kconfig
index 91be65dec2ab..20681dc4b8a5 100644
--- a/security/loadpin/Kconfig
+++ b/security/loadpin/Kconfig
@@ -18,3 +18,19 @@ 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=1".
+
+config SECURITY_LOADPIN_VERITY
+	bool "Allow reading files from certain other filesystems that use dm-verity"
+	depends on DM_VERITY=y && SYSCTL
+	help
+	  If selected LoadPin can allow reading files from filesystems
+	  that use dm-verity. LoadPin maintains a list of verity root
+	  digests it considers trusted. A verity backed filesystem is
+	  considered trusted if its root digest is found in the list
+	  of trusted digests.
+
+	  Userspace can populate the list of trusted digests by writing
+	  the path of a file with the digests to the syctl file
+	  'trusted_verity_root_digests_path'. The file must be located
+	  on the pinned root and contain a comma separated list of
+	  digests.
diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
index b12f7d986b1e..db10b7ff6efd 100644
--- a/security/loadpin/loadpin.c
+++ b/security/loadpin/loadpin.c
@@ -18,6 +18,8 @@
 #include <linux/path.h>
 #include <linux/sched.h>	/* current */
 #include <linux/string_helpers.h>
+#include <linux/device-mapper.h>
+#include <linux/dm-verity-loadpin.h>
 
 static void report_load(const char *origin, struct file *file, char *operation)
 {
@@ -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 LIST_HEAD(trusted_verity_root_digests);
+static const char *verity_digests_path;
+#endif
 
 #ifdef CONFIG_SYSCTL
 
@@ -65,6 +71,176 @@ static struct ctl_table loadpin_sysctl_table[] = {
 	{ }
 };
 
+#ifdef CONFIG_SECURITY_LOADPIN_VERITY
+
+static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
+			     bool contents);
+
+static int read_trusted_verity_root_digests(struct file *file)
+{
+	void *data;
+	char *p, *d;
+	int err, rc;
+
+	data = kzalloc(SZ_4K, GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	rc = kernel_read_file(file, 0, &data, SZ_4K - 1, NULL, READING_POLICY);
+	if (rc < 0)
+		return rc;
+
+	((char *)data)[rc] = '\0';
+
+	p = strim(data);
+	while ((d = strsep(&p, ",")) != NULL) {
+		int len = strlen(d);
+		struct trusted_root_digest *trd;
+
+		if (len % 2) {
+			err = -EPROTO;
+			goto free_mem;
+		}
+
+		len /= 2;
+
+		trd = kzalloc(sizeof(*trd), GFP_KERNEL);
+		if (!trd) {
+			err = -ENOMEM;
+			goto free_mem;
+		}
+
+		trd->data = kzalloc(len, GFP_KERNEL);
+		if (!trd->data) {
+			kfree(trd);
+			err = -ENOMEM;
+			goto free_mem;
+		}
+
+		if (hex2bin(trd->data, d, len)) {
+			kfree(trd);
+			err = -EPROTO;
+			goto free_mem;
+		}
+
+		list_add_tail(&trd->node, &trusted_verity_root_digests);
+
+		trd->len = len;
+	}
+
+	kfree(data);
+
+	return 0;
+
+free_mem:
+	kfree(data);
+
+	{
+		struct trusted_root_digest *trd, *tmp;
+
+		list_for_each_entry_safe(trd, tmp, &trusted_verity_root_digests, node) {
+			kfree(trd->data);
+			list_del(&trd->node);
+			kfree(trd);
+		}
+	}
+
+	return err;
+}
+
+static int proc_verity_digests(struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
+{
+	struct ctl_table tbl = *table;
+
+	if (write) {
+		int rc;
+		char *digests_path;
+		struct file *file;
+
+		if (*ppos)
+			return -EINVAL;
+
+		if (verity_digests_path != NULL)
+			return -EPERM;
+
+		digests_path = kzalloc(tbl.maxlen, GFP_KERNEL);
+		if (!digests_path)
+			return -ENOMEM;
+
+		tbl.data = digests_path;
+
+		rc = proc_dostring(&tbl, write, buffer, lenp, ppos);
+		if (rc) {
+			kfree(digests_path);
+			return rc;
+		}
+
+		/* only absolute paths are allowed */
+		if (digests_path[0] != '/') {
+			kfree(digests_path);
+			return -EINVAL;
+		}
+
+		file = filp_open(digests_path, O_RDONLY, 0);
+		if (IS_ERR(file)) {
+			int err = PTR_ERR(file);
+
+			if (err == -ENOENT) {
+				kfree(digests_path);
+				return -EINVAL;
+			}
+
+			return err;
+		}
+
+		/* verify the root digests stem from a trusted file system */
+		if (loadpin_read_file(file, READING_POLICY, true)) {
+			fput(file);
+			kfree(digests_path);
+			return -EPERM;
+		}
+
+		rc = read_trusted_verity_root_digests(file);
+		fput(file);
+		if (rc) {
+			kfree(digests_path);
+			return rc;
+		}
+
+		verity_digests_path = digests_path;
+	} else {
+		if (verity_digests_path) {
+			tbl.data = kzalloc(strlen(verity_digests_path) + 1, GFP_KERNEL);
+			strcpy(tbl.data, verity_digests_path);
+		} else {
+			tbl.data = kzalloc(1, GFP_KERNEL);
+		}
+
+		proc_dostring(&tbl, write, buffer, lenp, ppos);
+		kfree(tbl.data);
+	}
+
+	return 0;
+}
+
+static struct ctl_table loadpin_sysctl_table_verity_digests[] = {
+	{
+		.procname       = "trusted_verity_root_digests_path",
+		.maxlen         = SZ_256,
+		.mode           = 0644,
+		.proc_handler   = proc_verity_digests,
+	},
+
+	{ }
+};
+
+#else
+
+static struct ctl_table loadpin_sysctl_table_verity_digests[] = {};
+
+#endif /* CONFIG_SECURITY_LOADPIN_VERITY */
+
 /*
  * This must be called after early kernel init, since then the rootdev
  * is available.
@@ -118,6 +294,20 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb)
 	}
 }
 
+static bool loadpin_is_fs_trusted(struct super_block *sb)
+{
+	struct mapped_device *md = dm_get_md(sb->s_bdev->bd_dev);
+	bool trusted;
+
+	if (!md)
+		return false;
+
+	trusted = 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 id,
 			     bool contents)
 {
@@ -174,7 +364,8 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
 		spin_unlock(&pinned_root_spinlock);
 	}
 
-	if (IS_ERR_OR_NULL(pinned_root) || load_root != pinned_root) {
+	if (IS_ERR_OR_NULL(pinned_root) ||
+	    ((load_root != pinned_root) && !loadpin_is_fs_trusted(load_root))) {
 		if (unlikely(!enforce)) {
 			report_load(origin, file, "pinning-ignored");
 			return 0;
@@ -240,6 +431,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_digests))
+			pr_notice("sysctl registration failed!\n");
+	}
+
 	return 0;
 }
 
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 3/3] dm: verity-loadpin: Use CONFIG_SECURITY_LOADPIN_VERITY for conditional compilation
  2022-04-26 21:31 ` [dm-devel] " Matthias Kaehlcke
@ 2022-04-26 21:31   ` Matthias Kaehlcke
  -1 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: linux-kernel, linux-security-module, dm-devel, linux-raid,
	Douglas Anderson, Song Liu, Matthias Kaehlcke

The verity glue for LoadPin is only needed when CONFIG_SECURITY_LOADPIN_VERITY
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 <mka@chromium.org>
---

Changes in v2:
- none

 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)	+= dm-log-writes.o
 obj-$(CONFIG_DM_INTEGRITY)	+= dm-integrity.o
 obj-$(CONFIG_DM_ZONED)		+= dm-zoned.o
 obj-$(CONFIG_DM_WRITECACHE)	+= dm-writecache.o
+obj-$(CONFIG_SECURITY_LOADPIN_VERITY)	+= dm-verity-loadpin.o
 
 ifeq ($(CONFIG_DM_INIT),y)
 dm-mod-objs			+= dm-init.o
@@ -100,12 +101,6 @@ ifeq ($(CONFIG_IMA),y)
 dm-mod-objs			+= dm-ima.o
 endif
 
-ifeq ($(CONFIG_DM_VERITY),y)
-ifeq ($(CONFIG_SECURITY_LOADPIN),y)
-dm-mod-objs			+= dm-verity-loadpin.o
-endif
-endif
-
 ifeq ($(CONFIG_DM_VERITY_FEC),y)
 dm-verity-objs			+= dm-verity-fec.o
 endif
diff --git a/include/linux/dm-verity-loadpin.h b/include/linux/dm-verity-loadpin.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;
 };
 
-#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
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [dm-devel] [PATCH v2 3/3] dm: verity-loadpin: Use CONFIG_SECURITY_LOADPIN_VERITY for conditional compilation
@ 2022-04-26 21:31   ` Matthias Kaehlcke
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-04-26 21:31 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris, Serge E . Hallyn
  Cc: dm-devel, linux-kernel, Douglas Anderson, linux-raid, Song Liu,
	linux-security-module, Matthias Kaehlcke

The verity glue for LoadPin is only needed when CONFIG_SECURITY_LOADPIN_VERITY
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 <mka@chromium.org>
---

Changes in v2:
- none

 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)	+= dm-log-writes.o
 obj-$(CONFIG_DM_INTEGRITY)	+= dm-integrity.o
 obj-$(CONFIG_DM_ZONED)		+= dm-zoned.o
 obj-$(CONFIG_DM_WRITECACHE)	+= dm-writecache.o
+obj-$(CONFIG_SECURITY_LOADPIN_VERITY)	+= dm-verity-loadpin.o
 
 ifeq ($(CONFIG_DM_INIT),y)
 dm-mod-objs			+= dm-init.o
@@ -100,12 +101,6 @@ ifeq ($(CONFIG_IMA),y)
 dm-mod-objs			+= dm-ima.o
 endif
 
-ifeq ($(CONFIG_DM_VERITY),y)
-ifeq ($(CONFIG_SECURITY_LOADPIN),y)
-dm-mod-objs			+= dm-verity-loadpin.o
-endif
-endif
-
 ifeq ($(CONFIG_DM_VERITY_FEC),y)
 dm-verity-objs			+= dm-verity-fec.o
 endif
diff --git a/include/linux/dm-verity-loadpin.h b/include/linux/dm-verity-loadpin.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;
 };
 
-#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
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [dm-devel] [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
  2022-04-26 21:31   ` [dm-devel] " Matthias Kaehlcke
@ 2022-04-27 16:06     ` kernel test robot
  -1 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2022-04-27 16:06 UTC (permalink / raw)
  To: Matthias Kaehlcke, Alasdair Kergon, Mike Snitzer, Kees Cook,
	James Morris, Serge E . Hallyn
  Cc: kbuild-all, dm-devel, linux-kernel, Douglas Anderson, linux-raid,
	Song Liu, linux-security-module, Matthias Kaehlcke

Hi Matthias,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on device-mapper-dm/for-next]
[also build test ERROR on song-md/md-next kees/for-next/pstore v5.18-rc4 next-20220427]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
config: sh-buildonly-randconfig-r004-20220427 (https://download.01.org/0day-ci/archive/20220427/202204272332.Ro5WIkwF-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f3a54909bcd78b9f7f006d7e78acd03987031fae
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
        git checkout f3a54909bcd78b9f7f006d7e78acd03987031fae
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   sh4-linux-ld: security/loadpin/loadpin.o: in function `loadpin_read_file':
   loadpin.c:(.text+0x2ac): undefined reference to `dm_get_md'
>> sh4-linux-ld: loadpin.c:(.text+0x2b0): undefined reference to `dm_put'

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-04-27 16:06     ` kernel test robot
  0 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2022-04-27 16:06 UTC (permalink / raw)
  To: Matthias Kaehlcke, Alasdair Kergon, Mike Snitzer, Kees Cook,
	James Morris, Serge E . Hallyn
  Cc: kbuild-all, linux-kernel, linux-security-module, dm-devel,
	linux-raid, Douglas Anderson, Song Liu, Matthias Kaehlcke

Hi Matthias,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on device-mapper-dm/for-next]
[also build test ERROR on song-md/md-next kees/for-next/pstore v5.18-rc4 next-20220427]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
config: sh-buildonly-randconfig-r004-20220427 (https://download.01.org/0day-ci/archive/20220427/202204272332.Ro5WIkwF-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f3a54909bcd78b9f7f006d7e78acd03987031fae
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
        git checkout f3a54909bcd78b9f7f006d7e78acd03987031fae
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   sh4-linux-ld: security/loadpin/loadpin.o: in function `loadpin_read_file':
   loadpin.c:(.text+0x2ac): undefined reference to `dm_get_md'
>> sh4-linux-ld: loadpin.c:(.text+0x2b0): undefined reference to `dm_put'

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
  2022-04-26 21:31   ` [dm-devel] " Matthias Kaehlcke
@ 2022-04-28  1:59     ` kernel test robot
  -1 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2022-04-28  1:59 UTC (permalink / raw)
  To: Matthias Kaehlcke, Alasdair Kergon, Mike Snitzer, Kees Cook,
	James Morris, Serge E . Hallyn
  Cc: kbuild-all, linux-kernel, linux-security-module, dm-devel,
	linux-raid, Douglas Anderson, Song Liu, Matthias Kaehlcke

Hi Matthias,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on device-mapper-dm/for-next]
[also build test ERROR on song-md/md-next kees/for-next/pstore v5.18-rc4 next-20220427]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
config: alpha-randconfig-r024-20220425 (https://download.01.org/0day-ci/archive/20220428/202204280323.OzDYYX55-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f3a54909bcd78b9f7f006d7e78acd03987031fae
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
        git checkout f3a54909bcd78b9f7f006d7e78acd03987031fae
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   security/loadpin/loadpin.c: In function 'loadpin_init':
   security/loadpin/loadpin.c:436:44: error: 'loadpin_sysctl_path' undeclared (first use in this function)
     436 |                 if (!register_sysctl_paths(loadpin_sysctl_path,
         |                                            ^~~~~~~~~~~~~~~~~~~
   security/loadpin/loadpin.c:436:44: note: each undeclared identifier is reported only once for each function it appears in
>> security/loadpin/loadpin.c:437:44: error: 'loadpin_sysctl_table_verity_digests' undeclared (first use in this function)
     437 |                                            loadpin_sysctl_table_verity_digests))
         |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/loadpin_sysctl_table_verity_digests +437 security/loadpin/loadpin.c

   427	
   428	static int __init loadpin_init(void)
   429	{
   430		pr_info("ready to pin (currently %senforcing)\n",
   431			enforce ? "" : "not ");
   432		parse_exclude();
   433		security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin");
   434	
   435		if (IS_ENABLED(CONFIG_SECURITY_LOADPIN_VERITY)) {
   436			if (!register_sysctl_paths(loadpin_sysctl_path,
 > 437						   loadpin_sysctl_table_verity_digests))
   438				pr_notice("sysctl registration failed!\n");
   439		}
   440	
   441		return 0;
   442	}
   443	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dm-devel] [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-04-28  1:59     ` kernel test robot
  0 siblings, 0 replies; 18+ messages in thread
From: kernel test robot @ 2022-04-28  1:59 UTC (permalink / raw)
  To: Matthias Kaehlcke, Alasdair Kergon, Mike Snitzer, Kees Cook,
	James Morris, Serge E . Hallyn
  Cc: kbuild-all, dm-devel, linux-kernel, Douglas Anderson, linux-raid,
	Song Liu, linux-security-module, Matthias Kaehlcke

Hi Matthias,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on device-mapper-dm/for-next]
[also build test ERROR on song-md/md-next kees/for-next/pstore v5.18-rc4 next-20220427]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
base:   https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git for-next
config: alpha-randconfig-r024-20220425 (https://download.01.org/0day-ci/archive/20220428/202204280323.OzDYYX55-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f3a54909bcd78b9f7f006d7e78acd03987031fae
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthias-Kaehlcke/LoadPin-Enable-loading-from-trusted-dm-verity-devices/20220427-053314
        git checkout f3a54909bcd78b9f7f006d7e78acd03987031fae
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   security/loadpin/loadpin.c: In function 'loadpin_init':
   security/loadpin/loadpin.c:436:44: error: 'loadpin_sysctl_path' undeclared (first use in this function)
     436 |                 if (!register_sysctl_paths(loadpin_sysctl_path,
         |                                            ^~~~~~~~~~~~~~~~~~~
   security/loadpin/loadpin.c:436:44: note: each undeclared identifier is reported only once for each function it appears in
>> security/loadpin/loadpin.c:437:44: error: 'loadpin_sysctl_table_verity_digests' undeclared (first use in this function)
     437 |                                            loadpin_sysctl_table_verity_digests))
         |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/loadpin_sysctl_table_verity_digests +437 security/loadpin/loadpin.c

   427	
   428	static int __init loadpin_init(void)
   429	{
   430		pr_info("ready to pin (currently %senforcing)\n",
   431			enforce ? "" : "not ");
   432		parse_exclude();
   433		security_add_hooks(loadpin_hooks, ARRAY_SIZE(loadpin_hooks), "loadpin");
   434	
   435		if (IS_ENABLED(CONFIG_SECURITY_LOADPIN_VERITY)) {
   436			if (!register_sysctl_paths(loadpin_sysctl_path,
 > 437						   loadpin_sysctl_table_verity_digests))
   438				pr_notice("sysctl registration failed!\n");
   439		}
   440	
   441		return 0;
   442	}
   443	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 0/3] LoadPin: Enable loading from trusted dm-verity devices
  2022-04-26 21:31 ` [dm-devel] " Matthias Kaehlcke
@ 2022-04-28  5:32   ` Paul Menzel
  -1 siblings, 0 replies; 18+ messages in thread
From: Paul Menzel @ 2022-04-28  5:32 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Alasdair Kergon, Mike Snitzer, Kees Cook, James Morris,
	Serge E . Hallyn, linux-kernel, linux-security-module, dm-devel,
	linux-raid, Douglas Anderson, Song Liu

Dear Matthias,


Thank you for your patches.

Am 26.04.22 um 23:31 schrieb Matthias Kaehlcke:
> As of now LoadPin restricts loading of kernel files to a single
> pinned filesystem, typically the rootfs. This works for many

[…]

A small nit, if you should reroll the patches, please use 75 characters 
per line in commit messages. (`scripts/checkpatch.pl` uses that number.)


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dm-devel] [PATCH v2 0/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-04-28  5:32   ` Paul Menzel
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Menzel @ 2022-04-28  5:32 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Douglas Anderson, Kees Cook, dm-devel, Mike Snitzer,
	linux-kernel, James Morris, linux-raid, Song Liu,
	linux-security-module, Alasdair Kergon, Serge E . Hallyn

Dear Matthias,


Thank you for your patches.

Am 26.04.22 um 23:31 schrieb Matthias Kaehlcke:
> As of now LoadPin restricts loading of kernel files to a single
> pinned filesystem, typically the rootfs. This works for many

[…]

A small nit, if you should reroll the patches, please use 75 characters 
per line in commit messages. (`scripts/checkpatch.pl` uses that number.)


Kind regards,

Paul

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
  2022-04-26 21:31   ` [dm-devel] " Matthias Kaehlcke
@ 2022-05-01  6:21     ` Kees Cook
  -1 siblings, 0 replies; 18+ messages in thread
From: Kees Cook @ 2022-05-01  6:21 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Alasdair Kergon, Mike Snitzer, James Morris, Serge E . Hallyn,
	linux-kernel, linux-security-module, dm-devel, linux-raid,
	Douglas Anderson, Song Liu

On Tue, Apr 26, 2022 at 02:31:09PM -0700, Matthias Kaehlcke wrote:
> I'm still doubting what would be the best way to configure
> the list of trusted digests. The approach in v2 of writing
> a path through sysctl is flexible, but it also feels a bit
> odd. I did some experiments with passing a file descriptor
> through sysctl, but it's also odd and has its own issues.
> Passing the list through a kernel parameter seems hacky.
> A Kconfig string would work, but can be have issues when
> the same config is used for different platforms, where
> some may have trusted digests and others not.

I prefer the idea of passing an fd, since that can just use LoadPin
itself to verify the origin of the fd.

I also agree, though, that it's weird as a sysctl. Possible thoughts:

- make it a new ioctl on /dev/mapper/control (seems reasonable given
  that it's specifically about dm devices).
- have LoadPin grow a securityfs node, maybe something like
  /sys/kernel/security/loadpin/dm-verify and do the ioctl there (seems
  reasonable given that it's specifically about LoadPin, but is perhaps
  more overhead to built the securityfs).

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dm-devel] [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-05-01  6:21     ` Kees Cook
  0 siblings, 0 replies; 18+ messages in thread
From: Kees Cook @ 2022-05-01  6:21 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Douglas Anderson, dm-devel, Mike Snitzer, linux-kernel,
	James Morris, linux-raid, Song Liu, linux-security-module,
	Alasdair Kergon, Serge E . Hallyn

On Tue, Apr 26, 2022 at 02:31:09PM -0700, Matthias Kaehlcke wrote:
> I'm still doubting what would be the best way to configure
> the list of trusted digests. The approach in v2 of writing
> a path through sysctl is flexible, but it also feels a bit
> odd. I did some experiments with passing a file descriptor
> through sysctl, but it's also odd and has its own issues.
> Passing the list through a kernel parameter seems hacky.
> A Kconfig string would work, but can be have issues when
> the same config is used for different platforms, where
> some may have trusted digests and others not.

I prefer the idea of passing an fd, since that can just use LoadPin
itself to verify the origin of the fd.

I also agree, though, that it's weird as a sysctl. Possible thoughts:

- make it a new ioctl on /dev/mapper/control (seems reasonable given
  that it's specifically about dm devices).
- have LoadPin grow a securityfs node, maybe something like
  /sys/kernel/security/loadpin/dm-verify and do the ioctl there (seems
  reasonable given that it's specifically about LoadPin, but is perhaps
  more overhead to built the securityfs).

-- 
Kees Cook

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
  2022-05-01  6:21     ` [dm-devel] " Kees Cook
@ 2022-05-02 22:44       ` Matthias Kaehlcke
  -1 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-05-02 22:44 UTC (permalink / raw)
  To: Kees Cook
  Cc: Alasdair Kergon, Mike Snitzer, James Morris, Serge E . Hallyn,
	linux-kernel, linux-security-module, dm-devel, linux-raid,
	Douglas Anderson, Song Liu

On Sat, Apr 30, 2022 at 11:21:54PM -0700, Kees Cook wrote:
> On Tue, Apr 26, 2022 at 02:31:09PM -0700, Matthias Kaehlcke wrote:
> > I'm still doubting what would be the best way to configure
> > the list of trusted digests. The approach in v2 of writing
> > a path through sysctl is flexible, but it also feels a bit
> > odd. I did some experiments with passing a file descriptor
> > through sysctl, but it's also odd and has its own issues.
> > Passing the list through a kernel parameter seems hacky.
> > A Kconfig string would work, but can be have issues when
> > the same config is used for different platforms, where
> > some may have trusted digests and others not.
> 
> I prefer the idea of passing an fd, since that can just use LoadPin
> itself to verify the origin of the fd.
> 
> I also agree, though, that it's weird as a sysctl. Possible thoughts:
> 
> - make it a new ioctl on /dev/mapper/control (seems reasonable given
>   that it's specifically about dm devices).
> - have LoadPin grow a securityfs node, maybe something like
>   /sys/kernel/security/loadpin/dm-verify and do the ioctl there (seems
>   reasonable given that it's specifically about LoadPin, but is perhaps
>   more overhead to built the securityfs).

Thanks for your feedback!

Agreed that an ioctl is preferable over a sysctl interface. I wasn't aware
of securityfs and prefer it over a /dev/mapper/control ioctl. Ultimately
the list of digests is meaningful to LoadPin, not (directly) to the device
mapper / verity. I'm not sure how well this feature of integrating LoadPin
with verity will be by the verity maintainers in the first place, it's
probably best to limit the LoadPin specific stuff in verity to a minimum.
I experimented a bit with the securityfs option, building it doesn't seem
too much of an overhead. If loadpin.c ends up too cluttered with the
verity and securityfs stuff I could try to outsource some of it to (a)
dedicated file(s).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dm-devel] [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices
@ 2022-05-02 22:44       ` Matthias Kaehlcke
  0 siblings, 0 replies; 18+ messages in thread
From: Matthias Kaehlcke @ 2022-05-02 22:44 UTC (permalink / raw)
  To: Kees Cook
  Cc: Douglas Anderson, dm-devel, Mike Snitzer, linux-kernel,
	James Morris, linux-raid, Song Liu, linux-security-module,
	Alasdair Kergon, Serge E . Hallyn

On Sat, Apr 30, 2022 at 11:21:54PM -0700, Kees Cook wrote:
> On Tue, Apr 26, 2022 at 02:31:09PM -0700, Matthias Kaehlcke wrote:
> > I'm still doubting what would be the best way to configure
> > the list of trusted digests. The approach in v2 of writing
> > a path through sysctl is flexible, but it also feels a bit
> > odd. I did some experiments with passing a file descriptor
> > through sysctl, but it's also odd and has its own issues.
> > Passing the list through a kernel parameter seems hacky.
> > A Kconfig string would work, but can be have issues when
> > the same config is used for different platforms, where
> > some may have trusted digests and others not.
> 
> I prefer the idea of passing an fd, since that can just use LoadPin
> itself to verify the origin of the fd.
> 
> I also agree, though, that it's weird as a sysctl. Possible thoughts:
> 
> - make it a new ioctl on /dev/mapper/control (seems reasonable given
>   that it's specifically about dm devices).
> - have LoadPin grow a securityfs node, maybe something like
>   /sys/kernel/security/loadpin/dm-verify and do the ioctl there (seems
>   reasonable given that it's specifically about LoadPin, but is perhaps
>   more overhead to built the securityfs).

Thanks for your feedback!

Agreed that an ioctl is preferable over a sysctl interface. I wasn't aware
of securityfs and prefer it over a /dev/mapper/control ioctl. Ultimately
the list of digests is meaningful to LoadPin, not (directly) to the device
mapper / verity. I'm not sure how well this feature of integrating LoadPin
with verity will be by the verity maintainers in the first place, it's
probably best to limit the LoadPin specific stuff in verity to a minimum.
I experimented a bit with the securityfs option, building it doesn't seem
too much of an overhead. If loadpin.c ends up too cluttered with the
verity and securityfs stuff I could try to outsource some of it to (a)
dedicated file(s).

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-05-03  7:12 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 21:31 [PATCH v2 0/3] LoadPin: Enable loading from trusted dm-verity devices Matthias Kaehlcke
2022-04-26 21:31 ` [dm-devel] " Matthias Kaehlcke
2022-04-26 21:31 ` [PATCH v2 1/3] dm: Add verity helpers for LoadPin Matthias Kaehlcke
2022-04-26 21:31   ` [dm-devel] " Matthias Kaehlcke
2022-04-26 21:31 ` [PATCH v2 2/3] LoadPin: Enable loading from trusted dm-verity devices Matthias Kaehlcke
2022-04-26 21:31   ` [dm-devel] " Matthias Kaehlcke
2022-04-27 16:06   ` kernel test robot
2022-04-27 16:06     ` kernel test robot
2022-04-28  1:59   ` kernel test robot
2022-04-28  1:59     ` [dm-devel] " kernel test robot
2022-05-01  6:21   ` Kees Cook
2022-05-01  6:21     ` [dm-devel] " Kees Cook
2022-05-02 22:44     ` Matthias Kaehlcke
2022-05-02 22:44       ` [dm-devel] " Matthias Kaehlcke
2022-04-26 21:31 ` [PATCH v2 3/3] dm: verity-loadpin: Use CONFIG_SECURITY_LOADPIN_VERITY for conditional compilation Matthias Kaehlcke
2022-04-26 21:31   ` [dm-devel] " Matthias Kaehlcke
2022-04-28  5:32 ` [PATCH v2 0/3] LoadPin: Enable loading from trusted dm-verity devices Paul Menzel
2022-04-28  5:32   ` [dm-devel] " Paul Menzel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.