|
|
Log in / Subscribe / Register

Adding fs-verity support for Fedora 36?

By Jake Edge
December 14, 2021

Adding fs-verity file-integrity information to RPM packages for Fedora 36 is the topic of a recent discussion on the Fedora devel mailing list. The feature would provide a means to install files from RPM packages as read-only files that cannot be read or otherwise operated on if the data in the files changes at any point. The proposal is mostly about making the plumbing available for use cases that are not particularly clear—which has led to some questions and skepticism among those participating in the thread.

fs-verity and RPM

Fs-verity is a kernel feature that is supported by some filesystems; it provides a way to ensure that the contents of a file cannot change on disk. It revolves around a Merkle tree that is created for each file being protected; the tree contains hashes of each data block in the file. When a file is protected by fs-verity, it is marked as read-only and every read operation checks that the block read matches the value stored in the tree; the operation fails if there is no match. In addition, the tree itself can be cryptographically signed to ensure that nothing has been changed underneath the filesystem by, say, accessing the raw block device or image file.

Fedora program manager Ben Cotton posted the Fedora change proposal to add fs-verity support on behalf of the feature owners: Davide Cavalca, Boris Burkov, Filipe Brandenburger, Michel Alexandre Salim, and Matthew Almond. There are several elements to the plan. To start with, the Koji build system needs to be able to create and sign the Merkle tree for each file that gets shipped in the RPM package. The tree itself is not added to the RPM package, just the signed top-level hash for each file.

On the other end, an optional fs-verity RPM plugin would install the Fedora key and enable fs-verity for each file it installs. The filesystem would then recreate the Merkle tree, check it against the signature in the RPM metadata, and store the tree with the file. After that, each access to the file will be checked against the tree, which means that various kinds of operations (e.g. read(), mmap(), execve(), etc.) will only proceed if the data blocks on disk have not changed.

The proposal mainly focuses on the build side of the equation: "Specifically, installing and enabling the fs-verity rpm plugin by default is explicitly considered out of scope here." The overhead of creating the Merkle tree at installation time did not "appear to meaningfully slow down package installs during empirical testing", but there is some (unspecified) cost of creating the tree for every Koji build, of course. The Merkle tree is only stored if the RPM fs-verity plugin is enabled and adds roughly 1/127th (0.8%) to the size of the installed file. All RPMs would get additional metadata, in the form of signatures, if the proposal is adopted, but even that is fairly negligible: "in the vast majority of cases we expect to see minimal to no size increase thanks to RPM header packing".

Reaction

Kevin Fenzi had a number of questions about the proposal. He wondered which keys would be used to sign the Merkle tree at build time and who would work on the changes to the RoboSignatory component that supplies signatures to Koji in order to make all of this happen. In addition, only ext4, F2FS, and, since Linux 5.15, Btrfs (commit) have support for fs-verity; what happens for other filesystems such as XFS?

Cavalca replied, noting that the feature owners plan to work on the changes to RoboSignatory, but would need some help and advice with code review, testing, and deployment. They will be looking into the possibility of using the Fedora package-signing key:

fs-verity needs a RSA key/cert pair for file signing at package signature time. At package install time, the cert needs to be loaded in the appropriate kernel keyring. We've always used a dedicated keypair during testing -- I'm not actually sure if the package signing key could be reused for this, as it's a GPG key, but this is something we should follow up on.

Beyond that, if the filesystem does not support fs-verity, the plugin will fail and there will be no protection of that sort. If it is desired, though, fs-verity support for XFS could be added, he said.

Josh Boyer asked about adding fs-verity support for Fedora when a seemingly similar feature, adding IMA signatures to RPM, was rejected due in part to its impact on RPM size. The Integrity Measurement Architecture (IMA) is a kernel-based mechanism that can be used to detect file tampering, but Salim said that the impact on RPM size is much smaller for fs-verity than for IMA. The idea is that users who do not install the RPM plugin "will be mostly unimpacted" by the change. The proposal compared the two integrity mechanisms, noting a smaller impact at run time as well:

Because fsverity operates on block reads, its runtime cost is small (as it only needs to verify the block that is being accessed), and it can protect from alterations at any point in time.

IMA works by measuring a file as a whole and comparing its signature whenever it’s read of executed. It has a higher runtime cost than fsverity (as it needs to verify the whole file at once) and it cannot detect subsequent alternations.

The proposal also said that IMA provides a rich policy system that can be tied into other security mechanisms, such as SELinux; it might make sense to integrate the two down the road. But Boyer and others were interested in what benefit fs-verity would bring to Fedora and its use cases. Boyer said that the benefit listed in the proposal could largely be fulfilled by IMA, so he wanted to know more. Cavalca said that this particular proposal was "mostly about putting in place the necessary plumbing"; he also described one potential use case:

