From patchwork Wed Jun 14 23:40:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Halcrow X-Patchwork-Id: 9787631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7FD0E60325 for ; Wed, 14 Jun 2017 23:41:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71BE320007 for ; Wed, 14 Jun 2017 23:41:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 663EF25D9E; Wed, 14 Jun 2017 23:41:00 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12D732022C for ; Wed, 14 Jun 2017 23:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752810AbdFNXk5 (ORCPT ); Wed, 14 Jun 2017 19:40:57 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:35533 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752809AbdFNXky (ORCPT ); Wed, 14 Jun 2017 19:40:54 -0400 Received: by mail-pg0-f43.google.com with SMTP id k71so6722662pgd.2 for ; Wed, 14 Jun 2017 16:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=xpz/sP5JkqlgYXRMBaFRX95MxkY1B4jwDH8w+En6Ft0=; b=kcDbwNkabJGJQ3ociD5llCWio1DjR0ba2OHaB5donvwIdrXYhqJDoHaTpDlMSLTGF/ jOu5oqW0kO4waSQh0UUk9qiP31aDvc3Ov3N42VssLsE8089ksKLuwnFisQsopsvn+fPM 3mVOibAaCNR9gvnDn8n+PSBf673ZY+g4SjJmaXoSWAJZ7orJisgULS3ZfDmOyzoUWuEP BSVfPrOtNK0Ifc4VRA4AHQqJUqETjS3JMxEDeWRLDqEgbhQE61U7T/KESWHWkwp81Ith DqK1kqBezUOZKi8XlaF5h0ZDdYsmi+70CDFjaPpOwR8ifYroCfeAhSZFv7zxXy4xtADi yygA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=xpz/sP5JkqlgYXRMBaFRX95MxkY1B4jwDH8w+En6Ft0=; b=eX6OkY6dYSMT/vN4qdU48rfDMX5mO2UsKbQ5S6ZEkX6dvDFUt2ph5Aqvc9ZLXVSR+A p6hyyRJ15kGzq4tvFKVuKEx38B+bMUoprNYXeSvFj8RnSosrVdn3UJSRG8EEFwvwiM5r vzwk/yg9G1icjFZiqIHbRG8uZcGkH7eqqabmWVEQ8Hx4Y30Rf9SkghD6euhbd8ExPmCv B4mDb+5yUcONcHMj80K5QHvVz7RkfoNkkbRH/T9ehltaAdOeAck8xH7UWplrDTZS7ba5 a7wF/fDAHFcBe3VpG4+GgywAHEUvMQZbGtzNj4Z4tSIOLEN6dfytZQNJJG1P/8CAlbrN zLCg== X-Gm-Message-State: AKS2vOw7QmM5I5ld0c4wxkhPtPhKOLlMph5FQVn/pCDGfmKI2bsIp6DK LE3h96Wi+T3s6/kr X-Received: by 10.84.208.102 with SMTP id f35mr2761631plh.92.1497483653321; Wed, 14 Jun 2017 16:40:53 -0700 (PDT) Received: from mhalcrow-linux.kir.corp.google.com ([100.66.175.61]) by smtp.gmail.com with ESMTPSA id z66sm2141286pfl.13.2017.06.14.16.40.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 16:40:52 -0700 (PDT) From: Michael Halcrow To: Michael Halcrow , "Theodore Y . Ts'o" , Eric Biggers , Jaegeuk Kim , linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, linux-ext4@vger.kernel.org, Tyler Hicks Subject: [RFC PATCH 2/4] dm-crypt: Skip encryption of file system-encrypted blocks Date: Wed, 14 Jun 2017 16:40:38 -0700 Message-Id: <20170614234040.4326-3-mhalcrow@google.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog In-Reply-To: <20170614234040.4326-1-mhalcrow@google.com> References: <20170614234040.4326-1-mhalcrow@google.com> Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP File systems can encrypt some of their data blocks with their own encryption keys, and for those blocks another round of encryption at the dm-crypt layer may be redundant, depending on the keys being used. This patch enables dm-crypt to observe the REQ_NOENCRYPT flag as an indicator that a bio request should bypass the dm-crypt encryption queue. By default dm-crypt will ignore this request flag from the file system. The user must set the allow_encrypt_override option to enable this functionality. Once the dm-crypt has been used with the allow_encrypt_override option for any given block device, it must continue to be used with the option to avoid the possibility of data corruption. Signed-off-by: Michael Halcrow --- drivers/md/dm-crypt.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index ebf9e72d479b..14ca8a6de3d9 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -125,7 +125,8 @@ struct iv_tcw_private { * and encrypts / decrypts at the same time. */ enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID, - DM_CRYPT_SAME_CPU, DM_CRYPT_NO_OFFLOAD }; + DM_CRYPT_SAME_CPU, DM_CRYPT_NO_OFFLOAD, + DM_CRYPT_ENCRYPT_OVERRIDE }; enum cipher_flags { CRYPT_MODE_INTEGRITY_AEAD, /* Use authenticated mode for cihper */ @@ -2572,6 +2573,8 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT; } else if (!strcasecmp(opt_string, "iv_large_sectors")) set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); + else if (!strcasecmp(opt_string, "allow_encrypt_override")) + set_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags); else { ti->error = "Invalid feature arguments"; return -EINVAL; @@ -2770,12 +2773,15 @@ static int crypt_map(struct dm_target *ti, struct bio *bio) struct crypt_config *cc = ti->private; /* - * If bio is REQ_PREFLUSH or REQ_OP_DISCARD, just bypass crypt queues. + * If bio is REQ_PREFLUSH, REQ_NOENCRYPT, or REQ_OP_DISCARD, + * just bypass crypt queues. * - for REQ_PREFLUSH device-mapper core ensures that no IO is in-flight * - for REQ_OP_DISCARD caller must use flush if IO ordering matters */ - if (unlikely(bio->bi_opf & REQ_PREFLUSH || - bio_op(bio) == REQ_OP_DISCARD)) { + if (unlikely(bio->bi_opf & REQ_PREFLUSH) || + (unlikely(bio->bi_opf & REQ_NOENCRYPT) && + test_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags)) || + bio_op(bio) == REQ_OP_DISCARD) { bio->bi_bdev = cc->dev->bdev; if (bio_sectors(bio)) bio->bi_iter.bi_sector = cc->start + @@ -2862,6 +2868,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type, num_feature_args += test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags); num_feature_args += cc->sector_size != (1 << SECTOR_SHIFT); num_feature_args += test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); + num_feature_args += test_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags); if (cc->on_disk_tag_size) num_feature_args++; if (num_feature_args) { @@ -2878,6 +2885,8 @@ static void crypt_status(struct dm_target *ti, status_type_t type, DMEMIT(" sector_size:%d", cc->sector_size); if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags)) DMEMIT(" iv_large_sectors"); + if (test_bit(DM_CRYPT_ENCRYPT_OVERRIDE, &cc->flags)) + DMEMIT(" allow_encrypt_override"); } break;