Skip to contentSkip to conversation

init: boot image-based systems without an initramfs (rootimage=)

RFC PATCH Superseded Eric Curtin 3 participants 13 messages Jul 18 – Jul 30

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover init: boot image-based systems without an initramfs (rootimage=)

Image-based Linux systems (bootc-style OS updaters, ChromeOS/Android-like A/B schemes, embedded appliances) keep one or more immutable root filesystem images as sealed files on a writable filesystem and pick one at boot. Booting such a system today always requires an initramfs, even when that initramfs has nothing else to do; its only jobs are to parse the kernel command line, mount the state filesystem, verify the image, loop-mount it and switch_root into it.

This series teaches the kernel to do all of that directly:

  root=PARTUUID=... rootimage=/deploy/a/root.erofs rootimagefstype=erofs \
      rootimageverity=sha256:a9548f4c... rootimagesrcdir=/var/state

Patch 1 adds rootimage= (plus rootimagefstype=/rootimageflags=/ rootimagesrcdir=): root= then merely names the "carrier" filesystem. The image file on it is mounted read-only through the filesystem's file-backed mount support (available in erofs since v6.12), so no loop device is involved, and it becomes the root that prepare_namespace() pivots into. The carrier mount is detached by default, or moved to rootimagesrcdir= inside the new root, which image-based systems practically always want since the carrier holds their writable state.

Patch 2 adds rootimageverity=, which requires the image to carry a specific fsverity file digest, reusing the fsverity_get_digest() interface that IMA and overlayfs already use for digest pinning. With a signed or measured command line (e.g. a unified kernel image), the chain of trust extends to every byte of the root filesystem with no userspace boot stage: the pinned digest authenticates the image's Merkle tree root, and fsverity keeps verifying reads against it at runtime, so later tampering with the carrier is caught as well.

This is the file-backed analogue of dm-mod.create= (CONFIG_DM_INIT), which moved the equivalent block-device setup out of the initramfs for verity-partition layouts back in v5.1. For file-based deployment layouts nothing similar exists, so distributions ship a dracut stack whose only purpose is the five steps above, and which remains the largest and most failure-prone moving part of an otherwise fully image-defined boot.

Tested on arm64 (qemu -M virt with KVM), with no initrd= at any point:

- control: plain ext4 root boots as before
- rootimage=: an erofs image file on ext4 is mounted as /, the carrier ends up on /var/state, PID 1 runs from the image ~0.18s after kernel entry
- rootimageverity= with the correct digest: boots, digest logged
- rootimageverity= with a wrong digest: panics with expected-vs-got
- build: defconfig and allnoconfig (!CONFIG_FS_VERITY, !CONFIG_BLOCK), both with W=1, no warnings

Open questions for review:

- Should the carrier always be detached, dropping rootimagesrcdir=? The image mount pins the carrier superblock either way, so userspace can re-mount it, but a conflicting ro/rw state then needs a remount dance.
- Should this be behind a Kconfig option like CONFIG_DM_INIT is? All added code is __init and freed after boot.
- Naming: rootimage= vs. extending root= syntax (e.g. root=image:...).

This series was developed with AI assistance (see the Assisted-by tags and Documentation/process/coding-assistants.rst).

Eric Curtin (2):
init: support mounting the root filesystem from an image file
init: support pinning the root image's fsverity digest

 .../admin-guide/kernel-parameters.txt         |  42 ++++
 init/do_mounts.c                              | 221 ++++++++++++++++--
 2 files changed, 250 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/2 init: support mounting the root filesystem from an image file

Image-based Linux systems (bootc-style OS updaters, ChromeOS/Android-like A/B schemes, embedded appliances) commonly keep one or more immutable root filesystem images as plain files on a writable "carrier" filesystem and pick one at boot. Today that always requires an initramfs, even when the initramfs has nothing else to do: the kernel can only mount a block device (or NFS/CIFS/ubi/mtd) as root, so userspace must mount the carrier, loop-mount the image and switch_root into it.

Add a rootimage= parameter naming an image file on the filesystem specified by root=. When set, root= only designates the carrier: after mounting it as usual, mount the image file read-only on /image and make that the root that prepare_namespace() pivots into. The image is mounted through the filesystem's file-backed mount support (available in erofs since v6.12), so no loop device is involved. rootimagefstype= and rootimageflags= mirror rootfstype=/rootflags= for the image mount, while "ro"/"rw"/rootflags= keep applying to the carrier.

The carrier mount is detached again by default; the image mount keeps its superblock pinned, so userspace can still mount it later. Since systems following this model virtually always need the carrier mounted (it holds their writable state), rootimagesrcdir= optionally names a directory inside the image where the carrier mount is moved instead.

This is the file-backed analogue of what dm-mod.create= (CONFIG_DM_INIT) already does for device-mapper targets: moving a fixed, declarative bit of early-boot setup from initramfs userspace into the kernel so that small and verified systems can boot with no initramfs at all.

Assisted-by opencode:claude-fable-5
---
 .../admin-guide/kernel-parameters.txt         |  29 ++++
 init/do_mounts.c                              | 158 ++++++++++++++++--
 2 files changed, 174 insertions(+), 13 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +29 -0
index b5493a7f8..5dbd56098 100644
@@ -6699,6 +6699,35 @@ Kernel parameters
 
 	rootfstype=	[KNL] Set root filesystem type
 
+	rootimage=	[KNL] Mount the actual root filesystem from this
+			filesystem image file (absolute path) located on the
+			filesystem specified by root=, instead of using that
+			filesystem as the root directly.  This allows
+			image-based systems that keep their (typically
+			read-only, e.g. erofs) root filesystem images as
+			plain files on a carrier filesystem to boot without
+			an initramfs.  The image is mounted read-only via
+			the filesystem's file-backed mount support (no loop
+			device is set up); "ro", "rw" and rootflags= keep
+			applying to the carrier filesystem.  Once the image
+			is mounted, the carrier mount is detached (but kept
+			busy by the image mount itself) unless
+			rootimagesrcdir= is also given.
+
+	rootimageflags=	[KNL] Set root image filesystem mount option string,
+			used together with rootimage=.
+
+	rootimagefstype= [KNL] Set root image filesystem type, used together
+			with rootimage=.  Default is to try all filesystems
+			known to the kernel that can mount a block device or
+			an image file.
+
+	rootimagesrcdir= [KNL] Directory (absolute path) inside the root
+			image where the mount of the carrier filesystem
+			holding the image (i.e. the filesystem specified by
+			root=) is moved to, instead of detaching it.  Used
+			together with rootimage=.
+
 	rootwait	[KNL] Wait (indefinitely) for root device to show up.
 			Useful for devices that are detected asynchronously
 			(e.g. USB and MMC devices).
