Received: by 10.223.176.46 with SMTP id f43csp2657590wra; Mon, 22 Jan 2018 01:02:28 -0800 (PST) X-Google-Smtp-Source: AH8x225GzJENuZ4t3+x7Tq4fRtLaXSJvJ1Bo6vuShqhGVFeo2oHe6NvIhFLL8V0+fEPiQdXAOk4m X-Received: by 2002:a17:902:6849:: with SMTP id f9-v6mr3112630pln.113.1516611748825; Mon, 22 Jan 2018 01:02:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516611748; cv=none; d=google.com; s=arc-20160816; b=DnzyUa8aukcvQt4d/1Db/sicW2yWRMZuGw7Fp8+INeqNntPZNaDJwiuW95BGtC5PPO Okfm8EXPd88dH/j2FdTZZlsXDkvxge1uHAKv9JVXyWyOvTsvBhrgpytzoAmz49KUnIsD SDUVbnXLpnQQRMCg2dvPoijJlKviWDwl4PXa+VZKDpMNKSr9slqmgj7hjsA9HWp9622U smf/gjs1CubB39LlN2Ljx20vUKD14hJDK5kvucstE8CeZd69pwMzznUogiuoowxKhKer +ZDFU8hxZtq+0oEEbbZtQ8IROHJc1XVaEbcRe1BDMeM2K392jmF7TE1E6KKta7fQeWHW IuuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JyU4aY3Q/lezNN0h1ruxhxcy/7JriuYnx4w0xPLwhGA=; b=EopPWy3shB34EsnjE7MLhtUFO1KtwAVNBT2Zo3tC/nC2pHfUSrDoLpb27Qswrel/S6 P9vOQcGi6VrTatDGoM2mhBnzfpVeitUOe5LstvLod09lW6vIuKJPPQKdoQ75lAGrcSha YRknRBWy8lYGbfkobUaOb6APf6hrcYfa0YHzsoQpTopAVCtGTDJQJ6L7mzmhCBootP8C sVPlLBg+PA/fxKx8OurHDr8KOpANj/b2CRL5DnLShJ24fXP9DE6FRZVptjKBEw+GIpli wmABdnS/XpBuFa1ZNNrJwZglrWDWvGke8i+m7jev7OrPqlXaHidFEX8oCHLDONIQJre3 pcKw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13si13976073pgc.833.2018.01.22.01.02.14; Mon, 22 Jan 2018 01:02:28 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753164AbeAVIxX (ORCPT + 99 others); Mon, 22 Jan 2018 03:53:23 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:33950 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753057AbeAVIxV (ORCPT ); Mon, 22 Jan 2018 03:53:21 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5EB3FF0B; Mon, 22 Jan 2018 08:53:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Monty Pavel , Joe Thornber , Mike Snitzer Subject: [PATCH 4.14 70/89] dm btree: fix serious bug in btree_split_beneath() Date: Mon, 22 Jan 2018 09:45:50 +0100 Message-Id: <20180122084001.437618253@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083954.683903493@linuxfoundation.org> References: <20180122083954.683903493@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joe Thornber commit bc68d0a43560e950850fc69b58f0f8254b28f6d6 upstream. When inserting a new key/value pair into a btree we walk down the spine of btree nodes performing the following 2 operations: i) space for a new entry ii) adjusting the first key entry if the new key is lower than any in the node. If the _root_ node is full, the function btree_split_beneath() allocates 2 new nodes, and redistibutes the root nodes entries between them. The root node is left with 2 entries corresponding to the 2 new nodes. btree_split_beneath() then adjusts the spine to point to one of the two new children. This means the first key is never adjusted if the new key was lower, ie. operation (ii) gets missed out. This can result in the new key being 'lost' for a period; until another low valued key is inserted that will uncover it. This is a serious bug, and quite hard to make trigger in normal use. A reproducing test case ("thin create devices-in-reverse-order") is available as part of the thin-provision-tools project: https://github.com/jthornber/thin-provisioning-tools/blob/master/functional-tests/device-mapper/dm-tests.scm#L593 Fix the issue by changing btree_split_beneath() so it no longer adjusts the spine. Instead it unlocks both the new nodes, and lets the main loop in btree_insert_raw() relock the appropriate one and make any neccessary adjustments. Reported-by: Monty Pavel Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/persistent-data/dm-btree.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -683,23 +683,8 @@ static int btree_split_beneath(struct sh pn->keys[1] = rn->keys[0]; memcpy_disk(value_ptr(pn, 1), &val, sizeof(__le64)); - /* - * rejig the spine. This is ugly, since it knows too - * much about the spine - */ - if (s->nodes[0] != new_parent) { - unlock_block(s->info, s->nodes[0]); - s->nodes[0] = new_parent; - } - if (key < le64_to_cpu(rn->keys[0])) { - unlock_block(s->info, right); - s->nodes[1] = left; - } else { - unlock_block(s->info, left); - s->nodes[1] = right; - } - s->count = 2; - + unlock_block(s->info, left); + unlock_block(s->info, right); return 0; }