From patchwork Tue Jul 9 13:22:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 11037059 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 A013E112C for ; Tue, 9 Jul 2019 13:24:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F2D72873C for ; Tue, 9 Jul 2019 13:24:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83C2628770; Tue, 9 Jul 2019 13:24:47 +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 2F8772873C for ; Tue, 9 Jul 2019 13:24:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63586C079917; Tue, 9 Jul 2019 13:24:36 +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 42E1D53B20; Tue, 9 Jul 2019 13:24:33 +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 08C881833004; Tue, 9 Jul 2019 13:24:30 +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 x69DMiMU006670 for ; Tue, 9 Jul 2019 09:22:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id E017895A59; Tue, 9 Jul 2019 13:22:44 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB09C5C2F0 for ; Tue, 9 Jul 2019 13:22:42 +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 51535C05B03F for ; Tue, 9 Jul 2019 13:22:28 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id p17so9850266wrf.11 for ; Tue, 09 Jul 2019 06:22:28 -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=4G+jRC+EC9e/KVmmiXvmsg0Zi3cMg8CUY8CschsuKQA=; b=gsXFvetHSnIsmNU4E1IOFvnDeEoZQJi5K20Hx2T8alJg+KR0vVTL1sInO+K+NMPRfA oJA+aH/M9hVGpw1CfcjhyXCgSnbZJaYKj98QGvYToRfUEomeOiAKZSMiQAhm3W308P0x kJKy4tz77adTHN6WbPMkkpkznJReuIkuLxbSgI6YZZoKDJfWCPorhgmBC6qE9yWSZD3x T70J7572oCl54ycNc+Z2vJhEtMotVe/EVZSwMi8V2mu7PNlrQvgL/7uDaVAafV4fubdg FLc407SIKlTOPcIRVW4ajwQDm47RkhoxDG2En//vsnuW3Vn8G5VRVPGiEFcCzJXOHh+E vtCw== 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=4G+jRC+EC9e/KVmmiXvmsg0Zi3cMg8CUY8CschsuKQA=; b=c70iSdIIEh0pVA6FlhjrFx1Oo5gNNFs6Oh32djNvDVQjGTfy/gLeYNGBJ7tXe/2gb5 OLc6lk4FIShTSZIYkC50boxK8lOz2z5DvjdQAStOKiNpMG/DaRTNoNGOdxI8UoIJNw5W 76gCOktxvHerG11yymB8nLaCQzXnalCmn7A4WnI5xj1Ry/dC9U0hVGOcSmFYCiymjeKy 2tWjpOt4TQTeRxUWyMKUT6/kq1SRfwzT76Rh9GcqDgCcBk6TS9FHzfT0koACD9LOscNR 39TeuIDgSWOt3HUXPplkLhhDJ+0m0rKYg7G694E1X0ztTEVMADTPSMgqpFo57BO4YhRW yZLQ== X-Gm-Message-State: APjAAAUxyyGS6XOXVQ2ixJTRyrkPesfR90n/4ZVTFbLfrsUWz7eG5FdG VVSO6NpUwFNEbuevA0Xs6d7SZ/aCPuk= X-Google-Smtp-Source: APXvYqysaTDr9Apot1xQB04/DCGITLrKOVXT1l+fNdMbxB8w2PX8NaxLbi80xoh+skNc0/OKRqsREg== X-Received: by 2002:adf:f84a:: with SMTP id d10mr24700580wrq.319.1562678546751; Tue, 09 Jul 2019 06:22:26 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id z25sm3533319wmf.38.2019.07.09.06.22.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 06:22:26 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Tue, 9 Jul 2019 15:22:12 +0200 Message-Id: <20190709132214.3905-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.31]); Tue, 09 Jul 2019 13:22:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 09 Jul 2019 13:22:28 +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: 1.194 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, PDS_NO_HELO_DNS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.221.68 mail-wr1-f68.google.com 209.85.221.68 mail-wr1-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Tue, 09 Jul 2019 09:24:28 -0400 Cc: Milan Broz Subject: [dm-devel] [PATCH v2 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 09 Jul 2019 13:24: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 0fd3ca9bfe54..0e24079e97da 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 Tue Jul 9 13:22:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 11037055 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 06BD8112C for ; Tue, 9 Jul 2019 13:24:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA66C28774 for ; Tue, 9 Jul 2019 13:24:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE95528779; Tue, 9 Jul 2019 13:24: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 8E5FB28775 for ; Tue, 9 Jul 2019 13:24: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 F3042307D915; Tue, 9 Jul 2019 13:24:31 +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 AD926832AB; Tue, 9 Jul 2019 13:24: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 36EB41833002; Tue, 9 Jul 2019 13:24:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x69DMjd2006675 for ; Tue, 9 Jul 2019 09:22:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15B88466A1; Tue, 9 Jul 2019 13:22:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F766466A0 for ; Tue, 9 Jul 2019 13:22:42 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) (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 1A7E530860D5 for ; Tue, 9 Jul 2019 13:22:34 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id g17so10874737wrr.5 for ; Tue, 09 Jul 2019 06:22:34 -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=8TRl49LlHwPh+S3aZZuJGzkPdb+qKd5xTmuRDh0+uR0=; b=W9PkRtER5pP8ac/mVLQ20HM6rsWJC9ArXTh2tBZOFZeJW/Hq0SCKa16KkVy8U6RZrZ PbTbP9g8yOcQNrJ3FH2R218d/riMgn6G+tvKbJBzD4i3V3xhK1uroF3FuBl0mJDnOqxn H+gticHF7nRV7nOvReWbR815iLpJQJUAlyUhghJqQrbp/jNhU5ngiIEsWm9wEM57Ex2T Q+Z6he0YayNdEuRdx2YEsX60+r8ngmEFtuafJQN+ku7pE1rPDyA7Z25BuSGApxxaEvn4 WiMiw1+4HRy4im+Es0/n+QeD9gU+83R8xaKowElVEwL6nyS7PsuKUkmwQMKmsxh4rPnu TNYg== 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=8TRl49LlHwPh+S3aZZuJGzkPdb+qKd5xTmuRDh0+uR0=; b=ijLutkE6tD3W8GULwGDODNlU4rM6EItZJIpITSHBMy7Df+Ux7PxR31kVRgOOM6ZM42 VC/rkBmFuU3zSwMeHY7uMIWlRyllc3FYZGJCK9JuunwItY7SqBxDntp1yvJ+3WPhZHSv CC5DudwUI6IYIGtsXOOYa4n0BMAMTTF6UsGevFyMT3nQA6g//aLRc5VkqfeLBuxT6f22 ox2nkLpr8Vl2S1eL0en1wFPd7hsvcMcXMPug2YR6Xs9ncRT82JNDemsiwhqYZIIz7gc5 mwrbqzfriGUoTa/5QWLYFQMjD+4qWJDjyeZfp6hZDH7/BSGagoxiwpRqGfBVNeWHFEr8 MecQ== X-Gm-Message-State: APjAAAUPl/9/5aCmJAWYYLiu/2scYC3nkwD/BvdLBIP9HjrCR6LhXmlD u+FEIa4ZOl8TioBU+7huJ5kAb3J+530= X-Google-Smtp-Source: APXvYqxnjyYac9ehjS+wuAvfSLVp34FMFBsJ9Tt8k3GpFKJKoSSw4KIFqCoJf/95RR22fy/7SdW0vw== X-Received: by 2002:a5d:5012:: with SMTP id e18mr14933112wrt.166.1562678547636; Tue, 09 Jul 2019 06:22:27 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id z25sm3533319wmf.38.2019.07.09.06.22.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 06:22:26 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Tue, 9 Jul 2019 15:22:13 +0200 Message-Id: <20190709132214.3905-2-gmazyland@gmail.com> In-Reply-To: <20190709132214.3905-1-gmazyland@gmail.com> References: <20190709132214.3905-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.44]); Tue, 09 Jul 2019 13:22:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 09 Jul 2019 13:22:34 +0000 (UTC) for IP:'209.85.221.67' DOMAIN:'mail-wr1-f67.google.com' HELO:'mail-wr1-f67.google.com' FROM:'gmazyland@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.228 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, PDS_NO_HELO_DNS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS) 209.85.221.67 mail-wr1-f67.google.com 209.85.221.67 mail-wr1-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Milan Broz Subject: [dm-devel] [PATCH v2 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.48]); Tue, 09 Jul 2019 13:24:41 +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 0e24079e97da..c567e13a0e5f 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 Tue Jul 9 13:22:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 11037053 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 4BAC913B1 for ; Tue, 9 Jul 2019 13:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A9192877B for ; Tue, 9 Jul 2019 13:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F3D128779; Tue, 9 Jul 2019 13:23:49 +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 A349328775 for ; Tue, 9 Jul 2019 13:23:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6832A8831C; Tue, 9 Jul 2019 13:23:15 +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 935EC466A9; Tue, 9 Jul 2019 13:23:07 +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 E4651E162; Tue, 9 Jul 2019 13:22:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x69DMfa7006660 for ; Tue, 9 Jul 2019 09:22:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id CBBB8831C5; Tue, 9 Jul 2019 13:22:41 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5615831BC for ; Tue, 9 Jul 2019 13:22:39 +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 005F0308330C for ; Tue, 9 Jul 2019 13:22:30 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id g17so10874801wrr.5 for ; Tue, 09 Jul 2019 06:22:29 -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=wPhcfQRL6NW2tNfq/SWFOjSLpF4JrsR8NpUH9uwxvGQ=; b=biGsqAe6SMpn0viFc5cP8wcJ8p+Pqvb0UfHJpmwtfjxkzWPhRx//lkKdN4JuOeZgW8 UzdNI+4DdSrTzllnEiP9W4qjxgIdPtZXuy050KftBtBOuFoH/qv0dn35oRYtp31vk1fe NnNU4OQG8xKivnCHsalap3miB0AADKFL7+UGS+hs2esTEGZK0JSYoGZmWY90A7Skxtw8 axGocdpEgftybOG7ldM22vmp0saClTE56g8H8Ww02RrLWqr2AJDG5n73Qy7XLpSs8kEi hJoV40NfFF/K/bWQxO95Icb7YE4T+iPiDLJxIqc6PbKvsBoUs8OjC/nvp30RboBOTrwi yhHw== 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=wPhcfQRL6NW2tNfq/SWFOjSLpF4JrsR8NpUH9uwxvGQ=; b=MkoiYB3zLqkNtVQxMcoPFFhYpzlnd6H3QGPqJDDQ2lK0KRoJbmz0rS80BoBhh3kaUC VIAAGMBx3hGV+OESVWj4D4o9KeGvK18Wh6zGqLz4oky+wkVGf/7/7F8X0HKrjnk1oFdp H3EDhlYKJVqcK1qFlfL/5i/CtqwlFp+JqspKjMPHNtomym242JFvJRUvPj/kiS6nGoET ZbA2Hkh+o7T6uIockPV4UgYqcTJpkvfHkBQ/Y7UwUSFpFUetxbgJ3hzloNcfd/BXgokX /usRCPCc+fNjzdMA2Jd/rmeRG/MsteevqnjLG5XTDABCD1Yx0IAkYj6GpOUqcaOij+xy PwgQ== X-Gm-Message-State: APjAAAV7rTsMqNoBWdUOzJekUvIJyGgxJlXsi9bHy+CSGqMs7weKDSSs L68vaP71X2o1jva3isAR3Uw3YjqHTG8= X-Google-Smtp-Source: APXvYqy4cfQ7Si1/rlVfBdK4OI7sMkreIHpmy+2YEm7gEa5GaZjBgz5X/QkPwJZ0+5+pIwQuEWvE5A== X-Received: by 2002:adf:90e7:: with SMTP id i94mr19879999wri.224.1562678548331; Tue, 09 Jul 2019 06:22:28 -0700 (PDT) Received: from merlot.mazyland.net (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.googlemail.com with ESMTPSA id z25sm3533319wmf.38.2019.07.09.06.22.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 06:22:27 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Tue, 9 Jul 2019 15:22:14 +0200 Message-Id: <20190709132214.3905-3-gmazyland@gmail.com> In-Reply-To: <20190709132214.3905-1-gmazyland@gmail.com> References: <20190709132214.3905-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.44]); Tue, 09 Jul 2019 13:22:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 09 Jul 2019 13:22:30 +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: 1.229 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, PDS_NO_HELO_DNS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE) 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.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: Milan Broz Subject: [dm-devel] [PATCH v2 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 09 Jul 2019 13:23:47 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This IV is used in some BitLocker devices with CBC encryption mode. IV is encrypted little-endian byte-offset (with the same key and cipher as the volume). 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 c567e13a0e5f..0443a925840b 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,