From: Mikulas Patocka <mpatocka@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: dm-devel@redhat.com, linux-crypto@vger.kernel.org
Subject: Re: Desynchronizing dm-raid1
Date: Tue, 13 May 2008 16:35:03 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0805131622120.486@engineering.redhat.com> (raw)
In-Reply-To: <20080513033822.GA9604@gondor.apana.org.au>
On Tue, 13 May 2008, Herbert Xu wrote:
> On Mon, May 12, 2008 at 11:28:44PM -0400, Mikulas Patocka wrote:
>>
>> Or do you thint it would be useless (all major disk-encryption algorithms
>> read input buffer more times?) or it would create too much code
>> complexity?
>
> I'm open to this approach. As long as you do the work and come up
> with the patch that is :)
>
> Cheers,
And where would you propose to place this bit?
One possibility would be struct crypto_tfm->crt_flags
Another possibility is struct crypto_alg->cra_flags
Can chaining mode change the value of the flag? (I presume that yes)
So make a bit in struct crypto_alg. And propagate it to
crypto_alg->cra_flags of chaining modes that read input data only once?
I'm not familiar with Linux crypto API, so the location of the flag should
be selected by someone who knows it well.
Here I'm sending the patch for dm-crypt. To optimize it further, you
should add the test after bio_data_dir(ctx->bio_in) == WRITE test --- i.e.
if the algorithm is safe to read input only once, the smaller and faster
branch can be executed.
Mikukas
---
Copy data when writing to the device.
This patch fixes damaged blocks on encrypted device when the computer crashes.
Linux IO architecture allows the data to be modified while they are being
written.
While we are processing write requests, the data may change, and it is expected,
that each byte written to the device is either old byte or new byte.
Some crypto functions may read the input buffer more than once and so they'll
produce garbage if the buffer changes under them. When this garbage is
read again and decrypted, it may produce damage in all bytes in the block. This
damage is visible only if the computer crashes; if it didn't crash, the memory
manager writes correct buffer or page contents some times later.
So we first copy data to a temporary buffer with memcpy and then encrypt them
in place.
Mikulas Patocka <mpatocka@redhat.com>
---
drivers/md/dm-crypt.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
Index: linux-2.6.25.3/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.25.3.orig/drivers/md/dm-crypt.c 2008-05-13 21:48:32.000000000 +0200
+++ linux-2.6.25.3/drivers/md/dm-crypt.c 2008-05-13 22:14:12.000000000 +0200
@@ -360,8 +360,18 @@ static int crypt_convert_block(struct cr
crypto_ablkcipher_alignmask(cc->tfm) + 1);
sg_init_table(&dmreq->sg_in, 1);
- sg_set_page(&dmreq->sg_in, bv_in->bv_page, 1 << SECTOR_SHIFT,
- bv_in->bv_offset + ctx->offset_in);
+ if (bio_data_dir(ctx->bio_in) == WRITE) {
+ char *page_in = kmap_atomic(bv_in->bv_page, KM_USER0);
+ char *page_out = kmap_atomic(bv_out->bv_page, KM_USER1);
+ memcpy(page_out + bv_out->bv_offset + ctx->offset_out, page_in + bv_in->bv_offset + ctx->offset_in, 1 << SECTOR_SHIFT);
+ kunmap_atomic(page_in, KM_USER0);
+ kunmap_atomic(page_out, KM_USER1);
+
+ sg_set_page(&dmreq->sg_in, bv_out->bv_page, 1 << SECTOR_SHIFT,
+ bv_out->bv_offset + ctx->offset_out);
+ } else
+ sg_set_page(&dmreq->sg_in, bv_in->bv_page, 1 << SECTOR_SHIFT,
+ bv_in->bv_offset + ctx->offset_in);
sg_init_table(&dmreq->sg_out, 1);
sg_set_page(&dmreq->sg_out, bv_out->bv_page, 1 << SECTOR_SHIFT,
next prev parent reply other threads:[~2008-05-13 20:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <47DEC402.10309@redhat.com>
[not found] ` <Pine.LNX.4.64.0803171611430.31803@porkchop.devel.redhat.com>
[not found] ` <20080317215631.GG29322@agk.fab.redhat.com>
[not found] ` <Pine.LNX.4.64.0803181921380.10939@porkchop.devel.redhat.com>
[not found] ` <20080318233955.GA12007@agk.fab.redhat.com>
[not found] ` <Pine.LNX.4.64.0803181942140.20490@porkchop.devel.redhat.com>
[not found] ` <20080319000241.GB12007@agk.fab.redhat.com>
[not found] ` <Pine.LNX.4.64.0803182015001.21077@porkchop.devel.redhat.com>
[not found] ` <20080319011757.GD12007@agk.fab.redhat.com>
[not found] ` <Pine.LNX.4.64.0804021444120.22485@porkchop.devel.redhat.com>
[not found] ` <20080403014042.GA3789@us.ibm.com>
[not found] ` <yq14padoast.fsf@sermon.lab.mkp.net>
2008-05-05 21:45 ` Desynchronizing dm-raid1 Mikulas Patocka
2008-05-06 10:29 ` [dm-devel] " Herbert Xu
2008-05-06 22:50 ` Mikulas Patocka
2008-05-13 3:28 ` Mikulas Patocka
2008-05-13 3:38 ` [dm-devel] " Herbert Xu
2008-05-13 20:35 ` Mikulas Patocka [this message]
2008-05-14 1:14 ` Herbert Xu
2008-05-22 2:18 ` Mikulas Patocka
2008-05-22 2:42 ` [dm-devel] " Herbert Xu
2008-05-22 12:32 ` Mikulas Patocka
2008-05-22 23:53 ` [dm-devel] " Herbert Xu
2008-05-23 14:59 ` Mikulas Patocka
2008-05-24 0:01 ` Herbert Xu
2008-05-24 14:01 ` Mikulas Patocka
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=Pine.LNX.4.64.0805131622120.486@engineering.redhat.com \
--to=mpatocka@redhat.com \
--cc=dm-devel@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox