Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp736386imm; Thu, 13 Sep 2018 07:02:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZiE27yziJay24CJfhp+hL49BY0LBG8x3uLh0zqiYcsFUpScoQ0A18rbgfPFYkvx1c9MRM3 X-Received: by 2002:a65:4043:: with SMTP id h3-v6mr7263186pgp.207.1536847365790; Thu, 13 Sep 2018 07:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847365; cv=none; d=google.com; s=arc-20160816; b=YccFupPzlmrmevrbu9hxPxra30yfuA7n8nvhjAdDA1X7GUtTHq21zfTu/viv7399EG 7LB0g7mcvtXoF3QlQuY1mXemZ+waaUJ1jUsFvaY8APIj3SbrNiheQNv8SoXfnVUj5x2Q NXWToORQqB3mIBas6FJhhCzXK/9A+ZLVSb0AmkSiYYGnXcvQSO718eeCvwZn3rdYLo1s V/68s50R42BlAxx6BfqRDgj2p6Ci3m3WoYF1D4TM98AW/QezE1Q5Xmhls8amUyLCns0S rs8DlROQD3QsESPq3f83I0XlFA7SyeU3WyygIZBRwY93lUNuI0+yyEiqkp7coEFFArTC QB0Q== 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=he9hnGn0qCqsLCOJzGg6NB6eU+7m/LsI7U8hufhRDcI=; b=t3uGUEwo9DG40Md8csQq4kDIUHcKbfwPIpWvBujyWxNL1mLeZw5a8a75ms7RxY/ESo HtVHJfouLptDnIfQnvN9KmRlVU13g7/t7xYd6+LUKjffnDk0BxKyVDTQ/UJhxK2R2uwE SyobvLpy13+EGYdIdP1gCSzU4qR2P+TdDGxpEmenKgx2NrTji8r4zCAuZX9kbhm+RGqp vTV2CY1geydOvCwAP0LxPoPQlozCT6yP4uSfh2Uxg/MvokHqHYX9iIyG0Jd9h2QDgqUl uvpLVGSWfJUB1q3LBZur/N11uGXm1Nd8VAJPp3wF43Ff8D3QshMRLa5O8HgtEYm6LLpR dbig== 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 17-v6si4090630pgw.648.2018.09.13.07.02.24; Thu, 13 Sep 2018 07:02:45 -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 S1731504AbeIMTKW (ORCPT + 99 others); Thu, 13 Sep 2018 15:10:22 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34942 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727760AbeIMTKW (ORCPT ); Thu, 13 Sep 2018 15:10:22 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9EFCFD15; Thu, 13 Sep 2018 14:00:44 +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.18 133/197] btrfs: Exit gracefully when chunk map cannot be inserted to the tree Date: Thu, 13 Sep 2018 15:31:22 +0200 Message-Id: <20180913131846.882504917@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@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.18-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 @@ -6563,10 +6563,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,