All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fruhwirth Clemens <clemens-dated-1056963973.bf26@endorphin.org>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Initial Vector Fix for loop.c.
Date: Fri, 20 Jun 2003 11:06:12 +0200	[thread overview]
Message-ID: <20030620090612.GA1322@ghanima.endorphin.org> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2022 bytes --]

Meta information: 

This mail proposes a fix for: 
must-fix list item "drivers/block/loop.c" and
should-fix list item "drivers/block/cryptoloop"

Content:

loop.c is broken. It's broken since 2.4. In particular the initial vector
calculation which every cryptographic loop transformation uses is broken.

What's the problem you might ask.. It's that that the IV calculation is
based on the logical block sector of the block device. Just think of what
happends if you move your image to another device with a different block
size..

Correct! The IV metric changes and everyone who knows what's CBC
encryption will correctly conclude: you can't read your image. 

That's bad. And that's the reason why every project which provides you with
encryption via loop.c will also provide you with a patch for this broken
loop.c behavior. 

The fix is quite simple. Just switch to a fixed IV metric. Which is: the
smallest granulity -> fixed 512-byte and kerneli.org's cryptoloop as well as
Jari's loop-AES do exactly that.

These two packages are the only facilities I'm aware of that provides
harddisc encryption for the 2.4. kernel. However marcello refused to switch
the IV metric for 2.4. because it will - yes that's correct - break any
image which has been created with a IV-sensitiv loop transformation..

..BUT except for cryptoloop and loop-AES there are no such loop
transformation modules! And those two projects have already fixed this
issue. So we're providing backward compatiblity for nothing here. No user
base could ever benefit from this backward compatiblity, since the only
reason the initial vector calculation is done is for crypto and every crypto
project out there already uses the 512-byte IV-metric.

So go for it. Fix it before 2.6.x is out and we're stuck with this crap
again. 

http://bugzilla.kernel.org/show_bug.cgi?id=192

Just apply the patch. 

If this bug is fixed, we can go ahead and add cryptoloop which is ready and
tested.

Regards, Clemens

[-- Attachment #1.2: loop-clemens-2.5.70.diff --]
[-- Type: text/plain, Size: 1681 bytes --]

--- drivers/block/loop.c.orig	Fri Jun 20 11:02:10 2003
+++ drivers/block/loop.c	Fri Jun 20 11:02:49 2003
@@ -79,6 +79,8 @@
 
 #include <asm/uaccess.h>
 
+#define LOOP_IV_SECTOR_BITS 9
+
 static int max_loop = 8;
 static struct loop_device *loop_dev;
 static struct gendisk **disks;
@@ -196,7 +198,7 @@
 	data = kmap(bvec->bv_page) + bvec->bv_offset;
 	len = bvec->bv_len;
 	while (len > 0) {
-		sector_t IV = index * (PAGE_CACHE_SIZE/bsize) + offset/bsize;
+		sector_t IV = (index << (PAGE_CACHE_SHIFT - LOOP_IV_SECTOR_BITS)) + (offset >> LOOP_IV_SECTOR_BITS);
 		int transfer_result;
 
 		size = PAGE_CACHE_SIZE - offset;
@@ -279,7 +281,7 @@
 	unsigned long count = desc->count;
 	struct lo_read_data *p = (struct lo_read_data*)desc->buf;
 	struct loop_device *lo = p->lo;
-	int IV = page->index * (PAGE_CACHE_SIZE/p->bsize) + offset/p->bsize;
+	int IV =  (page->index << (PAGE_CACHE_SHIFT - LOOP_IV_SECTOR_BITS)) + (offset >> LOOP_IV_SECTOR_BITS);
 
 	if (size > count)
 		size = count;
@@ -484,7 +486,7 @@
 bio_transfer(struct loop_device *lo, struct bio *to_bio,
 			      struct bio *from_bio)
 {
-	unsigned long IV = loop_get_iv(lo, from_bio->bi_sector);
+	unsigned long IV = from_bio->bi_sector + (lo->lo_offset >> LOOP_IV_SECTOR_BITS);
 	struct bio_vec *from_bvec, *to_bvec;
 	char *vto, *vfrom;
 	int ret = 0, i;
@@ -545,7 +547,7 @@
 	 * piggy old buffer on original, and submit for I/O
 	 */
 	new_bio = loop_get_buffer(lo, old_bio);
-	IV = loop_get_iv(lo, old_bio->bi_sector);
+	IV = old_bio->bi_sector + (lo->lo_offset >> LOOP_IV_SECTOR_BITS);
 	if (rw == WRITE) {
 		if (bio_transfer(lo, new_bio, old_bio))
 			goto err;

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

             reply	other threads:[~2003-06-20  8:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-20  9:06 Fruhwirth Clemens [this message]
2003-06-20  9:23 ` [PATCH] Initial Vector Fix for loop.c Andrew Morton
     [not found] <20030620090612.GA1322@ghanima.endorphin.org.suse.lists.linux.kernel>
2003-06-20  9:30 ` Andi Kleen
2003-06-20 10:14   ` Fruhwirth Clemens
2003-06-20 10:24     ` Andi Kleen
2003-06-20 10:33       ` Fruhwirth Clemens
2003-06-20 10:35       ` Jörn Engel
2003-06-20 10:49         ` Andi Kleen
2003-06-20 10:52           ` Andi Kleen
2003-06-20 11:15           ` Fruhwirth Clemens
2003-06-20 10:51         ` Fruhwirth Clemens
2003-06-20 11:03           ` Jörn Engel
2003-06-21  2:18           ` Jan Rychter
2003-06-24 18:22       ` Bill Davidsen
2003-06-20 17:56   ` Andrew Morton
2003-06-20 18:14     ` David S. Miller
2003-06-20 19:04       ` Andries Brouwer
  -- strict thread matches above, loose matches on Subject: below --
2003-06-20 13:38 Fruhwirth Clemens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030620090612.GA1322@ghanima.endorphin.org \
    --to=clemens-dated-1056963973.bf26@endorphin.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.