Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Mon, 17 Aug 2020 14:32:33 +0200 (CEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07HBWYVm038815 for ; Mon, 17 Aug 2020 07:44:27 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 32y4f3tv42-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Aug 2020 07:44:27 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07HBi9P5003182 for ; Mon, 17 Aug 2020 11:44:25 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 32x6ygt6nw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Aug 2020 11:44:25 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07HBiNtF31982022 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 17 Aug 2020 11:44:23 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 25293AE056 for ; Mon, 17 Aug 2020 11:44:23 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0AE02AE04D for ; Mon, 17 Aug 2020 11:44:23 +0000 (GMT) Received: from [9.145.183.231] (unknown [9.145.183.231]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Mon, 17 Aug 2020 11:44:22 +0000 (GMT) From: Ingo Franzki Message-ID: <3e81e8d5-7afe-9cf9-abd4-9a2ca1482511@linux.ibm.com> Date: Mon, 17 Aug 2020 13:44:26 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: [dm-crypt] LUKS2 online reencryption with PAES cipher ? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "dm-crypt@saout.de" Hi, I just played a little bit with the LUKS2 online reencryption feature (using code from current master). Works great (as far as I can tell) for clear key (i.e. AES cipher), but it fails for the wrapped key cipher PAES. It fails because it always generates a new volume key by random, regardless which cipher is used. For the PAES cipher, a key generated by random wont work, such a key must be generated by the HSM. For 'cryptsetup luksFormat' we use it with a key generated outside of cryptsetup, passing the key via --master-key-file (together with --key-size). To make 'cryptsetup reencrypt' work with PAES, we would also need to pass in the new key via --master-key-file (and --key-size). Unfortunately, the reencrypt action does not use the master key file option. Function action_reencrypt() calls crypt_keyslot_add_by_key() which then calls crypt_keyslot_add_by_key() but passes NULL as volume key. Thus a new randomly generated key is used. If the key specified with the master key file options would be passed here, it should work with the PAES cipher also. This would not only be beneficial for PAES, but also for clear key AES cipher, allowing to use a specified key as volume key (like with luksFormat). If I try to use 'cryptsetup reencrypt' with an existing LUKS2 volume encrypted with PAES it fails as follows: # cryptsetup reencrypt /dev/loop0 --debug ... snip debug messages ... Enter passphrase for key slot 0: ... snip debug messages ... # Checking if cipher paes-cbc-plain64 is usable. # Userspace crypto wrapper cannot use paes-cbc-plain64 (-22). Failed to setup dm-crypt key mapping for device /dev/loop0. Check that kernel supports paes-cbc-plain64 cipher (check syslog for more info). This is because function LUKS2_check_cipher() is called which again generates a new volume key to test the cipher by random. So the code should use 'if (!crypt_cipher_wrapped_key(....))' like it does at other places (e.g. in _crypt_format_luks2() ) to not check the cipher for wrapped key ciphers (PAES is the only such at the moment). So I think with a few code changes, it should be possible to make online reencryption also work with the PAES cipher, when the volume key is generated outside of cryptsetup and passed in via --master-key-file. What _does_ work, is to reencrypt a LUKS2 PAES volume with a clear key cipher: # cryptsetup reencrypt /dev/loop0 --cipher aes-cbc-plain64 Enter passphrase for key slot 0: Finished, time 01:22.875, 984 MiB written, speed 11.9 MiB/s -- Ingo Franzki eMail: ifranzki@linux.ibm.com Tel: ++49 (0)7031-16-4648 Fax: ++49 (0)7031-16-3456 Linux on IBM Z Development, Schoenaicher Str. 220, 71032 Boeblingen, Germany IBM Deutschland Research & Development GmbH / Vorsitzender des Aufsichtsrats: Matthias Hartmann Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294 IBM DATA Privacy Statement: https://www.ibm.com/privacy/us/en/