From patchwork Mon Apr 14 20:02:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 3985531 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C4B969F336 for ; Mon, 14 Apr 2014 20:07:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05DC52016C for ; Mon, 14 Apr 2014 20:07:40 +0000 (UTC) Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mail.kernel.org (Postfix) with ESMTP id 2002E2015A for ; Mon, 14 Apr 2014 20:07:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3EK3417026496; Mon, 14 Apr 2014 16:03:05 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3EK32BL032414 for ; Mon, 14 Apr 2014 16:03:02 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3EK31jD006154; Mon, 14 Apr 2014 16:03:01 -0400 Received: from mail-ee0-f45.google.com (mail-ee0-f45.google.com [74.125.83.45]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3EK2xYI019648; Mon, 14 Apr 2014 16:03:00 -0400 Received: by mail-ee0-f45.google.com with SMTP id d17so6917640eek.18 for ; Mon, 14 Apr 2014 13:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=gAWokn40fgDnRQOGAw0qcbYV5pubnFt0Ej2DXb5lFhc=; b=fntPPT/FA/Zk4UD4i7DYAk/rRZZ0LX4m5Yi3RSmdrPiS76YxibwWY/9Mx7XsWqdfDp 30L4GtmKvn+OQgbY/O4GkM6+FGUlT9EzIl8lfrDBNsSdGaJTl2uWHhiakKLzYuBP70Qc 2srNUs+dpVyrtaSwcmSzI+sQ7bhhoWjYlRJevIMmU9tM21ebCtXXunNy0FS17y/eLv3w Y25yorm0FhHRElgsU1OKdfcqFq6WjW4upMkHbjPWKeI6aA3bp0x3nnHlWT5tWJZHxAiB dlWfb22zs96ZOET2ELn/zAjdac0583/1nDQAgNvJ9G2AG5j88LhyU1FmL2i9iHa9UnxC Eosw== X-Received: by 10.14.22.69 with SMTP id s45mr5895978ees.56.1397505779279; Mon, 14 Apr 2014 13:02:59 -0700 (PDT) Received: from tawny.mazyland.net (56.157.broadband5.iol.cz. [88.100.157.56]) by mx.google.com with ESMTPSA id x46sm42960826een.17.2014.04.14.13.02.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Apr 2014 13:02:58 -0700 (PDT) From: Milan Broz To: dm-devel@redhat.com Date: Mon, 14 Apr 2014 22:02:30 +0200 Message-Id: <1397505750-18783-1-git-send-email-gmazyland@gmail.com> X-RedHat-Spam-Score: -3.1 (BAYES_00, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.21 X-loop: dm-devel@redhat.com Cc: kmo@daterainc.com, mpatocka@redhat.com, Milan Broz , snitzer@redhat.com Subject: [dm-devel] [PATCH] dm-verity: Fix biovecs hash calculation regression X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The commit 003b5c5719f159f4f4bf97511c4702a0638313dd block: Convert drivers to immutable biovecs incorrectly converted biovec iteration in dm-verity to always calculate hash from full biovec, while the function need to calculate hash only from part of it (up to "todo" calculated value). This patch fixes the issue by limiting hash input to only really requested data size. The problem is easily reproducible using cryptsetup regression test for veritysetup (verity-compat-test). (Patch should be applied also to 3.14 stable.) Signed-off-by: Milan Broz Acked-by: Mikulas Patocka --- drivers/md/dm-verity.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c index 796007a..7a7bab8 100644 --- a/drivers/md/dm-verity.c +++ b/drivers/md/dm-verity.c @@ -330,15 +330,17 @@ test_block_hash: return r; } } - todo = 1 << v->data_dev_block_bits; - while (io->iter.bi_size) { + do { u8 *page; + unsigned len; struct bio_vec bv = bio_iter_iovec(bio, io->iter); page = kmap_atomic(bv.bv_page); - r = crypto_shash_update(desc, page + bv.bv_offset, - bv.bv_len); + len = bv.bv_len; + if (likely(len >= todo)) + len = todo; + r = crypto_shash_update(desc, page + bv.bv_offset, len); kunmap_atomic(page); if (r < 0) { @@ -346,8 +348,9 @@ test_block_hash: return r; } - bio_advance_iter(bio, &io->iter, bv.bv_len); - } + bio_advance_iter(bio, &io->iter, len); + todo -= len; + } while (todo); if (!v->version) { r = crypto_shash_update(desc, v->salt, v->salt_size);