Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp678899imm; Fri, 1 Jun 2018 07:47:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKll6xgsUKlBWctAlVIFRZdqS5lg5xoJyKA4YAJrOH8hmLrogZj5iBdhdw6jk+T2Mhjnywr X-Received: by 2002:a17:902:da4:: with SMTP id 33-v6mr11331904plv.169.1527864475841; Fri, 01 Jun 2018 07:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527864475; cv=none; d=google.com; s=arc-20160816; b=XRyM7+dBPeGe7KCbD3b2nalAWoio0H/WNsm1mKgsY7VG3JTF6xCMOPpget8GEaipNK goPPH1V627lrwLxXD43yE3S7q8bTFehSsXp1EqtJSQyR8ijDB5ohyU8FtH5s/K9XX1LA rXyWo5UL4ZSb1i6gvHU2dcKll/WhcV6+gkCMCe9WiDBKn8PhYgLv00WLJCckUusjUbAw ZIwkbQwY7V1XIaoG01ywJbKuY8K4nXNI43VKndE0E8OdYuSo+u/cs726UNyW7yftOdLK 7MR58rZX8wrUhQHdmlgXz+AaEVq3XLnpv3+0KVVoWhZ2LiDGnACzZ97Ug4caDnL5Dm98 iPTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Kbc28wIQIfSfH1bJEKIsxft9D8EyoEia3FGQnZlR/M4=; b=lnY17til8W2IIE5INTX/FCLF54SkPMawzkwf/xDnloI0jGSMOCPw6mcQffOJT39fBM cZ5192BWUhzOQtjhSTmafyTYoHTnZylJLLvy+uJg1DbMFj29+MENUK9fXGMvHRwlxcTS svmhH8qF2ZMid3t9RIPqokc7uhShJAQ3nVr52WI8BtGm6RsEf2fpT6q6pMyATrKG90in ub8IdU4+HP5HnAvLPWYJdADvVOZtbF7E6QoG6QAYu7YZYqPz9aH/0+7b+vNUjy7JovPm AXe1UldAnbAfD40ouDYYKODG4ic6pGVCZyquuqV8TwvYLZEFJAr1SsMHFZLBRE0SIOtu rJAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XapD/twr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k74-v6si2394298pgc.304.2018.06.01.07.47.41; Fri, 01 Jun 2018 07:47:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XapD/twr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752487AbeFAOqr (ORCPT + 99 others); Fri, 1 Jun 2018 10:46:47 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:55430 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752552AbeFAOqb (ORCPT ); Fri, 1 Jun 2018 10:46:31 -0400 Received: by mail-it0-f66.google.com with SMTP id 144-v6so2092423iti.5 for ; Fri, 01 Jun 2018 07:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Kbc28wIQIfSfH1bJEKIsxft9D8EyoEia3FGQnZlR/M4=; b=XapD/twrNfqFGshdiHaZacvHIK5qvOTpBFocrtPOS92qDtntTJmXnE+1k4Y24wUhTr qaLXtbYlWEsvOU7QZYXojk4ERYHpZbfIVBMxN4DVJ9kjn82zFrWQ3skWpckOtun/MhmS ordSxtJ2uiFugs4B4M8k9JPe3PM2sWjnD7GNHuUfQNW/Ju8jCM8qbZAFZIrKrSyc909y lnrbptaUGJN9n3T5WsDSi/sGAigt+YPoqjyemy0Rn7LGrMl1ODMn11qtLDUlHTJCSL14 qJaqt+TBF06uiHhofbQrG7MKQHBsKbTEnxbzWhPqpK0WguLaCwPUitWrSQIlfrVf1nK1 uj1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Kbc28wIQIfSfH1bJEKIsxft9D8EyoEia3FGQnZlR/M4=; b=jToiB58g3v4wQ6EiSCGyavw4bXwO25LcTO/vZ5/JT+1IeB4Uui53xke9OSZoDyOUmN oRriOnYJCq7xxpqHawUVTVw/yaaYgTAlMAHGOTUZT4fShJzW317uZlB+IYQXcPRqN0hr GorTQbI+6gAekSGrTwqi3hkjjL73ltffbMnZkzk7ISyTwlLi4ZntQoHjVJE1Nb1d/8wP Wq5f0gY3xqve2qvYliZoUV/NS4CrtOF66g0m5u357WzjHrZRNoNyz0UBVRvJFIQQ6N9E 3zTx6uzc9JCbMnP5KFBQyksvflp5frpah+0V3Lm8q40v2O/LL1V8d/VpqKQYPQdELstM Ri/Q== X-Gm-Message-State: APt69E32KPtxMH4zT8bYHz8BeONOdeAMd4DrSHU847XqY2O8gK6hvPAm 44MOEFBLx0PhKmYZVpwWRcc= X-Received: by 2002:a24:8201:: with SMTP id t1-v6mr4658683itd.51.1527864390167; Fri, 01 Jun 2018 07:46:30 -0700 (PDT) Received: from zzz.localdomain (c-73-5-182-226.hsd1.mn.comcast.net. [73.5.182.226]) by smtp.gmail.com with ESMTPSA id p7-v6sm1227611iob.80.2018.06.01.07.46.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 07:46:29 -0700 (PDT) Date: Fri, 1 Jun 2018 09:46:25 -0500 From: Eric Biggers To: Ladvine D Almeida Cc: Milan Broz , Alasdair Kergon , Mike Snitzer , Joao Pinto , "linux-kernel@vger.kernel.org" , device-mapper development , Manjunath M Bettegowda , Tejas Joglekar , Prabu Thangamuthu Subject: Re: [dm-devel] [PATCH] md: dm-crypt: Add Inline Encryption support for dmcrypt Message-ID: <20180601144625.GA8111@zzz.localdomain> References: <7a510610-9133-39aa-6841-3925c532f3c0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ladvine, On Wed, May 30, 2018 at 02:52:07PM +0000, Ladvine D Almeida wrote: > On Monday 28 May 2018 05:33 PM, Milan Broz wrote: > > On 05/28/2018 03:01 PM, Ladvine D Almeida wrote: > >> This patch adds new option > >> -- perform_inline_encrypt > >> that set the option inside dmcrypt to use inline encryption for > >> the configured mapping. I want to introduce inline encryption support > >> in the UFS Host Controller driver. The usage of the same for accomplishing > >> the Full Disk Encryption is done by the following changes in the > >> dmcrypt subsystem: > >> - New function crypt_inline_encrypt_submit() is added to the > >> dmcrypt which associate the crypto context to the bios which > >> are submitted by the subsystem. > >> - Successful configuration for the inline encryption will result in > >> the crypto transformation job being bypassed in the dmcrypt layer and the > >> actual encryption happens inline to the block device. > > I am not sure this is a good idea. Dm-crypt should never ever forward > > plaintext sector to underlying device. > > > > And you do not even check that your hw is available in the underlying device! > > > > If you want to use dm-crypt, write a crypto API driver for your crypto hw that defines > > specific cipher and let dm-crypt use this cipher (no patches needed in this case!) > > Thanks for sharing your review. > I am sharing the links for the patches which are related to inline encryption below: > https://lkml.org/lkml/2018/5/28/1153 > https://lkml.org/lkml/2018/5/28/1196 > https://lkml.org/lkml/2018/5/28/1158 > https://lkml.org/lkml/2018/5/28/1173 > https://lkml.org/lkml/2018/5/28/1178 > > we have crypto API implementation for the hardware for XTS algorithm, which will get registered when > the XTS algorithm capability of the inline encryption engine inside UFS Host Controller get detected by the UFS HC > driver. dm-crypt will be using this registered cipher. > dm-crypt patch is unavoidable because the encrypt/decrypt function cannot perform the transformation > when inline encryption engine is involved. Also, it demands forwarding the plaintext sectors to the underlying > block device driver and the crypto transformation happens internally in controller when data transfer happens. > I appreciate that you're working on this, but can you please send the full series to the relevant mailing lists, so that everyone has the needed context? Single random patches for this are basically impossible to review. OFC that also means including a cover letter that explains the overall problem and your solution. In the Cc list I also recommend including the ext4 maintainer Theodore Ts'o , who led a discussion at LSFMM 2017 about this topic (https://lwn.net/Articles/717754/), and the f2fs maintainer Jaegeuk Kim who has had to deal with this stuff in an Android device kernel, but for another vendor's inline encryption hardware. I assume your solution will work for other vendors too? I think inline encryption is part of the latest UFS specificaton now, so the latest hardware does it in a "standardized" way and doesn't require ad-hoc vendor-specific stuff --- right? And do you have any plans for inline encryption support with fscrypt (ext4/f2fs encryption, a.k.a. what Android calls "File-Based Encryption")? We need a design for inline encryption in the upstream kernel that is sufficiently general to work for all these vendors and use cases, not just specific ones. Just at a quick glance, you also seem to be abusing the crypto API by exposing inline encryption capabilities as a skcipher_alg. With inline encryption by definition you can't actually do encryption outside of a block device request; as a result, your patch has to use a fallback algorithm to do the actual encryption for the skcipher_alg, which makes no sense. So it is not at all clear to me that you should use the crypto API at all, as opposed to having it be purely a block layer thing. (Please also Cc linux-crypto if you are doing significant work related to the crypto API.) > > > > If I read the patch correctly, you do not check any parameters for > > compatibility with your hw support (cipher, mode, IV algorithm, key length, sector size ...) > > I am registering an algorithm with cipher mode, IV size, block size, supported key size etc. for use by dm-crypt > as per the hardware capability of inline encryption engine. > If any other cipher mode, etc is used during the setup stage, DM-Crypt will work as normal. > > > > > It seems like if the "perform_inline_encrypt" option is present, you just submit > > the whole bio to your code with new INLINE_ENCRYPTION bit set. > > when the optional argument "perform_inline_encrypt" is set, we are not unconditionally sending the bio > to the block devices. The steps are explained below: > 1. user invokes the dm-setup command with the registered cipher "xts" and with the optional argument > "perform_inline_encrypt". > 2. dm-setup invokes the setkey function of the newly introduced algorithm, which finds the available key slots > to be programmed(UFS Host controller Inline Encryption engine has multiple keyslots), program the key slot, > and return the key slot index as return value of the set key function. > 3. When read/write operation happens, crypt_map() function in dm-crypt validates whether there is associated > key configuration index for the request. The Bio will be submitted directly in this case only with the associated > crypto context. > 4. Block device driver, eg. UFS host controller driver will create the Transfer requests as per this crypto context and > encryption happens inside the controller. > > > > > What happens, if the cipher in table is different from what your hw is doing? > > In this case, the dm-crypt will work as previous. This is because the setkey returns 0. > whenever there is key configuration index associated, setkey returns index value(greater than 0). The bios are submitted > with that information to underlying block device drivers. > Also, care is taken to ensure that fallback will happen incase hardware lacks the support of any key lengths. > > Appreciate your suggestions/feedback. We are trying to bring modifications into the subsystem to support controllers with > inline encryption capabilities and tried our best to take care of any vulnerabilities or risks associated to same. > Inline encryption engines got huge advantage over the accelerators/software algorithms that it removes overhead associated > to current implementation like performing transformation on 512 byte chunks, allocation of scatterlists etc. Thanks, Eric