Message ID | cover.1667389115.git.sweettea-kernel@dorminy.me (mailing list archive) |
---|---|
Headers | show |
Series | btrfs: add fscrypt integration | expand |
Thank you for creating this! I'm told the design document [1] no longer reflects the current proposal in these patches. If that's so I think it's worth bringing the design document up to date so we can review the cryptography. Thanks! [1] https://docs.google.com/document/d/1iNnrqyZqJ2I5nfWKt7cd1T9xwU0iHhjhk9ALQW3XuII/edit
On Thu, Nov 3, 2022 at 3:54 PM Paul Crowley <paulcrowley@google.com> wrote: > > Thank you for creating this! I'm told the design document [1] no > longer reflects the current proposal in these patches. If that's so I > think it's worth bringing the design document up to date so we can > review the cryptography. Thanks! > > [1] https://docs.google.com/document/d/1iNnrqyZqJ2I5nfWKt7cd1T9xwU0iHhjhk9ALQW3XuII/edit So this might be my ignorance here, but when I look at the patch set, I don't really see any significant mathematics or cryptographic work going on here. This seems to be primarily just interacting with the fscrypt stuff that exists in the kernel already. Could you please clarify what you mean here?
On 11/3/22 15:22, Paul Crowley wrote: > Thank you for creating this! I'm told the design document [1] no > longer reflects the current proposal in these patches. If that's so I > think it's worth bringing the design document up to date so we can > review the cryptography. Thanks! > > [1] https://docs.google.com/document/d/1iNnrqyZqJ2I5nfWKt7cd1T9xwU0iHhjhk9ALQW3XuII/edit I apologize for the delay; I realized when this thread was bumped just now that my attempt to share the updated doc didn't seem to make it to the mailing list. https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing is an update of the design document that hopefully is what you're requesting.
On Wed, Nov 16, 2022 at 03:08:26PM -0500, Neal Gompa wrote: > On Thu, Nov 3, 2022 at 3:54 PM Paul Crowley <paulcrowley@google.com> wrote: > > > > Thank you for creating this! I'm told the design document [1] no > > longer reflects the current proposal in these patches. If that's so I > > think it's worth bringing the design document up to date so we can > > review the cryptography. Thanks! > > > > [1] https://docs.google.com/document/d/1iNnrqyZqJ2I5nfWKt7cd1T9xwU0iHhjhk9ALQW3XuII/edit > > So this might be my ignorance here, but when I look at the patch set, > I don't really see any significant mathematics or cryptographic work > going on here. This seems to be primarily just interacting with the > fscrypt stuff that exists in the kernel already. > > Could you please clarify what you mean here? There absolutely is significant cryptographic work going on here. There needs to be a new way to choose keys and IVs for file contents blocks, as the existing ways are not appropriate for btrfs. That is the main difficulty we are having. One idea is the one which this patchset is intended to implement. Other ideas that have been brought up involve deriving per-extent keys, using per-block IVs, or using authenticated encryption (or some combination of these). These ideas would be better cryptographically then the one that this patchset actually implements, so it needs to be properly documented why they've been ruled out. (Or maybe they haven't really been ruled out -- I'm not sure they have.) And as I've mentioned, if we do go with the current proposal, which results in some IV reuse, it needs to be decided whether we should try to ameliorate that by hashing part of the IV with a secret key, like IV_INO_LBLK_32 does. Another area where new cryptographic design is needed is the encryption of the fsverity metadata. ext4 and f2fs get encryption of the fsverity metadata "for free" since they store it past EOF, but btrfs doesn't. Anyway, I tried to get Paul's feedback on this patchset, but he (understandingly) didn't want to dig through random mailing list discussions, which don't really have all the information anyway. I think updating the design document to fully reflect the current proposal and the detailed reasoning behind it would be super helpful to get everyone on the right page and to make sure the right design is being chosen. - Eric
I appreciate the conversation happening on the doc; thank ya'll for reading and commenting. Would it be worth having a meeting on Zoom or the like this week to discuss the way forward for getting encryption for btrfs, be that one of the extent-based encryption variations or AEAD? Thanks! Sweet Tea On 11/16/22 15:19, Sweet Tea Dorminy wrote: > > > On 11/3/22 15:22, Paul Crowley wrote: >> Thank you for creating this! I'm told the design document [1] no >> longer reflects the current proposal in these patches. If that's so I >> think it's worth bringing the design document up to date so we can >> review the cryptography. Thanks! >> >> [1] >> https://docs.google.com/document/d/1iNnrqyZqJ2I5nfWKt7cd1T9xwU0iHhjhk9ALQW3XuII/edit > > I apologize for the delay; I realized when this thread was bumped just > now that my attempt to share the updated doc didn't seem to make it to > the mailing list. > > https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing is an update of the design document that hopefully is what you're requesting.
We had a very productive meeting and have greatly changed the design: we now plan to implement authenticated encryption, and have per-extent keys instead of per-extent nonces, which will greatly improve the cryptographic characteristics over this version. Many thanks for the discussion, both in the meeting and on the document. The document has been updated to hopefully reflect the discussion we had; further comments are always appreciated. https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing I look forward to working on implementing the new design; thanks to all! Sweet Tea On 11/21/22 12:26, Sweet Tea Dorminy wrote: > I appreciate the conversation happening on the doc; thank ya'll for > reading and commenting. > > Would it be worth having a meeting on Zoom or the like this week to > discuss the way forward for getting encryption for btrfs, be that one of > the extent-based encryption variations or AEAD? > > Thanks! > > Sweet Tea > > On 11/16/22 15:19, Sweet Tea Dorminy wrote: >> >> >> On 11/3/22 15:22, Paul Crowley wrote: >>> Thank you for creating this! I'm told the design document [1] no >>> longer reflects the current proposal in these patches. If that's so I >>> think it's worth bringing the design document up to date so we can >>> review the cryptography. Thanks! >>> >>> [1] >>> https://docs.google.com/document/d/1iNnrqyZqJ2I5nfWKt7cd1T9xwU0iHhjhk9ALQW3XuII/edit >> >> I apologize for the delay; I realized when this thread was bumped just >> now that my attempt to share the updated doc didn't seem to make it to >> the mailing list. >> >> https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing is an update of the design document that hopefully is what you're requesting.
On Wed, Nov 23, 2022 at 08:22:30PM -0500, Sweet Tea Dorminy wrote: > The document has been updated to hopefully reflect the discussion we had; > further comments are always appreciated. https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing How is this going to work with hardware encryption offload? I think the number of keys for UFS and eMMC inline encryption, but Eric may correct me.
On Sun, Nov 27, 2022 at 11:59:40PM -0800, Christoph Hellwig wrote: > On Wed, Nov 23, 2022 at 08:22:30PM -0500, Sweet Tea Dorminy wrote: > > The document has been updated to hopefully reflect the discussion we had; > > further comments are always appreciated. https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing > > How is this going to work with hardware encryption offload? I think > the number of keys for UFS and eMMC inline encryption, but Eric may > correct me. First, traditional crypto accelerators via the crypto API will work in any case. I think your question is specifically about inline encryption (https://www.kernel.org/doc/html/latest/block/inline-encryption.html). To use inline encryption hardware, consecutive blocks must use consecutive IVs, and the nonzero part of the IVs needs to fit within the hardware's DUN size. That's 64 bits for the UFS standard, and 32 bits for the eMMC standard. fscrypt's "default" setting of per-file keys satisfies both of those requirements. That means the current proposal for btrfs does too, since it's the same as that "default" setting -- just with extents instead of files. (For eMMC, extents would have to be limited to 2^32 blocks.) The other consideration, which seems to be what you're asking about, is a performance one: how well this performs on hardware where switching keys is very expensive. The answer is not very well. Of course, that's the answer for per-file keys too. Note that this is an issue for some inline encryption hardware (e.g. Qualcomm ICE), but not others (e.g. Exynos FMP, Mediatek UFS). The way this problem is "solved" in ext4 and f2fs is by also providing the (less than cryptographically ideal) settings IV_INO_LBLK_64 and IV_INO_LBLK_32. Those squeeze the inode number *and* file offset into a 64-bit or 32-bit IV, so that per-file keys aren't needed. There's a natural mapping of the IV_INO_LBLK_* settings onto extent-based encryption. A 32-bit extent number would just be used instead of an inode number. Or, if a 32-bit extent number is infeasible, an extent nonce of any length hashed with a secret key could be used instead. So yes, it would be possible to provide settings that optimize for hardware like Qualcomm ICE, as ext4 and f2fs do with IV_INO_LBLK_*. However, it makes sense to leave that for later until if/when someone actually has a use case for it. - Eric
The kind of inline encryption hardware we see on Android devices tends to have these limitations: - as you indicate, loading keys can incur latency, so if many keys are in use at once it can slow things down - it's limited to using AES-XTS - on UFS devices, the IV (transmitted in the DUN) must be zero in the 64 high bits - consecutive blocks in the same operation use consecutive IVs - there's no easy way to gather a checksum or MAC over the on-disk ciphertext short of re-reading after writing Android works around this with IV_INO_LBLK_64 policies, but these only work well on the relatively small storage devices we use on Android. In particular the IV limitation is very serious: - inode numbers must be four bytes - they must never change (so ext4 filesystem resizing is disabled) - files cannot be more than 2^32 blocks Things are worse on eMMC devices. Even without this IV limitation, the security proofs for most AES modes of operation start to look shaky as you approach the "birthday bound" of encrypting 2^68 bytes with the same key. If your attack model always assumes a point-in-time attack then you only have to worry if you use a single key to encrypt a multi-exabyte storage device; btrfs is designed to scale to such devices and more. If your attack model includes an attacker who repeatedly gets access to the storage device across time, then writing multiple exabytes with the same key can be a problem even if some of those are overwritten. This leads us to prefer per-extent AES keys (derived from a root key) if possible. It's a shame AES doesn't have a 256-bit blocksize. The way btrfs works also gives us some opportunities to do things a little better. In general disk encryption has to make sacrifices to deal with the limitation that IVs must be reused and there's no room for a MAC. But because btrfs writes in whole extents, with fresh metadata and checksum on each write, it becomes possible to use a fresh IV and MAC for every new write. This opens up the possibility of using an AEAD mode like AES-GCM. This combination gives us the strongest proofs of security even against very generous attack models. Our recommendation: btrfs should first build the ideal thing first since it will have reasonable performance for most users, then later design alternatives that make a few compromises for performance where there is demand. On Sun, 27 Nov 2022 at 23:59, Christoph Hellwig <hch@infradead.org> wrote: > > On Wed, Nov 23, 2022 at 08:22:30PM -0500, Sweet Tea Dorminy wrote: > > The document has been updated to hopefully reflect the discussion we had; > > further comments are always appreciated. https://docs.google.com/document/d/1janjxewlewtVPqctkWOjSa7OhCgB8Gdx7iDaCDQQNZA/edit?usp=sharing > > How is this going to work with hardware encryption offload? I think > the number of keys for UFS and eMMC inline encryption, but Eric may > correct me.