From patchwork Fri Mar 31 19:32:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 9657239 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 ECAF560350 for ; Fri, 31 Mar 2017 19:33:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF624286F7 for ; Fri, 31 Mar 2017 19:33:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D44F3286FB; Fri, 31 Mar 2017 19:33:36 +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 C16D0286F7 for ; Fri, 31 Mar 2017 19:33: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 8B7D7C01C718; Fri, 31 Mar 2017 19:33:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B7D7C01C718 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ext-mx08.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 8B7D7C01C718 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="q6Dst64Q" Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F1007EBCE; Fri, 31 Mar 2017 19:33:33 +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 B8C2E18521CA; Fri, 31 Mar 2017 19:33:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2VJX8aP006531 for ; Fri, 31 Mar 2017 15:33:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9838277C93; Fri, 31 Mar 2017 19:33:08 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9042277C8C for ; Fri, 31 Mar 2017 19:33:06 +0000 (UTC) Received: from mail-pg0-f43.google.com (mail-pg0-f43.google.com [74.125.83.43]) (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 195FA2EF193 for ; Fri, 31 Mar 2017 19:33:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 195FA2EF193 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=samitolvanen@google.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 195FA2EF193 Received: by mail-pg0-f43.google.com with SMTP id 81so79889757pgh.2 for ; Fri, 31 Mar 2017 12:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ioYr8T+xHO6nuBAyPwX97PGhzlH+8fKPKjujJP9lcaY=; b=q6Dst64QiYtaiiaqSUrmbLN9amytURMqiN5OiFAXkjPh4VhIrteipSP8Kz4w9mKbic mEfRoWGPjQJ9SpjeDgr3mFcyb9x+aDN04POA7QnB1jfN+zN9twy/+WBlfKWXNIUoq86e aozt/yNOhNYln0aBkrwZS3/KWpJIaz6mST3ii8YyWyYAsF9Bi9kUVc5XLN/KK7+Y0oYK zWhvd60TdGpOshnApw17oemYR3zutIrstPGjMNwEtJVFCgvGlOlL8fqXqXBM/WBXHjOZ QLMFLAgiHsacyei6ZvTv0WoY5k3jJuc7P0fUDytTrsFcc7fgwLYklkxHF/+R0mAIL+XJ 6K1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ioYr8T+xHO6nuBAyPwX97PGhzlH+8fKPKjujJP9lcaY=; b=HwlU5oXCA6N56KWWkZnBBsi9N7jCd4MO8kRtdDao8xyWBHAYpkz7CqRgRYD+eOPk2P PjsZuaARnQXzxYn5QFXmVAH+XGVR+7SdLaOSArkcUvTW6kyvw3KcFWwCafu6RLV2hbUE Q4csE6JEfDsC2Lu9IRTTPDXhRcGh8Rf/+nfpbdxtB8ZXNk5y3uia7eUNWgnJUUMILtcR NVkFXSgxrHlCOsK6CmYxmQubjQzM/yYtVEjicts6NMO4996tmFqs3VKI7bds3lbJiaF9 e/XBg7ICwyXM4+th1/znU8xfeBbU5pipgUxSxQwxfZe4twuR3Vp5qEswahglESUb8Vbf xzEw== X-Gm-Message-State: AFeK/H1bMSV7f4iqafeUpjIR3knlcXtQ2HyLtbIpyyCjc1tkHAebldnnHVrSRrb0MZabLFPj X-Received: by 10.84.215.215 with SMTP id g23mr5076475plj.22.1490988784368; Fri, 31 Mar 2017 12:33:04 -0700 (PDT) Received: from samitolvanen.mtv.corp.google.com ([100.98.112.14]) by smtp.gmail.com with ESMTPSA id r8sm12043072pfk.80.2017.03.31.12.33.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Mar 2017 12:33:03 -0700 (PDT) From: Sami Tolvanen To: Mike Snitzer , dm-devel@redhat.com, michal virgovic , Milan Broz Date: Fri, 31 Mar 2017 12:32:44 -0700 Message-Id: <20170331193245.46999-1-samitolvanen@google.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 31 Mar 2017 19:33:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 31 Mar 2017 19:33:05 +0000 (UTC) for IP:'74.125.83.43' DOMAIN:'mail-pg0-f43.google.com' HELO:'mail-pg0-f43.google.com' FROM:'samitolvanen@google.com' RCPT:'' X-RedHat-Spam-Score: -2.012 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, RP_MATCHES_RCVD, SPF_PASS) 74.125.83.43 mail-pg0-f43.google.com 74.125.83.43 mail-pg0-f43.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Sami Tolvanen Subject: [dm-devel] [PATCH 1/2] dm verity fec: limit error correction recursion 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: , MIME-Version: 1.0 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.32]); Fri, 31 Mar 2017 19:33:35 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP 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