From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226F2/RvDIpclbJT6OX3gQ0vNNj60QJcxLEhwbVDiaBERJVCtSzYDML0L18Ih7Fo5lp/o3Wz ARC-Seal: i=1; a=rsa-sha256; t=1517257052; cv=none; d=google.com; s=arc-20160816; b=CCstAhWqzrHTg53dxNQmb6Y2YIjZZNjahz9eGsxTzs3XRezUOsdkOLy30jEoMD1L6F nGhJIjoklqOy/wKfi6URU5zy1AP8PNkYsQ/fWZGtN+aZrPWK6nDALIgeKgyv9W/3+UtY bJcmmDDE9C5fI770d/wAB38G9RW6pvls9Yiu4rQbBe6kyMbMgzwX7KmFAvzbMxjY7qzb iUcLuabnjg99DImZaCwvr/eE19+sR+ivmPAZQlJhfoUW0UJasE3CLzb/KToKnmz2PsOI /pXQdUf/0PGmp1ATzPneAnPFs1KXd3RHVXXvQyinKetEoLRuG5TnDXKHhsAb0tvE6VG3 mEsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=CX0+HaVe5WExq6BO1YMvFhgu0EuNXE1IIvST29WEXoQ=; b=IGs5e60RcyRo1W0exyWQOpdjujcSt1m2Ik/hNTBUzmByUWREAKlqsvwt9xPoEu8Kxm 95ixS3KQJZ/nx0yvwRsmdNLtHDE7pLJlVMlLnBW8YMUiJUCQS9DE8IoFtg5LybkysxDa pt3IX40s1gV05EybEjZn3Qg8XSf6oVdr0wQOekIK3IFj9hYJXmdIo6ZkN7YK4cgHx3L/ r3N9YLQ+b16yGcS92Wb2wk47Mm0QgC70PxG7fcm8ucOlTkPWxNRfYAnAZbQsUWICjiJW zSbpoGq7pa0L67WeUtTL2LHNx7KWS+/ZAGLipsOu4g7kMKpWk9JEJb3bK/+cDbnNIt5O 0ohA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org 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 3.18 16/52] dm btree: fix serious bug in btree_split_beneath() Date: Mon, 29 Jan 2018 13:56:34 +0100 Message-Id: <20180129123628.903108090@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123628.168904217@linuxfoundation.org> References: <20180129123628.168904217@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590959331055344404?= X-GMAIL-MSGID: =?utf-8?q?1590959331055344404?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 3.18-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 @@ -572,23 +572,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; }