From patchwork Thu Jul 4 13:10:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 11031499 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F46C112C for ; Thu, 4 Jul 2019 13:14:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EB6F28A6D for ; Thu, 4 Jul 2019 13:14:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 535A828A91; Thu, 4 Jul 2019 13:14:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56E5328A6D for ; Thu, 4 Jul 2019 13:14:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91D9F30C585A; Thu, 4 Jul 2019 13:14:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AECD8429E; Thu, 4 Jul 2019 13:14:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BC04441F53; Thu, 4 Jul 2019 13:14:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x64DCLBP028673 for ; Thu, 4 Jul 2019 09:12:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id DFE9018B93; Thu, 4 Jul 2019 13:12:21 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D95DD968C4 for ; Thu, 4 Jul 2019 13:12:19 +0000 (UTC) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BF1C3082E51 for ; Thu, 4 Jul 2019 13:12:03 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id f9so6570902wre.12 for ; Thu, 04 Jul 2019 06:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eUtaMzTNP5KxTFEx4foexwTrUTVbqa8AryQmg0468gg=; b=pRxfZU0yv0Nij9aKgoZrg1B9m0o7vBolDGzL1ArroTSL5CLo+FMGQkR5sgliwArU3k th3jtvASN5P12/NIyayPm1R9iTILouqyJdaos3KgfomuEA8ZO4yr/MDxnq/KleD3b3oY sAoTsvxzZpz1JHn4bDVZ4rzEq61M/QA4eCvWTrWgtbU4YILiDydSFKbr9hOYyk/eVpfH L0jplq5CGG7H4OZrBOaLJjZ09NDpnprDN9h7yi4mRLV9Qtn9uevyYqllymmXI3RsaEaa ArMdgdcFCVPTx4Tlqh20haAtuogn9TO1BUkE51U6EiKwNGaUJJjOsIZ+KVmOD1XPX/sE U/kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eUtaMzTNP5KxTFEx4foexwTrUTVbqa8AryQmg0468gg=; b=dIPznUGpF+1j/aYp9JJoCOatMBI3u51rHVGR5TfA8kVTDvyrwq30kp2QBr+QeKomzL 8YDW7U482tjpjuQUrtvyuCTLp57Ohnxi1NdKtiVuu34NnZdbVa2WdIaS3yaNACzu8Ojt zd5ID1ZbzpU6UU6ljhmYk2D6UdtXkPbb8OC/0a2qNBRjY9LehH+9KvO20UIR2exrX7N9 WTVpunlXp9eE+ZtWW1yTgennuNcDaWOty2Ei8G7hamYfLaWJEP8+5Q3+fctycFHZOUJY 9fhK1JmXG2V4pdcvjUQWe65w01fFB0ZP2D0BgicfUUwzpdHkTfuqIYJCWcFygEEua9Y2 ingg== X-Gm-Message-State: APjAAAUoFm9QzQ10tRzW0STTGuNpuCZ9ULqp5q3Qv5/V/LDRL5GEAcxa utzvNRzww3r85sQ65rVAvMN46oI+8Mw= X-Google-Smtp-Source: APXvYqyipRxgHHyCm89WuC/nzl7vvHceHJpkePxPJ2+KJMpLzQpW7MG8/6Fpozc4zWf2/IFLV75btA== X-Received: by 2002:adf:dfc5:: with SMTP id q5mr36011015wrn.142.1562245921756; Thu, 04 Jul 2019 06:12:01 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id u6sm1844555wrw.15.2019.07.04.06.12.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 06:12:01 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Thu, 4 Jul 2019 15:10:31 +0200 Message-Id: <20190704131033.9919-1-gmazyland@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 04 Jul 2019 13:12:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 04 Jul 2019 13:12:03 +0000 (UTC) for IP:'209.85.221.68' DOMAIN:'mail-wr1-f68.google.com' HELO:'mail-wr1-f68.google.com' FROM:'gmazyland@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.089 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, T_PDS_NO_HELO_DNS) 209.85.221.68 mail-wr1-f68.google.com 209.85.221.68 mail-wr1-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Thu, 04 Jul 2019 09:14:39 -0400 Cc: Milan Broz Subject: [dm-devel] [PATCH 1/3] dm-crypt: Wipe private IV struct after key invalid flag is set. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 04 Jul 2019 13:14:46 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP If a private IV wipe function fails, the code does not set the key invalid flag. This patch moves code after the flag is set and prevents the device resume in an inconsistent state. Also, it allows using of a randomized key in private wipe function (to be used later patches). Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 1b16d34bb785..c6d41a7e89c9 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -2158,6 +2158,14 @@ static int crypt_wipe_key(struct crypt_config *cc) clear_bit(DM_CRYPT_KEY_VALID, &cc->flags); get_random_bytes(&cc->key, cc->key_size); + + /* Wipe IV private keys */ + if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) { + r = cc->iv_gen_ops->wipe(cc); + if (r) + return r; + } + kzfree(cc->key_string); cc->key_string = NULL; r = crypt_setkey(cc); @@ -3050,14 +3058,8 @@ static int crypt_message(struct dm_target *ti, unsigned argc, char **argv, memset(cc->key, 0, cc->key_size * sizeof(u8)); return ret; } - if (argc == 2 && !strcasecmp(argv[1], "wipe")) { - if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) { - ret = cc->iv_gen_ops->wipe(cc); - if (ret) - return ret; - } + if (argc == 2 && !strcasecmp(argv[1], "wipe")) return crypt_wipe_key(cc); - } } error: From patchwork Thu Jul 4 13:10:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 11031493 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E41D214C0 for ; Thu, 4 Jul 2019 13:13:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D389028A4B for ; Thu, 4 Jul 2019 13:13:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C776928A97; Thu, 4 Jul 2019 13:13:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3C8BB28A4B for ; Thu, 4 Jul 2019 13:13:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0D0C30BC591; Thu, 4 Jul 2019 13:13:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0ACD284284; Thu, 4 Jul 2019 13:13:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D330118433A1; Thu, 4 Jul 2019 13:13:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x64DCN7C028707 for ; Thu, 4 Jul 2019 09:12:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0FD2B5D71B; Thu, 4 Jul 2019 13:12:23 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B21D17C21 for ; Thu, 4 Jul 2019 13:12:20 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 243F02F8BC4 for ; Thu, 4 Jul 2019 13:12:04 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id a10so5497808wrp.9 for ; Thu, 04 Jul 2019 06:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BX9lj6z8e1utzuyj8zOVNBuApmTW0qRrpYki7ieh5MQ=; b=NLCeOuy160Po9a+89z5EDwH7VKiOrmsDFWDXRaQ6f8kqFzSo5APvIto2MnUO8NugHs Ix+NC8BqKiRI8IlXl3JEQZXWSzWvbjQ6TRC4BCLSxmijCWdXX3Jyb8tNowL6/LMfpWTG SQjw9Enc4nm0wvjPh8AepZaToRWUAvD7IoNrrto296w7DXvySjqnKiEq7jey3lpMIgSz mCr/etjoIoRCqfiP3hwNNZUHsZKEnn2MARfNR5TA2GDbqYZii46oc62DXVZ87iOi6jJn ZuD8U0fSUDN5Nbad/sYVfltEcV4K03uGIfsTs9eKH/6EyQBnPlvToh2XlfGYnDf/dQfq dSTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BX9lj6z8e1utzuyj8zOVNBuApmTW0qRrpYki7ieh5MQ=; b=R+vom/Mx4Hl+lPJFAi8LS3tuCe8LTcR2ufblFXsT0jCRbynUw/3CAMwRAq0UbG8KLf DnpEPmy/SZK6Q6GwO3A+k2xRjj3WWgfr9pGxtiTV7nPZQJY+dCSP5+nBK7RKqI5FSxT6 6EbqbfuAETioxXXmIdouAWsgk5Xfmo/twKrE9etGEvzvIzyh3I3AUvTVUnAxcGk8osu/ a1/5zwBZIe6kR0nyZZYe5hCw0AJiMZRRQhu0TnDf+ZKKfGdKJRB8zOL4UfbSlX/ke+aK xFbplFbVKRM6oz9lYeuhdw2xUGIrhHFsg9Ln8yjfR1offZqddGsvIEuM3STe3I6mdxy5 AKdQ== X-Gm-Message-State: APjAAAX73UiMzjEX8aWiULonEAkvxdagHPQcCyHfyeAtVzhjAfHi4t05 zcv1CfVd1zuqPHmF95+69Mmv9DYZwt0= X-Google-Smtp-Source: APXvYqxIo6C+noW8VqzS+ZpUPQ9gb5roIUOIdFVJl3XJdNMVIzHBhmCF2XvsB3nyrlcslffSZy5MgQ== X-Received: by 2002:adf:e3cc:: with SMTP id k12mr16168303wrm.284.1562245922551; Thu, 04 Jul 2019 06:12:02 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id u6sm1844555wrw.15.2019.07.04.06.12.01 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 06:12:01 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Thu, 4 Jul 2019 15:10:32 +0200 Message-Id: <20190704131033.9919-2-gmazyland@gmail.com> In-Reply-To: <20190704131033.9919-1-gmazyland@gmail.com> References: <20190704131033.9919-1-gmazyland@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 04 Jul 2019 13:12:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 04 Jul 2019 13:12:04 +0000 (UTC) for IP:'209.85.221.65' DOMAIN:'mail-wr1-f65.google.com' HELO:'mail-wr1-f65.google.com' FROM:'gmazyland@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.089 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, T_PDS_NO_HELO_DNS) 209.85.221.65 mail-wr1-f65.google.com 209.85.221.65 mail-wr1-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Milan Broz Subject: [dm-devel] [PATCH 2/3] dm-crypt: Remove obsolete comment about plumb IV. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 04 Jul 2019 13:13:35 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The URL is no longer valid and the comment is obsolete anyway (the plumb IV was never used). Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index c6d41a7e89c9..96ead4492787 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -290,9 +290,6 @@ static struct crypto_aead *any_tfm_aead(struct crypt_config *cc) * is calculated from initial key, sector number and mixed using CRC32. * Note that this encryption scheme is vulnerable to watermarking attacks * and should be used for old compatible containers access only. - * - * plumb: unimplemented, see: - * http://article.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/454 */ static int crypt_iv_plain_gen(struct crypt_config *cc, u8 *iv, From patchwork Thu Jul 4 13:10:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 11031491 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14AC2112C for ; Thu, 4 Jul 2019 13:13:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 038E828A4B for ; Thu, 4 Jul 2019 13:13:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBB4828A8F; Thu, 4 Jul 2019 13:13:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A21528A8C for ; Thu, 4 Jul 2019 13:13:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 287402F8BEA; Thu, 4 Jul 2019 13:13:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E12AC968AC; Thu, 4 Jul 2019 13:13:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4C16754D3D; Thu, 4 Jul 2019 13:13:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x64DCJ8P028607 for ; Thu, 4 Jul 2019 09:12:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1621286BBC; Thu, 4 Jul 2019 13:12:19 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0FAB5891A7 for ; Thu, 4 Jul 2019 13:12:16 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EED19308FC4E for ; Thu, 4 Jul 2019 13:12:04 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id c27so6623742wrb.2 for ; Thu, 04 Jul 2019 06:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j9ZgjohFzAaYD7yrF8N/LTC6X+yDRv1YytjPRhSO5cw=; b=m2gH37pxx/ZbWWZ0iM0ZIMD5bLhbg58fVue120H/r2/bCRoy4LCYR/Xqbmm7QRcm8l QHUt0GzDX758cu1ALkfB8oLfpsrz6W//iBrf80UjTJtv12cxfSLw5vjZy/VCJeAMYq24 BLmEuaTnSREHqfHV8A6ZGnaw6ir1k8ZCT1GT2IZfFs18LtZlv8Y7w1XcMeQlcVK/GDIF sXTR3hVOy7/2jfxQG86hYft146xzo/6Dmix81ETYXCZmgOIzuidrbnbmbROV43KbnI8T /XNT3fTkbM2nmRaWiKptCStumSO1W/0xF0kKFvE0GKV8/p6fw3dRiWFSVVE4Bi1U+lwt 6NJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j9ZgjohFzAaYD7yrF8N/LTC6X+yDRv1YytjPRhSO5cw=; b=dEy+ro3o+zKmGVFhesVUVbJjjO4tNLtAbckV2rWvI0/nlJHDpm8VJ3u6J2sXE7Tdj7 LoWUkWK9/OU8f6eRHcpg/VsPiZSIGdOTwrwHNbIuVDKIyos7mPpbzgSwffLFfc5ZCtnb gT7FUYjk+vYQVquFWcG7UCCFBzWF7NHEara/OWm794VVS/df6Xadv3MOLmXGh7XEkOXX kGC0IKudlzyB95XLTYYUS8aIlmyoEH6877q9nZeeCjMXjTuoTL76mPwd+I/0kNjh283L JGaViwpk9XBGJrQzlzP8D+45NlHPNwcxXMDuQhHL4T8N2cyHamHm8V1pcftvdc5qs0QQ URGg== X-Gm-Message-State: APjAAAXDNVKID3912f6CX7Ahbhs/f/1ys6+JbPZnl6pGa5/zKxtJRZmY HwsO1QDoj1+6+uwsH52yFnBwRCw9tKw= X-Google-Smtp-Source: APXvYqy8o/3SMKKQJ7WU3DsNZ2+750IbHfu1hRh0mEVsWsEH7N2TJ5yTLamUF68XvlX6TlIOkccgHw== X-Received: by 2002:adf:e28a:: with SMTP id v10mr16290499wri.178.1562245923390; Thu, 04 Jul 2019 06:12:03 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id u6sm1844555wrw.15.2019.07.04.06.12.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 06:12:02 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Thu, 4 Jul 2019 15:10:33 +0200 Message-Id: <20190704131033.9919-3-gmazyland@gmail.com> In-Reply-To: <20190704131033.9919-1-gmazyland@gmail.com> References: <20190704131033.9919-1-gmazyland@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 04 Jul 2019 13:12:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 04 Jul 2019 13:12:05 +0000 (UTC) for IP:'209.85.221.65' DOMAIN:'mail-wr1-f65.google.com' HELO:'mail-wr1-f65.google.com' FROM:'gmazyland@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.089 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, T_PDS_NO_HELO_DNS) 209.85.221.65 mail-wr1-f65.google.com 209.85.221.65 mail-wr1-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: Milan Broz Subject: [dm-devel] [PATCH 3/3] dm-crypt: Implement eboiv - encrypted byte-offset initialization vector. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 04 Jul 2019 13:13:35 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This IV is used in some BitLocker devices with CBC encryption mode. NOTE: maybe we need to use another crypto API if the bare cipher API is going to be deprecated. Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 82 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 96ead4492787..a5ffa1ac6a28 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -120,6 +120,10 @@ struct iv_tcw_private { u8 *whitening; }; +struct iv_eboiv_private { + struct crypto_cipher *tfm; +}; + /* * Crypt: maps a linear range of a block device * and encrypts / decrypts at the same time. @@ -159,6 +163,7 @@ struct crypt_config { struct iv_benbi_private benbi; struct iv_lmk_private lmk; struct iv_tcw_private tcw; + struct iv_eboiv_private eboiv; } iv_gen_private; u64 iv_offset; unsigned int iv_size; @@ -290,6 +295,10 @@ static struct crypto_aead *any_tfm_aead(struct crypt_config *cc) * is calculated from initial key, sector number and mixed using CRC32. * Note that this encryption scheme is vulnerable to watermarking attacks * and should be used for old compatible containers access only. + * + * eboiv: Encrypted byte-offset IV (used in Bitlocker in CBC mode) + * The IV is encrypted little-endian byte-offset (with the same key + * and cipher as the volume). */ static int crypt_iv_plain_gen(struct crypt_config *cc, u8 *iv, @@ -838,6 +847,67 @@ static int crypt_iv_random_gen(struct crypt_config *cc, u8 *iv, return 0; } +static void crypt_iv_eboiv_dtr(struct crypt_config *cc) +{ + struct iv_eboiv_private *eboiv = &cc->iv_gen_private.eboiv; + + crypto_free_cipher(eboiv->tfm); + eboiv->tfm = NULL; +} + +static int crypt_iv_eboiv_ctr(struct crypt_config *cc, struct dm_target *ti, + const char *opts) +{ + struct iv_eboiv_private *eboiv = &cc->iv_gen_private.eboiv; + struct crypto_cipher *tfm; + + tfm = crypto_alloc_cipher(cc->cipher, 0, 0); + if (IS_ERR(tfm)) { + ti->error = "Error allocating crypto tfm for EBOIV"; + return PTR_ERR(tfm); + } + + if (crypto_cipher_blocksize(tfm) != cc->iv_size) { + ti->error = "Block size of EBOIV cipher does " + "not match IV size of block cipher"; + crypto_free_cipher(tfm); + return -EINVAL; + } + + eboiv->tfm = tfm; + return 0; +} + +static int crypt_iv_eboiv_init(struct crypt_config *cc) +{ + struct iv_eboiv_private *eboiv = &cc->iv_gen_private.eboiv; + int err; + + err = crypto_cipher_setkey(eboiv->tfm, cc->key, cc->key_size); + if (err) + return err; + + return 0; +} + +static int crypt_iv_eboiv_wipe(struct crypt_config *cc) +{ + /* Called after cc->key is set to random key in crypt_wipe() */ + return crypt_iv_eboiv_init(cc); +} + +static int crypt_iv_eboiv_gen(struct crypt_config *cc, u8 *iv, + struct dm_crypt_request *dmreq) +{ + struct iv_eboiv_private *eboiv = &cc->iv_gen_private.eboiv; + + memset(iv, 0, cc->iv_size); + *(__le64 *)iv = cpu_to_le64(dmreq->iv_sector * cc->sector_size); + crypto_cipher_encrypt_one(eboiv->tfm, iv, iv); + + return 0; +} + static const struct crypt_iv_operations crypt_iv_plain_ops = { .generator = crypt_iv_plain_gen }; @@ -890,6 +960,14 @@ static struct crypt_iv_operations crypt_iv_random_ops = { .generator = crypt_iv_random_gen }; +static struct crypt_iv_operations crypt_iv_eboiv_ops = { + .ctr = crypt_iv_eboiv_ctr, + .dtr = crypt_iv_eboiv_dtr, + .init = crypt_iv_eboiv_init, + .wipe = crypt_iv_eboiv_wipe, + .generator = crypt_iv_eboiv_gen +}; + /* * Integrity extensions */ @@ -2293,6 +2371,8 @@ static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode) cc->iv_gen_ops = &crypt_iv_benbi_ops; else if (strcmp(ivmode, "null") == 0) cc->iv_gen_ops = &crypt_iv_null_ops; + else if (strcmp(ivmode, "eboiv") == 0) + cc->iv_gen_ops = &crypt_iv_eboiv_ops; else if (strcmp(ivmode, "lmk") == 0) { cc->iv_gen_ops = &crypt_iv_lmk_ops; /* @@ -3093,7 +3173,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits) static struct target_type crypt_target = { .name = "crypt", - .version = {1, 18, 1}, + .version = {1, 19, 0}, .module = THIS_MODULE, .ctr = crypt_ctr, .dtr = crypt_dtr,