diff mbox series

[4/5] dm-crypt: don't modify the data when using authenticated encryption

Message ID c0fb19b6-8ff9-99b1-e9fe-2e86abf33dd7@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show
Series dm-integrity, dm-verity and dm-crypt recheck patches | expand

Commit Message

Mikulas Patocka Feb. 19, 2024, 8:30 p.m. UTC
It was said that authenticated encryption could produce invalid tag when
the data that is being encrypted is modified [1]. So, fix this problem by
copying the data into the clone bio first and then encrypt them inside the
clone bio.

This may reduce performance, but it is needed to prevent the user from
corrupting the device by writing data with O_DIRECT and modifying them at
the same time.

[1] https://lore.kernel.org/all/20240207004723.GA35324@sol.localdomain/T/

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 drivers/md/dm-crypt.c |    6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

Index: linux-2.6/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-crypt.c	2024-02-05 10:58:03.000000000 +0100
+++ linux-2.6/drivers/md/dm-crypt.c	2024-02-08 14:50:08.000000000 +0100
@@ -2071,6 +2071,12 @@  static void kcryptd_crypt_write_convert(
 	io->ctx.bio_out = clone;
 	io->ctx.iter_out = clone->bi_iter;
 
+	if (crypt_integrity_aead(cc)) {
+		bio_copy_data(clone, io->base_bio);
+		io->ctx.bio_in = clone;
+		io->ctx.iter_in = clone->bi_iter;
+	}
+
 	sector += bio_sectors(clone);
 
 	crypt_inc_pending(io);