init/do_mounts.c +145 -13

232 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH 2/2 init: support pinning the root image's fsverity digest

In reply to Eric Curtin

When the root filesystem is mounted from an image file with rootimage=, the carrier filesystem holding the image is typically writable and therefore untrusted. Systems that seal their root images with fsverity currently need an initramfs for the sole purpose of checking that the image carries the expected fsverity digest before mounting it.

Add rootimageverity=<hash algorithm>:<hex digest>, which requires the rootimage= file to have fsverity enabled with exactly this file digest and fails the boot otherwise, using the same fsverity_get_digest() interface that IMA and overlayfs already use for digest pinning.

Combined with a trusted kernel command line (e.g. a signed unified kernel image, or a TPM-measured bootloader configuration), this extends the chain of trust to every byte of the root filesystem without any userspace boot stage: the digest pins the image's Merkle tree, and fsverity keeps verifying all data read from the image against it at runtime, so post-boot tampering with the carrier filesystem is detected as well. It is the file-backed counterpart of setting up a dm-verity target for a partition-backed root via dm-mod.create=.

Verification is done on the file the kernel is about to mount: it is opened before mounting (which also loads the fsverity information) and kept open across the mount, and no userspace exists yet that could race a replacement in between.

Assisted-by opencode:claude-fable-5
---
 .../admin-guide/kernel-parameters.txt         | 13 ++++
 init/do_mounts.c                              | 63 +++++++++++++++++++
 2 files changed, 76 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +13 -0
index 5dbd56098..105ebb171 100644
@@ -6728,6 +6728,19 @@ Kernel parameters
 			root=) is moved to, instead of detaching it.  Used
 			together with rootimage=.
 
+	rootimageverity= [KNL] Require the root image specified by
+			rootimage= to have fsverity enabled with this file
+			digest, given as <hash algorithm>:<hex digest>,
+			e.g. sha256:dd1b3fa9...  The boot is aborted if the
+			image carries no or a different fsverity digest.
+			Because fsverity keeps verifying data read from the
+			image against its Merkle tree at runtime, a trusted
+			(e.g. signed or TPM-measured) kernel command line
+			extends the chain of trust to the complete root
+			filesystem contents without an initramfs.  Requires
+			CONFIG_FS_VERITY and a carrier filesystem with
+			fsverity support.
+
 	rootwait	[KNL] Wait (indefinitely) for root device to show up.
 			Useful for devices that are detected asynchronously
 			(e.g. USB and MMC devices).
init/do_mounts.c +63 -0

91 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw
In reply to Eric Curtin
Quoted 31 lines · Eric Curtin

Image-based Linux systems (bootc-style OS updaters, ChromeOS/Android-like A/B schemes, embedded appliances) keep one or more immutable root filesystem images as sealed files on a writable filesystem and pick one at boot. Booting such a system today always requires an initramfs, even when that initramfs has nothing else to do; its only jobs are to parse the kernel command line, mount the state filesystem, verify the image, loop-mount it and switch_root into it.

This series teaches the kernel to do all of that directly:

  root=PARTUUID=... rootimage=/deploy/a/root.erofs rootimagefstype=erofs \
      rootimageverity=sha256:a9548f4c... rootimagesrcdir=/var/state

Patch 1 adds rootimage= (plus rootimagefstype=/rootimageflags=/ rootimagesrcdir=): root= then merely names the "carrier" filesystem. The image file on it is mounted read-only through the filesystem's file-backed mount support (available in erofs since v6.12), so no loop device is involved, and it becomes the root that prepare_namespace() pivots into. The carrier mount is detached by default, or moved to rootimagesrcdir= inside the new root, which image-based systems practically always want since the carrier holds their writable state.

Patch 2 adds rootimageverity=, which requires the image to carry a specific fsverity file digest, reusing the fsverity_get_digest() interface that IMA and overlayfs already use for digest pinning. With a signed or measured command line (e.g. a unified kernel image), the chain of trust extends to every byte of the root filesystem with no userspace boot stage: the pinned digest authenticates the image's Merkle tree root, and fsverity keeps verifying reads against it at runtime, so later tampering with the carrier is caught as well.

Quoted 7 lines

This is the file-backed analogue of dm-mod.create= (CONFIG_DM_INIT), which moved the equivalent block-device setup out of the initramfs for verity-partition layouts back in v5.1. For file-based deployment layouts nothing similar exists, so distributions ship a dracut stack whose only purpose is the five steps above, and which remains the largest and most failure-prone moving part of an otherwise fully image-defined boot.

So I have several structual and design issues with this.

In the first pach the filp_open() and subsequent fput() are unused. And that claim "the image cannot change between this open and the mount below" is resting on very weak assumptions.

The second patch then checks the digest on the struct file from its own filp_open(). But the mount goes through init_mount() with the path... so erofs does a third lookup via filp_open(fc->source)...

Nothing guarantees that there's a relationship between the verified inode and the path the superblock is created from. The only guarantee is that no userspace yet exists but which can't really be enforced.

To support this properly we need new infrastructure such that you can actually hand an already opened file as the source. I know that erofs is intended to merge support for this at least but this should be generic infra available to any fs.

Note also that the default detach mode creates a zombie superblock and the image superblocks source string (/root/deploy/...) dangles after the pivot. /proc/self/mounts names a path that doesn't exist in the final namespace. And unlike loop there's no /sys/block/loopX/loop/backing_file to recover which file backs the root.

