Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp718606imm; Thu, 13 Sep 2018 06:46:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbA/SS7hgvKzOdEENx/f+jIphc5hpWO8vC2NflU9iqK3batWi6Ag4EJOXPAwFITEusxug0I X-Received: by 2002:a63:9619:: with SMTP id c25-v6mr7368702pge.23.1536846417405; Thu, 13 Sep 2018 06:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846417; cv=none; d=google.com; s=arc-20160816; b=WrpvKDGaltjzzdFoxCHIZ9GpFR8gPjttmHCvx3Lcd9ipkP+9rMttpC8nJwUVoamcEy rlYeoQzPYUzUzPzDM22RcbD6X4IJNwRSakLyCDjCux9YU4D9wkedu1Mu9tZg5U4DeS3B 0uNM8Es9qsdcPpNlUtkHThtPAkDU/DN42OtLZGNcHZE3hZcI7WQPbFPThi7D8HyvGKT6 eFFMLz76QWVjVQTgE9i4brQ2cd92XV8kQd4wA7SgsBAS/V4Q6kOqzwIk2OMpzVmT0+/2 e7B90koE6ETQ7GyEFzC0z6FcOFHJKpnwixmPTzb1uiRkTULLg62kNSkYCCQQUxKAYDnC 690Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=2JIAlOcYXmDMBO9LO4IOy2bMsClFyzXN7Nh+Jw8mOfE=; b=sbBHD9erCWB4/r6qg9JzgyZwJlJEkUMhNdOr02Vyl+qECqUSd5hf8IBK1yLOgU0gjk YZt5AcS1Q6gizUitdSLIk12S6CXmnbTax1s9BnQckYSjwXh4bI9ibJaAo7WFf5T9sN6V SqoIxEdpq1fFzN2CzVgnEuDOkhWCBAXSa5KSKk48lpPZpeoe2JUtIURqhyKHQbxrL+JK DouvSw6Guix/Oiaiqf9Tulab9DzfNCYufc1u6DwVChqow7Rnd3wOlMYQwgSTe+sTBN8f W0W6apGLitijPn2HdVrJjOWsy1SmVSfmZLurVlUmkZi2+4pktr5cmMlIMgOowGWMR6MM jdng== 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 t23-v6si3486055pgk.26.2018.09.13.06.46.41; Thu, 13 Sep 2018 06:46:57 -0700 (PDT) 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 S1730304AbeIMS4E (ORCPT + 99 others); Thu, 13 Sep 2018 14:56:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60880 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728479AbeIMS4D (ORCPT ); Thu, 13 Sep 2018 14:56:03 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D93F1D19; Thu, 13 Sep 2018 13:46:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xu Wen , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 4.14 080/115] btrfs: Exit gracefully when chunk map cannot be inserted to the tree Date: Thu, 13 Sep 2018 15:31:40 +0200 Message-Id: <20180913131828.505905143@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131823.327472833@linuxfoundation.org> References: <20180913131823.327472833@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Qu Wenruo [ Upstream commit 64f64f43c89aca1782aa672e0586f6903c5d8979 ] It's entirely possible that a crafted btrfs image contains overlapping chunks. Although we can't detect such problem by tree-checker, it's not a catastrophic problem, current extent map can already detect such problem and return -EEXIST. We just only need to exit gracefully and fail the mount. Reported-by: Xu Wen Link: https://bugzilla.kernel.org/show_bug.cgi?id=200409 Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6492,10 +6492,14 @@ static int read_one_chunk(struct btrfs_f write_lock(&map_tree->map_tree.lock); ret = add_extent_mapping(&map_tree->map_tree, em, 0); write_unlock(&map_tree->map_tree.lock); - BUG_ON(ret); /* Tree corruption */ + if (ret < 0) { + btrfs_err(fs_info, + "failed to add chunk map, start=%llu len=%llu: %d", + em->start, em->len, ret); + } free_extent_map(em); - return 0; + return ret; } static void fill_device_from_item(struct extent_buffer *leaf,