dm-verity: remove support for asynchronous hashes
PATCH v2 1/1 dm-verity: remove support for asynchronous hashes
The support for asynchronous hashes in dm-verity has outlived its usefulness. It adds significant code complexity and opportunity for bugs. I don't know of anyone using it in practice. (The original submitter of the code possibly was, but that was 8 years ago.) Data I recently collected for en/decryption shows that using off-CPU crypto "accelerators" is consistently much slower than the CPU
(https://lore.kernel.org/r/[email protected]/),
even on CPUs that lack dedicated cryptographic instructions. Similar results are likely to be seen for hashing.
I already removed support for asynchronous hashes from fsverity two years ago, and no one ever complained.
Moreover, neither dm-verity, fsverity, nor fscrypt has ever actually used the asynchronous crypto algorithms in a truly asynchronous manner. The lack of interest in such optimizations provides further evidence that it's only the CPU-based crypto that actually matters.
Historically, it's also been common for people to forget to enable the optimized SHA-256 code, which could contribute to an off-CPU crypto engine being perceived as more useful than it really is. In 6.16 I fixed that: the optimized SHA-256 code is now enabled by default.
Therefore, let's drop the support for asynchronous hashes in dm-verity.
Tested with verity-compat-test.
---
Changed in v2:
- Removed the now-unused 'may_sleep' parameter from verity_hash()
- Fixed a typo in commit message
- Added comment in verity_setup_salt_and_hashstate()
- Keep SHASH_DESC_ON_STACK in existing place in verity_setup_salt_and_hashstate(), to reduce the diff slightly
- Added Ard's Acked-by
drivers/md/dm-verity-fec.c | 4 +- drivers/md/dm-verity-target.c | 183 ++++++---------------------------- drivers/md/dm-verity.h | 22 ++-- 3 files changed, 37 insertions(+), 172 deletions(-)
drivers/md/dm-verity-fec.c +2 -2
@@ -189,11 +189,11 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_io *io,*/ static int fec_is_erasure (struct dm_verity *v,struct dm_verity_io *io,u8 *want_digest,u8 *data) {if (unlikely (verity_hash (v, io, data,1 << v->data_dev_block_bits, -verity_io_real_digest (v, io), true))) +verity_io_real_digest (v, io))))return 0 ;return memcmp (verity_io_real_digest (v, io), want_digest, v->digest_size) !=0 ; }
@@ -390,11 +390,11 @@ static int fec_decode_rsb(struct dm_verity *v, struct dm_verity_io *io, pos += fio->nbufs <<DM_VERITY_FEC_BUF_RS_BITS ; }/* Always re-validate the corrected block against the expected hash */ r =verity_hash (v, io, fio->output,1 << v->data_dev_block_bits, -verity_io_real_digest (v, io), true); +verity_io_real_digest (v, io));if (unlikely (r <0 ))return r;if (memcmp (verity_io_real_digest (v, io),verity_io_want_digest (v, io), v->digest_size)) {
drivers/md/dm-verity-target.c +28 -155
327 lines not on this page · raw message
drivers/md/dm-verity.h +7 -15
@@ -37,15 +37,14 @@ struct dm_verity {struct dm_dev *data_dev;struct dm_dev *hash_dev;struct dm_target *ti;struct dm_bufio_client *bufio;char *alg_name; -struct crypto_ahash *ahash_tfm;/* either this or shash_tfm is set */ -struct crypto_shash *shash_tfm;/* either this or ahash_tfm is set */ +struct crypto_shash *shash_tfm;u8 *root_digest;/* digest of the root block */ u8 *salt;/* salt: its size is salt_size */ -u8 *initial_hashstate;/* salted initial state, if shash_tfm is set */ +u8 *initial_hashstate;/* salted initial state, if version >= 1 */ u8 *zero_digest;/* digest for a zero block */ #ifdef CONFIG_SECURITY u8 *root_digest_sig;/* signature of the root digest */ unsigned int sig_size;/* root digest signature size */ #endif /* CONFIG_SECURITY */
@@ -59,11 +58,10 @@ struct dm_verity {unsigned char levels;/* the number of tree levels */ unsigned char version; bool hash_failed:1; /* set if hash of any block failed */ bool use_bh_wq:1; /* try to verify in BH wq before normal work-queue */unsigned int digest_size;/* digest size for the current hash algorithm */ -unsigned int hash_reqsize;/* the size of temporary space for crypto */ enum verity_mode mode;/* mode for handling verification errors */ enum verity_mode error_mode;/* mode for handling I/O errors */ unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ struct workqueue_struct *verify_wq;
@@ -98,23 +96,17 @@ struct dm_verity_io {u8 real_digest[HASH_MAX_DIGESTSIZE ];u8 want_digest[HASH_MAX_DIGESTSIZE ];/* -* This struct is followed by a variable-sized hash request of size -* v->hash_reqsize, either a struct ahash_request or a struct shash_desc -* (depending on whether ahash_tfm or shash_tfm is being used). To -* access it, use verity_io_hash_req(). +* Temporary space for hashing. This is variable-length and must be at +* the end of the struct. struct shash_desc is just the fixed part; +* it's followed by a context of size crypto_shash_descsize(shash_tfm). */ +struct shash_desc hash_desc; }; -static inline void *verity_io_hash_req (struct dm_verity *v, -struct dm_verity_io *io) -{ -return io +1 ; -} -static inline u8 *verity_io_real_digest (struct dm_verity *v,struct dm_verity_io *io) {return io->real_digest; }
@@ -124,11 +116,11 @@ static inline u8 *verity_io_want_digest(struct dm_verity *v, {return io->want_digest; }extern int verity_hash (struct dm_verity *v,struct dm_verity_io *io, -const u8 *data,size_t len,u8 *digest,bool may_sleep); +const u8 *data,size_t len,u8 *digest);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);
base-commit: 846e9e999dd36ce5898d302d674e441e72c3a8cf
Signature · 1 line
2.50.1
Quoted 18 lines · Eric Biggers
The support for asynchronous hashes in dm-verity has outlived its usefulness. It adds significant code complexity and opportunity for bugs. I don't know of anyone using it in practice. (The original submitter of the code possibly was, but that was 8 years ago.) Data I recently collected for en/decryption shows that using off-CPU crypto "accelerators" is consistently much slower than the CPU
(https://lore.kernel.org/r/[email protected]/),
even on CPUs that lack dedicated cryptographic instructions. Similar results are likely to be seen for hashing.I already removed support for asynchronous hashes from fsverity two years ago, and no one ever complained.
Moreover, neither dm-verity, fsverity, nor fscrypt has ever actually used the asynchronous crypto algorithms in a truly asynchronous manner. The lack of interest in such optimizations provides further evidence that it's only the CPU-based crypto that actually matters.
Quoted 8 lines
Historically, it's also been common for people to forget to enable the optimized SHA-256 code, which could contribute to an off-CPU crypto engine being perceived as more useful than it really is. In 6.16 I fixed that: the optimized SHA-256 code is now enabled by default.
Therefore, let's drop the support for asynchronous hashes in dm-verity.
Tested with verity-compat-test.
Hi,
I shortly tested it with veritysetup too, also on 32bit.
And I like this patch (I wish we can remove the async thing from the dmcrypt too...)
Just one nitpick - could you please increase minor version of dm-verity target, so we have information in debug log that it is a patched version?
Thanks,
Milan
Quoted 17 lines
Acked-by Ard Biesheuvel <[email protected]>Signed-off-by Eric Biggers <[email protected]>---
Changed in v2:
- Removed the now-unused 'may_sleep' parameter fromverity_hash()
- Fixed a typo in commit message
- Added comment inverity_setup_salt_and_hashstate()
- KeepSHASH_DESC_ON_STACKin existing place inverity_setup_salt_and_hashstate(), to reduce the diff slightly
- Added Ard's Acked-bydrivers/md/dm-verity-fec.c | 4 +- drivers/md/dm-verity-target.c | 183 ++++++---------------------------- drivers/md/dm-verity.h | 22 ++-- 3 files changed, 37 insertions(+), 172 deletions(-)
Quoted 3 lines · Milan Broz
Just one nitpick - could you please increase minor version of dm- verity target, so we have information in debug log that it is a patched version?
Others are convinced that version numbers have no place in the upstream kernel and that all version information should be removed from upstream kernel drivers.
Thanks,
Bart.
Quoted 7 lines · Bart Van Assche
Quoted 3 lines · Milan Broz
Just one nitpick - could you please increase minor version of dm- verity target, so we have information in debug log that it is a patched version?
Others are convinced that version numbers have no place in the upstream kernel and that all version information should be removed from upstream kernel drivers.
As long as it's there, we might as well update it. But yes, the device-mapper version numbers don't work all that well.
- Eric
Quoted 24 lines · Milan Broz
Quoted 23 lines · Eric Biggers
The support for asynchronous hashes in dm-verity has outlived its usefulness. It adds significant code complexity and opportunity for bugs. I don't know of anyone using it in practice. (The original submitter of the code possibly was, but that was 8 years ago.) Data I recently collected for en/decryption shows that using off-CPU crypto "accelerators" is consistently much slower than the CPU
(https://lore.kernel.org/r/[email protected]/),
even on CPUs that lack dedicated cryptographic instructions. Similar results are likely to be seen for hashing.I already removed support for asynchronous hashes from fsverity two years ago, and no one ever complained.
Moreover, neither dm-verity, fsverity, nor fscrypt has ever actually used the asynchronous crypto algorithms in a truly asynchronous manner. The lack of interest in such optimizations provides further evidence that it's only the CPU-based crypto that actually matters.
Historically, it's also been common for people to forget to enable the optimized SHA-256 code, which could contribute to an off-CPU crypto engine being perceived as more useful than it really is. In 6.16 I fixed that: the optimized SHA-256 code is now enabled by default.
Quoted 8 lines
Quoted 3 lines
Therefore, let's drop the support for asynchronous hashes in dm-verity.
Tested with verity-compat-test.
Hi,
I shortly tested it with veritysetup too, also on 32bit.
And I like this patch (I wish we can remove the async thing from the dmcrypt too...)
IMO we should do it for dm-crypt too, though it's going to be a slightly tougher sell there because it actually goes through the trouble of using the async API "properly".
- Eric
Quoted 7 lines · Bart Van Assche
Quoted 3 lines · Milan Broz
Just one nitpick - could you please increase minor version of dm- verity target, so we have information in debug log that it is a patched version?
Others are convinced that version numbers have no place in the upstream kernel and that all version information should be removed from upstream kernel drivers.
Others are convinced that this information from the log is very useful, which is why we report all versions as the first step in cryptsetup tests.
This says nothing about detecting the availability of certain functions - that is done by just trying the ioctl.
That was the discussion you are probably referring to.
I understand what you are saying, but device-mapper was constructed with some logic that allows many variants of mapping table parameters and reporting version is very useful to reproduce compatibility issues. It saved me a lot of time.
Thanks,
Milan
Quoted 2 lines · Milan Broz
Just one nitpick - could you please increase minor version of dm-verity target, so we have information in debug log that it is a patched version?
I see this is already in linux-dm/for-next with the version updated from {1, 11, 0} to {1, 12, 0}. So I won't bother sending a v3 with just that change. Thanks!
- Eric
Quoted 29 lines · Eric Biggers
Quoted 28 lines · Milan Broz
Quoted 26 lines · Eric Biggers
The support for asynchronous hashes in dm-verity has outlived its usefulness. It adds significant code complexity and opportunity for bugs. I don't know of anyone using it in practice. (The original submitter of the code possibly was, but that was 8 years ago.) Data I recently collected for en/decryption shows that using off-CPU crypto "accelerators" is consistently much slower than the CPU
(https://lore.kernel.org/r/[email protected]/),
even on CPUs that lack dedicated cryptographic instructions. Similar results are likely to be seen for hashing.I already removed support for asynchronous hashes from fsverity two years ago, and no one ever complained.
Moreover, neither dm-verity, fsverity, nor fscrypt has ever actually used the asynchronous crypto algorithms in a truly asynchronous manner. The lack of interest in such optimizations provides further evidence that it's only the CPU-based crypto that actually matters.
Historically, it's also been common for people to forget to enable the optimized SHA-256 code, which could contribute to an off-CPU crypto engine being perceived as more useful than it really is. In 6.16 I fixed that: the optimized SHA-256 code is now enabled by default.
Therefore, let's drop the support for asynchronous hashes in dm-verity.
Tested with verity-compat-test.
Quoted 8 lines
Quoted 4 lines
Hi,
I shortly tested it with veritysetup too, also on 32bit.
And I like this patch (I wish we can remove the async thing from the dmcrypt too...)IMO we should do it for dm-crypt too, though it's going to be a slightly tougher sell there because it actually goes through the trouble of using the async API "properly".
We tested async by replacing dm-crypt/dm-verity arg with cryptd(%s-generic). Nice, if it really works, but... I think it is time to simplify it.
Thanks,
Milan