For example, consider an appliance-like system placed in an untrusted location where you may not be able to control who has physical access (this could be a server, but it could also be a kiosk in an internet point or a school). In this scenario, fs-verity can be one of the building blocks to ensure and maintain system trust.

As with most security solutions, Cavalca continued, fs-verity is no silver bullet, but it is a useful building block:

Once fs-verity is enabled for a given file (which, in the RPM case, happens at package installation time), it cannot be disabled, and the file becomes immutable. One can still rename() or unlink() it (and this is indeed how rpm is able to replace files when upgrading packages), but the actual contents cannot be altered.

Where is this useful? For example, fs-verity can help in the scenario where an attacker has out-of-band access to the storage device (say, they pull a hard drive from a colo'd server or a sdcard from an embedded device, or they boot into a liveusb, or they access a VM image directly from a host).

Let's say that happens, and the attacker changes a few blocks of /bin/ls on the device to make it run nefarious code. When you boot your system again, it would fail at exec() time because the Merkle tree wouldn't match.

But since an attacker can simply replace the files, or add new ones, there is still a missing piece, as Zbigniew Jędrzejewski-Szmek pointed out:

If fs-verity verification prevents me from successfully modifying or replacing /usr/bin/foo or /usr/lib/systemd/system/foo.service, is there anything which hinders just adding /etc/systemd/system/foo.service that does whatever I want?

He asked if there was a Linux Security Module (LSM) available to enforce whatever policies are needed to ensure the integrity of the system. Beyond that, if an attacker can replace a binary like /bin/ls, they may also be able to add new keys to the kernel keyring that would allow their binaries to pass the fs-verity checks.

If the keys are loaded from the file system, can I just drop in a rogue key, similarly to what happens when new keys are distributed as part of distro upgrades?

Florian Weimer described two additional problems that he called "unsolvable". Attackers can reuse binaries from unrelated Fedora packages that have been signed properly, or they can alter the system configuration to disable the feature at boot time. Given those problems, he said, it is unlikely that anyone who actually wants this kind of a feature would use the signatures being added to the RPM files:

The combination of these two unsolvable issues suggests to me that anyone who wants to deploy this is better off with their own trust root, and that approach will include their particular version of key management as well. But this also means that pre-computed file signatures are not [particularly] useful to them. They would have to discard them anyway before deployment.

Burkov agreed that there were some missing pieces, but noted that a message from Roberto Sassu mentioned some ongoing work integrating fs-verity with IMA that might lead to a solution to some of these problems. But, in a similar vein, Lennart Poettering pointed out a number of areas where the threat model is not at all clear—the protections are not really geared to the problems that Fedora users might have:

This protects file contents, not the [metadata], right? So what about the metadata? if I see a fs-verity enabled inode with libssl.so data in it today, and it's a vulnerably version, and I make a hardlink to it, and then it gets replaced by a fixed version (with a slightly updated name) — how you intend to make sure, that i can't fool you into loading my copy of the old file but under the new name?

[...] Is there any protection against downgrades between RPM package versions? Does this in any way protect combinations of binaries/libraries? I mean, pretty much all programs we ship consist of a large number of ELF objects, and you probably need to sign the combination of them, but this model doesn't look like it offers that at all?

There are some areas that need further research, Burkov said, but the threat model is not really specified because the feature is simply meant as plumbing:

The short answer is that just this change as-is has no practical threat model, we viewed it as an enablement step that we believe has a realistic path to broadly authenticated rpm contents. Alternatively, it does give a sophisticated user an opportunity to build something like that for themselves as well.

Poettering expressed further skepticism about the proposal, noting: "Infrastructure that has no consuming feature typically doesn't work. Experience tells us that." But, even if that were overcome, the protection provided is not particularly useful: "If I can have 'ping' and 'poweroff' binaries both signed by Fedora, but then swap them without the signing being able to detect that, why do this at all?"

There were other concerns raised as well. For example, Stephen John Smoogen objected on logistical grounds. Any changes need to be in place before the mass rebuild for Fedora 36, which is currently scheduled for January 19. Given the upcoming holiday season, it is pretty unlikely that those who need to review and sign off on these kinds of changes will even be available to do so. "Even if the changes are trivial ones, this is a very short window to land things." He suggested that Fedora 37 would be a more realistic target.

The wiki version of the change proposal has been updated with further information, along with responses to many of the questions and concerns posted in the thread. But without a real use case that benefits some actual subset of Fedora users, this has the look of a feature that is going nowhere fast. Perhaps what is needed is to join forces with those who are working on IMA to come up with an integrated plan that does provide a threat model and real use cases. The IMA proposal, for example, pointed to the Fedora IoT edition as a possible consumer of that feature, which is more in line with the existing use of fs-verity in Android. Boyd made it clear that Red Hat is interested in seeing IMA support in Fedora, so there would perhaps be some synergy in a combined effort. That approach may find more traction with the Fedora community.


Index entries for this article
SecurityDistribution security
SecurityIntegrity


to post comments

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 0:15 UTC (Wed) by developer122 (guest, #152928) [Link] (2 responses)

The building block for larger security schemes is nice and all, but I'm not really even interested in it from the standpoint of security.

This sounds like it could also be used to ensure the integrity of a file, like system libraries for example, against random corruption. It can be automatically detected if a file has been damaged since it was installed, and I suppose in later work damaged files could be automatically re-aquired.

Not all filesystems are ZFS, with their own internal per-block checksums.

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 2:33 UTC (Wed) by Henning (subscriber, #37195) [Link]

This seems more like a job for dm-integrity and it seems like systemd 250 will support it (at least according to the release notes).

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 9:52 UTC (Wed) by gray_-_wolf (subscriber, #131074) [Link]

> Not all filesystems are ZFS, with their own internal per-block checksums.

Btrfs does that as well, so there is in-kernel support for this. You don't need ZFS.

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 8:51 UTC (Wed) by taladar (subscriber, #68407) [Link] (1 responses)

So what happens if we need to update the file on purpose, either via RPM, or, such as in the case of the recent log4j issues, through manual workarounds (e.g. adding a property to the shell script starting some Java application)?

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 9:18 UTC (Wed) by rahulsundaram (subscriber, #21946) [Link]

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 11:15 UTC (Wed) by LtWorf (subscriber, #124958) [Link] (14 responses)

Seems to me the actual users of the feature would be proprietary softwares that don't want people to replace bad sections of code with NOP, edit scripts, and so on…

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 11:45 UTC (Wed) by Conan_Kudo (subscriber, #103240) [Link] (2 responses)

It wouldn't work very well for them, since (if you are the administrator) you can just turn it off and do what you will.

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 13:26 UTC (Wed) by gray_-_wolf (subscriber, #131074) [Link] (1 responses)

Then what *is* the actual use case for this? If someone can temper with the actual blocks on the device, what does this exactly prevent? I know that the article said that it's supposed to be just plumbing with some use case (maybe) comming later, but should the use case be first?

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 16:07 UTC (Wed) by LtWorf (subscriber, #124958) [Link]

My suspicious nature is that there is a use case for this but it's nothing the community would like.

If there is not a use case I agree that it's a complete waste of time since probably use cases will require different features to be implemented.

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 16:48 UTC (Wed) by mebrown (subscriber, #7960) [Link] (10 responses)

I ship an embedded linux device. That device has to adhere to various NIST and other governmental standards regarding robustness and reliability. We are very interested in using this stack of technologies to secure our device for our users. We have built in a way for the user to take control of their device and install their own stuff to handle the folks that want to do the open source management themselves, but the default device state is that it is verifiably secure with cryptographic checks up and down the stack. We cant sell into a huge segment of the marketplace without these controls in place.

stack looks like: DM-Crypt + DM-Integrity, EXT or F2FS, FS-Verity, OSTree + Flatpack

With the above plus SELinux and all internal daemons running as non-root, we have good protection against offline attacks (think desoldering EMMC chips) as well as protection against runtime hacks.

The biggest hole I can see is we need a way to sign/seal directories to prevent executable replacement attacks.

This stack enables us to provide more features over the older technologies, so there is distinct benefit to users even if they never crack it open themselves. The old stack was squashfs+dm-verity, so fundamentally everything was read-only. With the new stack, we can enable installation of application-level updates, installation of new applicaitons, and more.

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 18:05 UTC (Wed) by LtWorf (subscriber, #124958) [Link] (4 responses)

but… if you change the files while the machine is off… why not also disable the fs check then as well?

It seems the old problem of trying to make a root account less powerful by just adding extra steps to achieve the same things.

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 18:22 UTC (Wed) by bluca (subscriber, #118303) [Link] (1 responses)

fsverity is a feature flag, you cannot disable it on a filesystem once it's enabled

Adding fs-verity support for Fedora 36?

Posted Dec 16, 2021 0:34 UTC (Thu) by draco (subscriber, #1792) [Link]

Can't be turned off even if I'm directly modifying the bits on the device?

Adding fs-verity support for Fedora 36?

Posted Dec 16, 2021 17:43 UTC (Thu) by mebrown (subscriber, #7960) [Link] (1 responses)

The entire point of the stack (DM-Crypt+DM-Integrity) is to ensure there is no possible way to modify anything while the machine is off. This protects against several threat models: supply chain attacks where equipment is intercepted en-route and malicious firmware installed, attacks involving theft, possibly others.

Most of the government purchasing contracts require robust protection against supply chain attacks.

Adding fs-verity support for Fedora 36?

Posted Dec 17, 2021 7:07 UTC (Fri) by LtWorf (subscriber, #124958) [Link]

But this doesn't protect user data?

Isn't it better (actually safe instead of kinda safe in a few selected scenarios) to use a usb stick to boot and then an encrypted partition?

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 21:27 UTC (Wed) by walters (subscriber, #7396) [Link] (2 responses)

Are you doing the ostree+fs-verity stuff out of band? This relates to https://github.com/ostreedev/ostree/pull/2269

Adding fs-verity support for Fedora 36?

Posted Dec 16, 2021 17:48 UTC (Thu) by mebrown (subscriber, #7960) [Link] (1 responses)

Correct. The merkle trees and signatures would all be computed and signed by the build system in a secure manner.

It looks to me like the RPM mechanism in discussion for Fedora actually 'ships' only the signature with the RPM, and the merkle trees are re-constructed at installation time. We are likely to do something similar, but are still in early design phase so that's not coded up yet.

Personally, I am a big fan of the "ship the signatures, reconstruct the merkle trees on install" method. We did something similar in the past with DM-Verity and even re-construct the verity forward error correction codes on install. Saves a fair amount of download bandwidth.

Adding fs-verity support for Fedora 36?

Posted Dec 16, 2021 23:16 UTC (Thu) by walters (subscriber, #7396) [Link]

(upstream ostree developer here btw)

One big problem with ostree and fs-verity that I was wrestling with is that by design, the data format is not extensible - extensibility is hard to mix with cryptographic checksums and reproducibility. There isn't a place to put new per-file data in the current design; at least, not without doing some hacks.

That said we have a big initiative going on recently around "container native" ostree where we encapsulate the updates inside a container image - see https://fedoraproject.org/wiki/Changes/OstreeNativeContainer - and the tar format is much more flexible (which is both a benefit and a drawback, see e.g. https://github.com/vbatts/tar-split )

But basically I've been thinking it could make sense to embed fs-verity Merkle trees and signatures in the tar stream, and have the client know how to write those natively.

Adding fs-verity support for Fedora 36?

Posted Jan 3, 2022 12:26 UTC (Mon) by Klavs (guest, #10563) [Link] (1 responses)

you cannot in fact protect against physical attacks IMHO - and it sounds unlikely anyone would even bother trying for a "personal user"-device - and also - trying to do physical protection, sounds more like you're trying to build a tivo device - ie. one thats protected against the owner actually using his rights to modify the software as he sees fit.. - not a good use case in my book.

Adding fs-verity support for Fedora 36?

Posted Jan 3, 2022 12:27 UTC (Mon) by Klavs (guest, #10563) [Link]

TPM is the "closest attempt" - but again - if its a personal user device - I strongly dislike "protecting" against the user being able to exercise their rights

Adding fs-verity support for Fedora 36?

Posted Dec 15, 2021 11:26 UTC (Wed) by atnot (guest, #124910) [Link] (1 responses)

> If the keys are loaded from the file system, can I just drop in a rogue key, similarly to what happens when new keys are distributed as part of distro upgrades?

I don't think that's inherently disarming. Adding keys is a much noisier operation than swapping out binaries with modified versions. If attackers are forced to do easily detectable things to gain persistence on a system, I think that is a good thing. If you can't have a lock it's good to at least have a seal.

Adding fs-verity support for Fedora 36?

Posted Dec 20, 2021 12:14 UTC (Mon) by zuki (subscriber, #41808) [Link]

> Adding keys is a much noisier operation than swapping out binaries with modified versions.

The point I was trying to make is that partial protection is very easy to circumvent without anyone noticing. My Fedora installation is 800k *files* under /usr, and 4500 files under /etc. With so many files, it's just too easy to find thousands of files that can be modified to hide something nefarious without anyone ever noticing. Signing keys may be not be the best option for stealth, but they are an obvious example of how you can defeat the system if you can modify arbitrary files.


Copyright © 2021, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds