Received: by 10.223.176.46 with SMTP id f43csp2678414wra; Mon, 22 Jan 2018 01:25:54 -0800 (PST) X-Google-Smtp-Source: AH8x227cMfGXXgZGhCxrnRErk1/Oh95mYJ7+v05EAGrwpykT/4QQ2ZD+1iVvHhyM7LeAPyzCELf7 X-Received: by 10.99.107.129 with SMTP id g123mr6639002pgc.356.1516613154325; Mon, 22 Jan 2018 01:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516613154; cv=none; d=google.com; s=arc-20160816; b=0G4kSKgnZtyB2ukxaeHY82GDKB/4L4LBK7UCzDhC4/oxt31tNFNi1C5WdkRsCje30f XJz2tecbnFOGK49TcxiWgz8Y11KBJ0K7tX7lx6l/qfnyNNS04ML/oBCgaDC2CEe7QESK afc15dU3BVmzllqo0G8XXi04s983/ioc+2dnIWlYx+Jpjw6dWtpZI4+zN8HJuNXYe4xr 80IO2M6ehW7qsUcnPBga3u1TuQBM+SamSyHKAgx+47RS86+WgY+hqGH59X0oc0xscL1y 00no4zqCUKGtAzcE6NHnWtK/Ljwhghvrt3g6N4YuzOlJaFI0FvYzLUuavLrH3XZVtNJr 9BOQ== 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=v9dATHlnOoCHc0c3gGOob4L3Motr/4mYJSAV78cdIHc=; b=pDdoj6oIyXyNFHDwA7CcAXsbFKb2XRXCFRMtqAkYiztkuPoih6AOzzp0j4Uf6ejlA2 HXhKxaHuSohjnqq5SPgewojHdRqcFEB49vM6Lyt34Zh/texRRdGNZKc8TBEKc+4Kvk85 t77u+30c4GO/15YNF2JeEIOqw3waqDaVJ3f2N669Q00/OiGEOraAXQwkaFrkJbL6W170 K9xF0qQG5X+jrl901lfOKlK89a+ffl8Q7fkWz/L23EQLtR/FNz3Dk88ve3ZuZpUvj08v hq4rcZsD76Kv/HBwqpZ2jLqL8x5Hy/rOZH5ygJyM6O/2/sBfgIh31Wr4ezX//p5TPZ0y A+IQ== 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 q7si15031742pfh.74.2018.01.22.01.25.40; Mon, 22 Jan 2018 01:25:54 -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 S1751794AbeAVJYw (ORCPT + 99 others); Mon, 22 Jan 2018 04:24:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60578 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752371AbeAVItB (ORCPT ); Mon, 22 Jan 2018 03:49:01 -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 C8335E9A; Mon, 22 Jan 2018 08:49:00 +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.9 37/47] dm btree: fix serious bug in btree_split_beneath() Date: Mon, 22 Jan 2018 09:45:48 +0100 Message-Id: <20180122083928.451597527@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083925.568134913@linuxfoundation.org> References: <20180122083925.568134913@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.9-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 @@ -678,23 +678,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; }