The other claim is that the digest sufficiently guarantees the integrity of the root filesystem. That's not correct per se...

An erofs multi-device filesystem blows this apart and rootimageflags=device= would also add more. So that digest only cover the primary image.

The bigger flaw is that the untrusted "carrier" (LLMs do pick the worst terms for things...) is fully parsed before anything is verified.

In other words, mounting the carrier means running the ext4 (or whatever) parsers and infra over attacker-writable data, and the fsverity descriptor are themselves read from that untrusted fs. So basically you're hosed before you ever got to the fsverity part.

This is also now the third fsverity-digest-pinning mechanism (IMA appraisal, the IPE LSM and now rootimageverity=). With the least expressive policy language of the three. No signature or keyring option either and so the boot entry must be regenerated per image update.

You're embedding a whole deployment topology into the core code here as well... There are _five_ interacting __setup parameters. Every real deployment immediately wants a sixth knob: A/B fallback inside the mechanism. Because in your current model every failure is a panic().

But that also means image selection must live in the bootloader anyway:
composefs/overlay stacking, LUKS-encrypted state partitions as command lines can't do crypto secrets, fsck of the carrier, directory-based deployments yadayadayada.

This is just turning do_mounts.c into policy it shouldn't be involved in. We just refused pushing the bootloader spec into the initramfs for the same reasons - and that one I'm much more sympathetic to since I was involved in creating it. I'd love to see parts of that in the kernel but I refuse it because I believe fundamentally the kernel is in the business of keeping complexity in userspace not the other way around.

Also the users the cover letter touches on such as distro kernels ship erofs and its decompressors, the block drivers, and the fs stack as modules. Afaict, rootimage= needs all of it builtin:

- bootc/ostree: composefs — multi-mount + overlay + external objects. inexpressible here and partially unverifiable
- ChromeOS/Android-style A/B: dm-verity partitions already served by dm-mod.create= and a fallback story.
- embedded squashfs appliances: no file-backed mount support in squashfs

What remains are single-erofs-filesystems with fully-builtin kernels. That's kinda what CONFIG_INITRAMFS_SOURCE embeds a five-line static /init into the same signed/measured kernel image with identical trust properties and full policy freedom.

UKI users likewise already sign and measure their initrd as part of the PE. The series only really makes sense if you get rid of that.

#4 lore raw
Quoted 1 line · Christian Brauner

So I have several structual and design issues with this.

[...]

Quoted 5 lines

You're embedding a whole deployment topology into the core code here as well... There are _five_ interacting __setup parameters. Every real deployment immediately wants a sixth knob: A/B fallback inside the mechanism. Because in your current model every failure is a panic().

Quoted 7 lines

But that also means image selection must live in the bootloader anyway:
composefs/overlay stacking, LUKS-encrypted state partitions as command lines can't do crypto secrets, fsck of the carrier, directory-based deployments yadayadayada.

This is just turning do_mounts.c into policy it shouldn't be involved in.

Thanks for the detailed review. Let me state the goal plainly, since I think it explains the choices even though several of your specific findings below are real bugs I should just fix rather than defend.

The goal is A/B image updates from a *single* partition, without paying for a second userspace spin-up at boot.

Today there are basically two ways to do A/B on Linux:

1. N partitions/dm-verity volumes, each a full root image, selected by the bootloader (dm-mod.create= + a GPT attribute flip). This is the ChromeOS/Android model. It costs Nx the storage/partition budget up front and the slot count is fixed at provisioning time.

2. A single filesystem holding N image files (what bootc/ostree/ composefs already do), where something picks which file becomes root. Far more space- and slot-count-flexible, but "pick a file and expose it as root" is currently dracut/initramfs's job, so you pay for a whole extra userspace stage whose only work is the five steps in the cover letter.

rootimage= targets (2): keep single-partition flexibility, drop the "spin up a second userspace just to switch_root" cost. On fast-boot targets that first userspace (loading dracut/busybox, forking, possibly loading modules) isn't free and is pure overhead for five mechanical steps.

To be clear, I'm not trying to relitigate "no bootloader spec in the kernel" - I agree with that call, and A/B slot selection/fallback bookkeeping is meant to stay in the bootloader, exactly as it does with dm-mod.create= today. rootimage= is only meant to do the same mechanical "resolve the one path the bootloader already chose, verify it, make it root" step dm-mod.create() does for partitions - just for the file-backed case, where there's no dm table to describe it. So the "sixth knob" is intentionally out of scope; where you're right is that I haven't specified what happens when this step fails (currently panic()), and that needs a real answer, not "bootloader's problem".

On the rest, these read like real bugs, not disagreements, and I'd rather fix them than defend the current code:

- filp_open()/fput() unused, and no guaranteed relationship between the fsverity-checked file and the path/inode init_mount() and erofs's own filp_open(fc->source) resolve independently - agreed, this needs a real "mount from an already-open fd" path.
- multi-device erofs / rootimageflags=device= meaning the digest only covers the primary image - agreed, real gap.
- the carrier fs being fully parsed, including reading the fsverity descriptor itself, before anything is verified - agreed, that ordering defeats the point.
- zombie superblock / dangling source path / no loop-style backing-file equivalent after detach - agreed, needs fixing.

I'll rework this into a v2 that only tries to solve the "take an already-resolved, already-open file and make it root, verified" problem, drop the multi-knob framing, and either fix the fd-vs-path lookup properly or wait for the generic "mount from fd" infra you mentioned.

Thanks for going through this in such detail.

Eric

#5 lore raw
Quoted 13 lines · Eric Curtin
Quoted 1 line · Christian Brauner

So I have several structual and design issues with this.

[...]

Quoted 10 lines

You're embedding a whole deployment topology into the core code here as well... There are _five_ interacting __setup parameters. Every real deployment immediately wants a sixth knob: A/B fallback inside the mechanism. Because in your current model every failure is a panic().

But that also means image selection must live in the bootloader anyway:
composefs/overlay stacking, LUKS-encrypted state partitions as command lines can't do crypto secrets, fsck of the carrier, directory-based deployments yadayadayada.

Quoted 4 lines
Quoted 2 lines

This is just turning do_mounts.c into policy it shouldn't be involved in.

Thanks for the detailed review. Let me state the goal plainly, since I

This kinda reads like a complete 1:1 dump of an LLM session...

Quoted 48 lines

think it explains the choices even though several of your specific findings below are real bugs I should just fix rather than defend.

The goal is A/B image updates from a *single* partition, without paying for a second userspace spin-up at boot.

Today there are basically two ways to do A/B on Linux:

1. N partitions/dm-verity volumes, each a full root image, selected by the bootloader (dm-mod.create= + a GPT attribute flip). This is the ChromeOS/Android model. It costs Nx the storage/partition budget up front and the slot count is fixed at provisioning time.

2. A single filesystem holding N image files (what bootc/ostree/ composefs already do), where something picks which file becomes root. Far more space- and slot-count-flexible, but "pick a file and expose it as root" is currently dracut/initramfs's job, so you pay for a whole extra userspace stage whose only work is the five steps in the cover letter.

rootimage= targets (2): keep single-partition flexibility, drop the "spin up a second userspace just to switch_root" cost. On fast-boot targets that first userspace (loading dracut/busybox, forking, possibly loading modules) isn't free and is pure overhead for five mechanical steps.

To be clear, I'm not trying to relitigate "no bootloader spec in the kernel" - I agree with that call, and A/B slot selection/fallback bookkeeping is meant to stay in the bootloader, exactly as it does with dm-mod.create= today. rootimage= is only meant to do the same mechanical "resolve the one path the bootloader already chose, verify it, make it root" step dm-mod.create() does for partitions - just for the file-backed case, where there's no dm table to describe it. So the "sixth knob" is intentionally out of scope; where you're right is that I haven't specified what happens when this step fails (currently panic()), and that needs a real answer, not "bootloader's problem".

On the rest, these read like real bugs, not disagreements, and I'd rather fix them than defend the current code:

- filp_open()/fput() unused, and no guaranteed relationship between the fsverity-checked file and the path/inode init_mount() and erofs's own filp_open(fc->source) resolve independently - agreed, this needs a real "mount from an already-open fd" path.
- multi-device erofs / rootimageflags=device= meaning the digest only covers the primary image - agreed, real gap.

Quoted 3 lines

- the carrier fs being fully parsed, including reading the fsverity descriptor itself, before anything is verified - agreed, that ordering defeats the point.

Yeah, and it's unaddressed as are all the other structurual issues.

Quoted 4 lines

- zombie superblock / dangling source path / no loop-style backing-file equivalent after detach - agreed, needs fixing.

I'll rework this into a v2 that only tries to solve the "take an

Why? The structural issues are all still there.

#6 lore raw

v2 cover init: boot image-based systems without an initramfs (rootimage=)

In reply to Christian Brauner

Changes since v1 (https://lore.kernel.org/all/[email protected]/),
following Christian Brauner's review
(https://lore.kernel.org/all/20260727-gepaukt-eislauf-waran-7c03f0e47609@brauner/):

The goal is unchanged: A/B image updates from a single partition, without paying for a second userspace spin-up at boot. What changed is how rootimage=/rootimageverity= get from "here is a path" to "here is the verified, mounted root", which is what most of the v1 review was about.

- Patches 1-2 are new: they add generic, reusable VFS infrastructure (struct fs_context::source_file, path_mount_file()/ init_mount_file(), vfs_parse_fs_param_file()) that lets an in-kernel caller hand a filesystem an already-open struct file as its mount source instead of a path, and convert erofs's existing file-backed mount support to use it when given. This is the "new infrastructure available to any fs" asked for, so that init/do_mounts.c never has to independently re-resolve a path that something else already opened and validated.

- Patch 3 (rootimage=) now opens the image file exactly once and mounts that same struct file via the above, instead of opening it, doing nothing with the open, and separately handing erofs a path that it re-resolved on its own with no guaranteed relationship to what was checked - which is what v1 did, and which is where most of the "second lookup" / "weak assumptions" findings came from. There is no fd-vs-path race left because there is no second lookup left.

rootimagesrcdir= is now mandatory (rootimagesrcdir=none opts out explicitly) instead of silently detaching the carrier by default, so there's no more zombie superblock/dangling mountpoint by default; you have to ask for that outcome by name.

- Patch 4 (rootimageverity=) is mostly unchanged in what it checks, but now runs on the exact file patch 3 mounts, so the digest check and the mount are guaranteed to agree on what "the image" is. It also now refuses rootimageverity= together with rootimageflags= containing device= (multi-device erofs images), since the digest only ever covers the primary image file and silently ignoring the rest would be a false sense of integrity.

Not changed / not attempting to fix in this version, per the v1 discussion:

- The carrier filesystem itself is still fully parsed (superblock, directory entries, extents) before rootimageverity= gets to check anything, since reaching the image file at all requires that. This is structural to a file-backed image sitting on a general-purpose writable filesystem, the same way a dm-verity root still needs a trusted block layer under it; rootimage=/rootimageverity= are meant to sit on top of an already-appropriately-trusted carrier (e.g. itself dm-verity/LUKS-backed, or a well-audited always-read-only fs), not conjure trust in an arbitrary writable one out of thin air.

- A/B slot selection and fallback/rollback bookkeeping are still the bootloader's job, exactly as with dm-mod.create= today; this series only does the "resolve the one path the bootloader already chose, verify it, make it root" mechanical step for the file-backed case, not image-based deployment policy in general.

- There is still no sysfs equivalent of /sys/block/loopX/loop/backing_file to discover which file backs the root after boot (the mandatory rootimagesrcdir= at least means the carrier itself stays reachable). This would need its own generic piece of infrastructure and is left for a follow-up.

Eric Curtin (4):
fs: allow in-kernel mounters to hand filesystems an already-open
source file
erofs: use fs_context source_file for file-backed mounts when given
init: support mounting the root filesystem from an image file
init: support pinning the root image's fsverity digest

 .../admin-guide/kernel-parameters.txt         |  56 ++++
 Documentation/filesystems/mount_api.rst       |  18 ++
 fs/erofs/super.c                              |  19 ++
 fs/fs_context.c                               |  39 ++-
 fs/init.c                                     |  18 ++
 fs/internal.h                                 |   2 +
 fs/namespace.c                                |  96 ++++++-
 include/linux/fs_context.h                    |   4 +
 include/linux/init_syscalls.h                 |   2 +
 init/do_mounts.c                              | 269 +++++++++++++++++-
 10 files changed, 514 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
#7 lore raw
Quoted 44 lines · Eric Curtin

Changes since v1 (https://lore.kernel.org/all/[email protected]/),
following Christian Brauner's review
(https://lore.kernel.org/all/20260727-gepaukt-eislauf-waran-7c03f0e47609@brauner/):

The goal is unchanged: A/B image updates from a single partition, without paying for a second userspace spin-up at boot. What changed is how rootimage=/rootimageverity= get from "here is a path" to "here is the verified, mounted root", which is what most of the v1 review was about.

- Patches 1-2 are new: they add generic, reusable VFS infrastructure (struct fs_context::source_file, path_mount_file()/ init_mount_file(), vfs_parse_fs_param_file()) that lets an in-kernel caller hand a filesystem an already-open struct file as its mount source instead of a path, and convert erofs's existing file-backed mount support to use it when given. This is the "new infrastructure available to any fs" asked for, so that init/do_mounts.c never has to independently re-resolve a path that something else already opened and validated.

- Patch 3 (rootimage=) now opens the image file exactly once and mounts that same struct file via the above, instead of opening it, doing nothing with the open, and separately handing erofs a path that it re-resolved on its own with no guaranteed relationship to what was checked - which is what v1 did, and which is where most of the "second lookup" / "weak assumptions" findings came from. There is no fd-vs-path race left because there is no second lookup left.

rootimagesrcdir= is now mandatory (rootimagesrcdir=none opts out explicitly) instead of silently detaching the carrier by default, so there's no more zombie superblock/dangling mountpoint by default; you have to ask for that outcome by name.

- Patch 4 (rootimageverity=) is mostly unchanged in what it checks, but now runs on the exact file patch 3 mounts, so the digest check and the mount are guaranteed to agree on what "the image" is. It also now refuses rootimageverity= together with rootimageflags= containing device= (multi-device erofs images), since the digest only ever covers the primary image file and silently ignoring the rest would be a false sense of integrity.

Not changed / not attempting to fix in this version, per the v1 discussion:

Quoted 6 lines

- The carrier filesystem itself is still fully parsed (superblock, directory entries, extents) before rootimageverity= gets to check anything, since reaching the image file at all requires that. This is structural to a file-backed image sitting on a general-purpose writable filesystem, the same way a dm-verity root still needs a trusted block layer under it; rootimage=/rootimageverity= are meant

dm-verity reads opaque sectors whereas this runs superblock/extent/directory parsers running on attacker-writable data.

The mitigation mentioned below kinda defeats the feature... The filesystem that contains the image files is writable and the whole rootimagesrcdir= exists to keep it reachable. If you could dm-verity is as stated below, you would just dm-verity the root and used dm-mod.create=

All of the other issues:

* init suddenly becomes deployment policy
* things shipped as modules
* composefs can't use this
* the alternative to achieve the same thing via CONFIG_INITRAMFS_SOURCE / UKI signed initrd completely ignored

/me walks away from this LLM hell.

#8 lore raw

RFC PATCH v2 1/4 fs: allow in-kernel mounters to hand filesystems an already-open source file

In reply to Christian Brauner

do_new_mount() and its path_mount() wrapper only ever let a filesystem's ->get_tree() resolve its own source, either from a path string that the kernel translates to fc->source via vfs_parse_fs_param_source(), or from whatever the filesystem's own ->parse_param() does with it. There is no way for a caller that already has an open, already-validated struct file in hand to mount from *that exact file*: the best it can do is hand the filesystem a path and hope nothing about the target changed by the time the filesystem re-resolves it, which is not a guarantee the VFS can make.

Add struct fs_context::source_file alongside the existing ::source, set via a new vfs_parse_fs_param_file() instead of the string parameter path, and a new path_mount_file() / init_mount_file() pair mirroring path_mount() / init_mount() that use it. This is deliberately not wired up to the fsconfig(FSCONFIG_SET_FD) uAPI: it is for in-kernel callers only, so no existing filesystem's ->parse_param() needs to change to avoid misinterpreting it, and none is affected by this patch.

Filesystems that support being mounted from a plain file and want to accept exactly the file a caller hands them, instead of independently re-resolving fc->source (unset in this case), check fc->source_file from their ->get_tree(). erofs is converted to do so in the next patch; the immediate motivation is letting init/do_mounts.c mount an fsverity- checked root image from the same struct file it just checked, instead of a path that erofs would then look up again on its own.

---
 Documentation/filesystems/mount_api.rst | 18 +++++
 fs/fs_context.c                         | 39 +++++++++-
 fs/init.c                               | 18 +++++
 fs/internal.h                           |  2 +
 fs/namespace.c                          | 96 ++++++++++++++++++++++++-
 include/linux/fs_context.h              |  4 ++
 include/linux/init_syscalls.h           |  2 +
 7 files changed, 175 insertions(+), 4 deletions(-)
Documentation/filesystems/mount_api.rst +18 -0
index e8b94357b4df..7b799f61c39d 100644
@@ -138,6 +138,24 @@ The fs_context fields are as follows:
      This specifies the source.  It may be a block device (e.g. /dev/sda1) or
      something more exotic, such as the "host:/path" that NFS desires.
 
+   * ::
+
+       struct file *source_file
+
+     An alternative to ``source`` for in-kernel mounters only (there is no
+     userspace-visible way to set this): an already-open file to use as the
+     source, set by vfs_parse_fs_param_file() instead of parsing a path
+     string.  At most one of ``source`` and ``source_file`` is ever set.
+
+     Filesystems that support being mounted from a plain file (as opposed to
+     a block device) and want to let such an in-kernel caller hand them an
+     exact, already-validated file - rather than a path they would then have
+     to re-resolve themselves, with no way to guarantee the two refer to the
+     same thing - should check this field in their ``get_tree`` and use it
+     directly instead of falling back to opening ``source``.  See
+     fs/erofs/super.c:erofs_fc_get_tree() for reference, and
+     init/do_mounts.c:mount_root_image() for the in-kernel caller.
+
    * ::
 
        char *subtype
fs/fs_context.c +38 -1
index 23ad66cd94e1..ab853147b87b 100644
@@ -85,7 +85,7 @@ int vfs_parse_fs_param_source(struct fs_context *fc, struct fs_parameter *param)
 	if (param->type != fs_value_is_string)
 		return invalf(fc, "Non-string source");
 
-	if (fc->source)
+	if (fc->source || fc->source_file)
 		return invalf(fc, "Multiple sources");
 
 	fc->source = param->string;
@@ -94,6 +94,36 @@ int vfs_parse_fs_param_source(struct fs_context *fc, struct fs_parameter *param)
 }
 EXPORT_SYMBOL(vfs_parse_fs_param_source);
 
+/**
+ * vfs_parse_fs_param_file - Set an already-open file as the mount source
+ * @fc: The filesystem context to modify
+ * @key: Parameter name; only "source" is currently supported
+ * @file: The file to use as the mount source
+ *
+ * In-kernel callers (see path_mount_file()) can use this to hand a
+ * filesystem an already-opened struct file as its source, instead of a
+ * path string for the filesystem to resolve on its own.  A reference is
+ * taken; it is released when @fc is freed.
+ *
+ * This deliberately has no fsconfig(FSCONFIG_SET_FD) counterpart: it is
+ * not reachable from userspace, so no filesystem needs to opt in to
+ * receive it and existing ->parse_param() implementations are unaffected.
+ * Filesystems that want to use the file directly (rather than silently
+ * ignoring it and falling back to re-resolving fc->source, which is not
+ * set in this case) check fc->source_file from their ->get_tree().
+ */
+int vfs_parse_fs_param_file(struct fs_context *fc, const char *key,
+			    struct file *file)
+{
+	if (strcmp(key, "source"))
+		return -EINVAL;
+	if (fc->source || fc->source_file)
+		return invalf(fc, "Multiple sources");
+	fc->source_file = get_file(file);
+	return 0;
+}
+EXPORT_SYMBOL(vfs_parse_fs_param_file);
+
 /**
  * vfs_parse_fs_param - Add a single parameter to a superblock config
  * @fc: The filesystem context to modify
@@ -376,6 +406,7 @@ struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc)
 	fc->fs_private	= NULL;
 	fc->s_fs_info	= NULL;
 	fc->source	= NULL;
+	fc->source_file	= NULL;
 	fc->security	= NULL;
 	get_filesystem(fc->fs_type);
 	get_net(fc->net_ns);
@@ -504,6 +535,8 @@ void put_fs_context(struct fs_context *fc)
 	put_fc_log(fc);
 	put_filesystem(fc->fs_type);
 	kfree(fc->source);
+	if (fc->source_file)
+		fput(fc->source_file);
 	kfree(fc);
 }
 EXPORT_SYMBOL(put_fs_context);
@@ -543,6 +576,10 @@ void vfs_clean_context(struct fs_context *fc)
 	security_free_mnt_opts(&fc->security);
 	kfree(fc->source);
 	fc->source = NULL;
+	if (fc->source_file) {
+		fput(fc->source_file);
+		fc->source_file = NULL;
+	}
 	fc->exclusive = false;
 
 	fc->purpose = FS_CONTEXT_FOR_RECONFIGURE;
fs/init.c +18 -0
index 33e312d74f58..d896d937e3e2 100644
@@ -44,6 +44,24 @@ int __init init_mount(const char *dev_name, const char *dir_name,
 	return ret;
 }
 
+/*
+ * Like init_mount(), but the source is an already-open file rather than a
+ * path for the filesystem to resolve on its own; see path_mount_file().
+ */
+int __init init_mount_file(struct file *file, const char *dir_name,
+		const char *type_page, unsigned long flags, void *data_page)
+{
+	struct path path;
+	int ret;
+
+	ret = kern_path(dir_name, LOOKUP_FOLLOW, &path);
+	if (ret)
+		return ret;
+	ret = path_mount_file(file, &path, type_page, flags, data_page);
+	path_put(&path);
+	return ret;
+}
+
 int __init init_umount(const char *name, int flags)
 {
 	int lookup_flags = LOOKUP_MOUNTPOINT;
fs/internal.h +2 -0
index d77578d66d42..04fb75383024 100644
@@ -91,6 +91,8 @@ extern bool may_mount(void);
 
 int path_mount(const char *dev_name, const struct path *path,
 		const char *type_page, unsigned long flags, void *data_page);
+int path_mount_file(struct file *file, const struct path *path,
+		const char *type_page, unsigned long flags, void *data_page);
 int path_umount(const struct path *path, int flags);
 int path_pivot_root(struct path *new, struct path *old);
 
fs/namespace.c +93 -3

121 lines not on this page · raw message

include/linux/fs_context.h +4 -0
index 0d6c8a6d7be2..b35d7583f0bd 100644
@@ -16,6 +16,7 @@
 
 struct cred;
 struct dentry;
+struct file;
 struct file_operations;
 struct file_system_type;
 struct mnt_namespace;
@@ -99,6 +100,7 @@ struct fs_context {
 	const struct cred	*cred;		/* The mounter's credentials */
 	struct p_log		log;		/* Logging buffer */
 	const char		*source;	/* The source name (eg. dev path) */
+	struct file		*source_file;	/* Already-open source file, in-kernel only */
 	void			*security;	/* LSM options */
 	void			*s_fs_info;	/* Proposed s_fs_info */
 	unsigned int		sb_flags;	/* Proposed superblock flags (SB_*) */
@@ -148,6 +150,8 @@ extern int vfs_get_tree(struct fs_context *fc);
 extern void put_fs_context(struct fs_context *fc);
 extern int vfs_parse_fs_param_source(struct fs_context *fc,
 				     struct fs_parameter *param);
+int vfs_parse_fs_param_file(struct fs_context *fc, const char *key,
+			    struct file *file);
 extern void fc_drop_locked(struct fs_context *fc);
 
 extern int get_tree_nodev(struct fs_context *fc,
include/linux/init_syscalls.h +2 -0
index 28776ee28d8e..ac937cdb9d46 100644
@@ -2,6 +2,8 @@
 
 int __init init_mount(const char *dev_name, const char *dir_name,
 		const char *type_page, unsigned long flags, void *data_page);
+int __init init_mount_file(struct file *file, const char *dir_name,
+		const char *type_page, unsigned long flags, void *data_page);
 int __init init_umount(const char *name, int flags);
 int __init init_chdir(const char *filename);
 int __init init_chroot(const char *filename);
Signature · 1 line
2.43.0
#9 lore raw

RFC PATCH v2 2/4 erofs: use fs_context source_file for file-backed mounts when given

In reply to Christian Brauner

erofs_fc_get_tree() falls back to filp_open(fc->source, ...) itself when get_tree_bdev_flags() reports the source isn't a block device. That is the only way to reach erofs's file-backed mount support today, which means an in-kernel caller that already opened and validated (e.g. fsverity-checked) that exact file has no way to make erofs mount it: it can only hand over the path again and trust erofs's independent lookup to land on the same file, which it has no way to guarantee.

Check fc->source_file first and use it directly when set, taking a reference and skipping the independent filp_open(fc->source) entirely (fc->source is unset in this case). This has no effect on the existing path-based fsconfig()/mount(2) flow, since userspace has no way to set fc->source_file (see the previous patch); it only enables in-kernel callers such as the following init/do_mounts.c change.

---
 fs/erofs/super.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
fs/erofs/super.c +19 -0
index 802add6652fd..b6cd4fde3ca2 100644
@@ -799,6 +799,25 @@ static int erofs_fc_get_tree(struct fs_context *fc)
 	if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid)
 		return get_tree_nodev(fc, erofs_fc_fill_super);
 
+	/*
+	 * An in-kernel caller (see path_mount_file()) has handed us the
+	 * exact, already-open file to mount, rather than a path for us to
+	 * resolve ourselves: use it directly instead of independently
+	 * re-opening fc->source (which isn't set in this case), so that
+	 * whatever the caller validated about this file - e.g. an fsverity
+	 * digest - is guaranteed to still apply to what actually gets
+	 * mounted.
+	 */
+	if (fc->source_file) {
+		if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE))
+			return invalf(fc, "File-backed mounts not supported");
+		if (!S_ISREG(file_inode(fc->source_file)->i_mode) ||
+		    !fc->source_file->f_mapping->a_ops->read_folio)
+			return invalf(fc, "Source file is not a plain, read-foliable file");
+		sbi->dif0.file = get_file(fc->source_file);
+		return get_tree_nodev(fc, erofs_fc_fill_super);
+	}
+
 	ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
 		IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
 			GET_TREE_BDEV_QUIET_LOOKUP : 0);
Signature · 1 line
2.43.0
#10 lore raw

RFC PATCH v2 3/4 init: support mounting the root filesystem from an image file

In reply to Christian Brauner

Image-based Linux systems (bootc-style OS updaters, ChromeOS/Android-like A/B schemes, embedded appliances) commonly keep one or more immutable root filesystem images as plain files on a writable "carrier" filesystem and pick one at boot. Today that always requires an initramfs, even when the initramfs has nothing else to do: the kernel can only mount a block device (or NFS/CIFS/ubi/mtd) as root, so userspace must mount the carrier, loop-mount the image and switch_root into it.

Add a rootimage= parameter naming an image file on the filesystem specified by root=. When set, root= only designates the carrier: after mounting it as usual, mount the image file read-only on /image and make that the root that prepare_namespace() pivots into. The image is mounted through the filesystem's file-backed mount support (available in erofs since v6.12) using path_mount_file()/init_mount_file() from the preceding patches: the image is opened exactly once, and that same struct file is what actually gets mounted, rather than a path for the filesystem driver to resolve a second time on its own. rootimagefstype= and rootimageflags= mirror rootfstype=/rootflags= for the image mount, while "ro"/"rw"/rootflags= keep applying to the carrier.

rootimagesrcdir= names a directory inside the image where the carrier mount is moved once the image is up, since systems following this model virtually always need continued access to the carrier for their writable state. Unlike an earlier version of this patch, this is mandatory rather than defaulting to silently detaching the carrier:
that default made it too easy to end up with a carrier mount that's still alive (the image mount pins its superblock either way) but unreachable from the new namespace, with no equivalent of /sys/block/loopX/loop/backing_file to even tell what it was. Systems that positively don't need the carrier again can still get the old behaviour with rootimagesrcdir=none, but have to say so.

This is the file-backed analogue of what dm-mod.create= (CONFIG_DM_INIT) already does for device-mapper targets: moving a fixed, declarative bit of early-boot setup from initramfs userspace into the kernel so that small and verified systems can boot with no initramfs at all.

Assisted-by opencode:claude-fable-5
---
 .../admin-guide/kernel-parameters.txt         |  34 ++++
 init/do_mounts.c                              | 188 +++++++++++++++++-
 2 files changed, 217 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +34 -0
index 4d0f545fb3ec..a1cd5973e497 100644
@@ -6732,6 +6732,40 @@ Kernel parameters
 
 	rootfstype=	[KNL] Set root filesystem type
 
+	rootimage=	[KNL] Mount the actual root filesystem from this
+			filesystem image file (absolute path) located on the
+			filesystem specified by root=, instead of using that
+			filesystem as the root directly.  This allows
+			image-based systems that keep their (typically
+			read-only, e.g. erofs) root filesystem images as
+			plain files on a carrier filesystem to boot without
+			an initramfs.  The image is mounted read-only via
+			the filesystem's file-backed mount support (no loop
+			device is set up); "ro", "rw" and rootflags= keep
+			applying to the carrier filesystem.  Requires
+			rootimagesrcdir=.
+
+	rootimageflags=	[KNL] Set root image filesystem mount option string,
+			used together with rootimage=.
+
+	rootimagefstype= [KNL] Set root image filesystem type, used together
+			with rootimage=.  Default is to try all filesystems
+			known to the kernel that can mount a block device or
+			an image file.
+
+	rootimagesrcdir= [KNL] Directory (absolute path) inside the root
+			image where the mount of the carrier filesystem
+			holding the image (i.e. the filesystem specified by
+			root=) is moved to.  Mandatory when rootimage= is
+			used, since image-based systems almost always need
+			continued access to the carrier for their writable
+			state, and there would otherwise be no way to reach
+			it again once switch_root has happened.  Pass
+			rootimagesrcdir=none instead to explicitly detach the
+			carrier mount, accepting that it becomes unreachable
+			(though still pinned alive by the image mount) after
+			boot.
+
 	rootwait	[KNL] Wait (indefinitely) for root device to show up.
 			Useful for devices that are detected asynchronously
 			(e.g. USB and MMC devices).
init/do_mounts.c +183 -5

223 lines not on this page · raw message

Signature · 1 line
2.43.0
#11 lore raw

RFC PATCH v2 4/4 init: support pinning the root image's fsverity digest

In reply to Christian Brauner

When the root filesystem is mounted from an image file with rootimage=, the carrier filesystem holding the image is typically writable and therefore untrusted. Systems that seal their root images with fsverity currently need an initramfs for the sole purpose of checking that the image carries the expected fsverity digest before mounting it.

Add rootimageverity=<hash algorithm>:<hex digest>, which requires the rootimage= file to have fsverity enabled with exactly this file digest and fails the boot otherwise, using the same fsverity_get_digest() interface that IMA and overlayfs already use for digest pinning. Verification runs on the exact struct file that mount_root_image() then hands to do_mount_root_file(): the fd-based mount from the preceding patches means there is no separate path lookup afterwards that could resolve to something else, and nothing between the check and the mount that a userspace-less boot could race.

Combined with a trusted kernel command line (e.g. a signed unified kernel image, or a TPM-measured bootloader configuration), this extends the chain of trust to every byte of the root filesystem without any userspace boot stage: the digest pins the image's Merkle tree, and fsverity keeps verifying all data read from the image against it at runtime, so post-boot tampering with the carrier filesystem is detected as well. It is the file-backed counterpart of setting up a dm-verity target for a partition-backed root via dm-mod.create=.

Two things this does not and cannot do:

- Establish trust in the carrier filesystem itself. Reaching the image file at all means parsing carrier filesystem metadata (superblock, directory entries, extents) before any of this runs, the same way a dm-verity root still needs a trusted block layer underneath it - this is meant to sit on top of an already-appropriately-trusted carrier (e.g. one that is itself dm-verity/LUKS-backed, or a well-audited always-read-only filesystem), not conjure trust in an arbitrary writable one.

- Cover erofs images that pull in extra devices via rootimageflags=device=device=..., since the pinned digest only ever applies to the primary image file. Refuse to boot in that combination rather than give a false sense of integrity.

Assisted-by opencode:claude-fable-5
---
 .../admin-guide/kernel-parameters.txt         | 22 +++++
 init/do_mounts.c                              | 91 ++++++++++++++++++-
 2 files changed, 108 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +22 -0
index a1cd5973e497..dcb5a78fba55 100644
@@ -6766,6 +6766,28 @@ Kernel parameters
 			(though still pinned alive by the image mount) after
 			boot.
 
+	rootimageverity= [KNL] Require the root image specified by
+			rootimage= to have fsverity enabled with this file
+			digest, given as <hash algorithm>:<hex digest>,
+			e.g. sha256:dd1b3fa9...  The boot is aborted if the
+			image carries no or a different fsverity digest, or
+			if rootimageflags= adds extra devices via device=
+			(their contents would not be covered by the digest).
+			Because fsverity keeps verifying data read from the
+			image against its Merkle tree at runtime, a trusted
+			(e.g. signed or TPM-measured) kernel command line
+			extends the chain of trust to the complete root
+			filesystem contents without an initramfs, provided
+			the carrier filesystem holding the image is itself
+			from a trusted source (rootimage= verifies the image
+			file; it does not and cannot retroactively establish
+			trust in the carrier filesystem code and metadata
+			that had to be parsed to reach that file in the first
+			place - the same way a dm-verity root still needs a
+			trusted block layer under it).  Requires
+			CONFIG_FS_VERITY and a carrier filesystem with
+			fsverity support.
+
 	rootwait	[KNL] Wait (indefinitely) for root device to show up.
 			Useful for devices that are detected asynchronously
 			(e.g. USB and MMC devices).
init/do_mounts.c +86 -5

137 lines not on this page · raw message

Signature · 1 line
2.43.0
#12 lore raw
In reply to Eric Curtin
Quoted 7 lines · Eric Curtin

Image-based Linux systems (bootc-style OS updaters, ChromeOS/Android-like A/B schemes, embedded appliances) keep one or more immutable root filesystem images as sealed files on a writable filesystem and pick one at boot. Booting such a system today always requires an initramfs, even when that initramfs has nothing else to do; its only jobs are to parse the kernel command line, mount the state filesystem, verify the image, loop-mount it and switch_root into it.

What's the higher level goal? Is it boot speed? That's my guess, but this needs to be stated explicitly and I'd really like to see some numbers on this. If you're using LLMs to do this kind of stuff, there's ~no excuse not to spend the tokens to generate benchmarks and things.

Also, we need to weigh this approach vs "static initramfs binary"; AFAIK it has historically been pretty common in some embedded/appliance style setups to have the initramfs basically be a single statically linked binary (and if I was doing this, it'd be in Rust nowadays). That's a wildly different thing than the typical dracut or equivalent thing, *especially* if you're comparing this approach vs a non-appliance general purpose initramfs.

At least for the composefs case, I bet it'd be quite easy to get to that single static Rust binary, and at a high level putting that into e.g. a UKI seems to me a lot more preferable than trying to push all of this into the Linux kernel core.