[PATCH] dm-crypt: zero key before freeing it
authorStefan Rompf <stefan@loplof.de>
Fri, 6 Jan 2006 08:20:08 +0000 (00:20 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 6 Jan 2006 16:34:01 +0000 (08:34 -0800)
Zap the memory before freeing it so we don't leave crypto information
around in memory.

Signed-off-by: Stefan Rompf <stefan@loplof.de>
Acked-by: Clemens Fruhwirth <clemens@endorphin.org>
Acked-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/md/dm-crypt.c

index cf6631056683b76cc3abbf2afa0a9564261de5f5..a601a427885cb0e97afa15449b89c9347e2b3b7a 100644 (file)
@@ -690,6 +690,8 @@ bad3:
 bad2:
        crypto_free_tfm(tfm);
 bad1:
+       /* Must zero key material before freeing */
+       memset(cc, 0, sizeof(*cc) + cc->key_size * sizeof(u8));
        kfree(cc);
        return -EINVAL;
 }
@@ -706,6 +708,9 @@ static void crypt_dtr(struct dm_target *ti)
                cc->iv_gen_ops->dtr(cc);
        crypto_free_tfm(cc->tfm);
        dm_put_device(ti, cc->dev);
+
+       /* Must zero key material before freeing */
+       memset(cc, 0, sizeof(*cc) + cc->key_size * sizeof(u8));
        kfree(cc);
 }