From patchwork Wed Mar 15 22:12:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 9626811 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.web.codeaurora.org (Postfix) with ESMTP id 067E8604A9 for ; Wed, 15 Mar 2017 22:12:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB21D269DA for ; Wed, 15 Mar 2017 22:12:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF6D92850E; Wed, 15 Mar 2017 22:12:35 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 78D7B269DA for ; Wed, 15 Mar 2017 22:12:35 +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 E630B7E9C7; Wed, 15 Mar 2017 22:12:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E630B7E9C7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E630B7E9C7 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="eOQPFs/V" Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C317A60E3F; Wed, 15 Mar 2017 22:12:34 +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 8E9EC4BB75; Wed, 15 Mar 2017 22:12:32 +0000 (UTC) Received: from smtp.corp.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 v2FMCVUC003706 for ; Wed, 15 Mar 2017 18:12:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8674319EE2; Wed, 15 Mar 2017 22:12:31 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A93660319 for ; Wed, 15 Mar 2017 22:12:29 +0000 (UTC) Received: from mail-pg0-f50.google.com (mail-pg0-f50.google.com [74.125.83.50]) (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 F3D2581233 for ; Wed, 15 Mar 2017 22:12:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F3D2581233 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=samitolvanen@google.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F3D2581233 Received: by mail-pg0-f50.google.com with SMTP id 141so15162179pgd.1 for ; Wed, 15 Mar 2017 15:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Da4daLlIkcVt6sRe+1mK9+6M1Bgf8oSFZLO5NdAoDH4=; b=eOQPFs/V0m3p311I1alSKCeBO3rNAcnOEUtkNTr8ULepOFlp/EicI61DwrCNM/oqc1 0XPX+04PBiz7pF611I9gkzeYNgRIPTd2G4Cw+Np+ArAiqVg1ZJar5X+GgUG5rxM6sIl7 5IlR8Q2oT2wU7y3yD2TrDUe+IbJsOy3Odkwm8gSCzQmQ5DMjqh/f4QOd6B8RjIBX27zM 7pVT0gpLhf1e15rTPtHFgNAvNQO46NUslNsy5SKBKhy5X9ygLkq9rz055s+NHjy6Ksqr BxP3mBuZpRTwZn0L6wuQvEW9pHl+BG+kwsdAOTnsP3/8R9h1Skqwo4k6UA0K4uFS0s1V 7xsg== 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=Da4daLlIkcVt6sRe+1mK9+6M1Bgf8oSFZLO5NdAoDH4=; b=o2fY9jh41i+BLwvTPxWAtauVg8TmuuzLnCvU/YW19XSxYFBH4R1Ea5KSFDpFPmqq+9 +zOka2TXXdng+Pzac2mYnvpdUAkwkQencSFBoy1EjR+qSqxbBdwMF/mL0lmIwjsKzHaO 472vkhMK/WsKb2QTwKTBG33pwJsoKduvyGXoR+p3fNJ3laEcbNFwq/I4y4/phBlKovc6 l8p0TSgvaeQciVpiCgb/P0H52VkMvGVeM7kgPqRu1Nl63VvpABThxcAyEhdK7ftAJpyK ueam8iaV8TCwQvvx+UmWrAWHoTRYj/AKM4ttztra11bygI7H+TcXYVuS2qi0gkhLp127 A6Qg== X-Gm-Message-State: AFeK/H1bk49o8gPGVmhba5TI9fxtGHPaJTdmsDBowrQLCg9V6Qv1BS3m7NAXC4lT/NwGvPAg X-Received: by 10.84.160.195 with SMTP id v3mr7596004plg.161.1489615946270; Wed, 15 Mar 2017 15:12:26 -0700 (PDT) Received: from samitolvanen.mtv.corp.google.com ([2620:0:1000:1611:8052:b039:1559:dc96]) by smtp.gmail.com with ESMTPSA id o5sm6139958pgj.66.2017.03.15.15.12.25 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 15 Mar 2017 15:12:25 -0700 (PDT) Date: Wed, 15 Mar 2017 15:12:23 -0700 From: Sami Tolvanen To: michal virgovic Message-ID: <20170315221223.GA116381@samitolvanen.mtv.corp.google.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 15 Mar 2017 22:12:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 15 Mar 2017 22:12:28 +0000 (UTC) for IP:'74.125.83.50' DOMAIN:'mail-pg0-f50.google.com' HELO:'mail-pg0-f50.google.com' FROM:'samitolvanen@google.com' RCPT:'' X-RedHat-Spam-Score: 0.768 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, RP_MATCHES_RCVD, SPF_PASS) 74.125.83.50 mail-pg0-f50.google.com 74.125.83.50 mail-pg0-f50.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, agk@redhat.com, snitzer@redhat.com, Milan Broz Subject: Re: [dm-devel] [BUG] Oops caused by FEC in 4.10.0 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.26]); Wed, 15 Mar 2017 22:12:35 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Mar 15, 2017 at 09:22:02PM +0100, michal virgovic wrote: > This oops keeps appearing. This can happen if dm-verity is set up with an invalid root hash, for example. Please test the attached patch, which limits recursion and should allow it to fail more gracefully. Sami --- dm verity fec: limit error correction recursion If the hash tree itself is sufficiently corrupt in addition to data blocks, it's possible for error correction to end up in a deep recursive loop, which eventually causes a kernel panic. This change limits the recursion to a reasonable level during a single I/O operation. Fixes: a739ff3f543a ("dm verity: add support for forward error correction") Signed-off-by: Sami Tolvanen --- drivers/md/dm-verity-fec.c | 12 +++++++++++- drivers/md/dm-verity-fec.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index 0f0eb8a3d922..c3cc04d89524 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -439,6 +439,13 @@ int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, if (!verity_fec_is_enabled(v)) return -EOPNOTSUPP; + if (fio->level >= DM_VERITY_FEC_MAX_RECURSION) { + DMWARN_LIMIT("%s: FEC: recursion too deep", v->data_dev->name); + return -EIO; + } + + fio->level++; + if (type == DM_VERITY_BLOCK_TYPE_METADATA) block += v->data_blocks; @@ -470,7 +477,7 @@ int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, if (r < 0) { r = fec_decode_rsb(v, io, fio, rsb, offset, true); if (r < 0) - return r; + goto done; } if (dest) @@ -480,6 +487,8 @@ int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, r = verity_for_bv_block(v, io, iter, fec_bv_copy); } +done: + fio->level--; return r; } @@ -520,6 +529,7 @@ void verity_fec_init_io(struct dm_verity_io *io) memset(fio->bufs, 0, sizeof(fio->bufs)); fio->nbufs = 0; fio->output = NULL; + fio->level = 0; } /* diff --git a/drivers/md/dm-verity-fec.h b/drivers/md/dm-verity-fec.h index 7fa0298b995e..bb31ce87a933 100644 --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -27,6 +27,9 @@ #define DM_VERITY_FEC_BUF_MAX \ (1 << (PAGE_SHIFT - DM_VERITY_FEC_BUF_RS_BITS)) +/* maximum recursion level for verity_fec_decode */ +#define DM_VERITY_FEC_MAX_RECURSION 4 + #define DM_VERITY_OPT_FEC_DEV "use_fec_from_device" #define DM_VERITY_OPT_FEC_BLOCKS "fec_blocks" #define DM_VERITY_OPT_FEC_START "fec_start" @@ -58,6 +61,7 @@ struct dm_verity_fec_io { unsigned nbufs; /* number of buffers allocated */ u8 *output; /* buffer for corrected output */ size_t output_pos; + unsigned level; /* recursion level */ }; #ifdef CONFIG_DM_VERITY_FEC