Received: by 10.223.176.46 with SMTP id f43csp248857wra; Tue, 23 Jan 2018 20:15:07 -0800 (PST) X-Google-Smtp-Source: AH8x2240fwPaVOF0ryU1xjyrBIXmsBv6dn3k4Yl4sSefr+RFDJeJvU7ix6ieB77izbBmZflM48Cv X-Received: by 10.98.25.69 with SMTP id 66mr11932077pfz.219.1516767307271; Tue, 23 Jan 2018 20:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516767307; cv=none; d=google.com; s=arc-20160816; b=kLtZAPDe2NmPzdCQUVsCRq3tQHpGr0SI6sQ+gCUNo4tT6pVYnbJRDGUTcL1pVE/2h7 zmtiLM56qbn939YgsF0zTyXIPJlD1FP+JbQMANHtbGQ8Oc0wvXbMxJqtkxeMVuSOhUs+ taJnCceI9OhdDzhROR59Xn4TV7S694Zc4XCqnx93Pe6txxmlIwakWpp4QAkWGG9AiDcm vFHymq/FRlfeetp1CwBnkK/6OedgQHDwDcjrmpsAiLCEyBQYD5b69WXwjBkh529TwaJD u1jWtola751axrfLM+1ZCZV1lNJXg1LSmXNKiLiGGqh5yjm8KuGutdzwPW5SRriV8QaS LYhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=amhHFJ4xlvK/ss3LRqstvBeVd4yXow1pJjquHBJum3w=; b=DmaenCJrjd2y+JVUjTRaMdJ8ZootrYyWJo/cXg8O4CUVgj/e9uk1h1YAaQoroSIXZr y+uVDoWLqwGkRefWRpfAuhXpPiTO8srSQGIA4OGOHlDJj1v/Xc/46n7IC05NMW9GtZRP tdkLh2FAFk/1DwWaQ2/x3GdcLO/1IzYBU1FyHj5zNyAJEmSqqq5W8137RcwwTTqvMjbq A/PdGOuA1nhtrvwzUmbAu6gi5IspXZdwDceH4YwjsUR0F54WWfsLdKdQQHbtvVsL/ejF 1QnIEqZpJ1t0o5xSckVJ46nagykZflw7kzmfovCnCBv51/kN2qqTnJ5B0f218qsbdKEk bL/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=iBuBqaJJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si568159plx.15.2018.01.23.20.14.53; Tue, 23 Jan 2018 20:15:07 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=iBuBqaJJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752602AbeAXEO3 (ORCPT + 99 others); Tue, 23 Jan 2018 23:14:29 -0500 Received: from mail-cys01nam02on0106.outbound.protection.outlook.com ([104.47.37.106]:53792 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752223AbeAXEOY (ORCPT ); Tue, 23 Jan 2018 23:14:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=amhHFJ4xlvK/ss3LRqstvBeVd4yXow1pJjquHBJum3w=; b=iBuBqaJJRa2LgBRKsVuKP57csvX3ZygQ9v4n6B3uM6hRgWcasw1y8kvqciBBA2efkuBQ0/24MZgK1LSKPMOdwky1Odqiu3cHTq7CbCbXd3LMGRvISi3dveqj/S4ZxVbOyuZs6AnPJrj8wimrggoe695eEt88MGIyxpbPb+mro6U= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0920.namprd21.prod.outlook.com (52.132.132.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.3; Wed, 24 Jan 2018 04:14:22 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:14:22 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Liu Bo , David Sterba , "Sasha Levin" Subject: [PATCH AUTOSEL for 4.14 003/100] Btrfs: bail out gracefully rather than BUG_ON Thread-Topic: [PATCH AUTOSEL for 4.14 003/100] Btrfs: bail out gracefully rather than BUG_ON Thread-Index: AQHTlMnPGb8I3+ByF0qBNyDOpOU2/A== Date: Wed, 24 Jan 2018 04:14:22 +0000 Message-ID: <20180124041414.32065-3-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0920;7:Rg479+Vje2T8+0VKj5Y7Wvz9YARmxYMGhIXiVvIDybOrMrLtrswXVzu0EMStthHqjkPawbpD1CdO92sEjIymyIyoChO93Mz8QYaZwLCPojuA3eDFFGp3sM9vpntATGfYpSP6cpPuUNkZYh1CpvIPCgbMxVdBB7ySjMG3pW1hrQ1iEdTyRIv7Dy9H80FXZ/FjjawX+1WvUgqgsjb6e1a5D7aLZpcGkwSjBsL55qnmFTebiwcjt3St7fyAsTmJYFxB x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-ms-office365-filtering-correlation-id: 5a6e462a-0153-4450-3264-08d562e0f297 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB0920; x-ms-traffictypediagnostic: DM5PR2101MB0920: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(8121501046)(5005006)(3231046)(2400081)(944501161)(93006095)(93001095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0920;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0920; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(376002)(396003)(39380400002)(346002)(189003)(199004)(105586002)(106356001)(86362001)(2900100001)(66066001)(305945005)(14454004)(22452003)(72206003)(3280700002)(3660700001)(10290500003)(5660300001)(36756003)(2950100002)(575784001)(7736002)(478600001)(110136005)(316002)(97736004)(81166006)(6116002)(3846002)(26005)(1076002)(6346003)(54906003)(25786009)(81156014)(6436002)(10090500001)(68736007)(107886003)(99286004)(8676002)(8936002)(4326008)(5250100002)(2501003)(86612001)(6486002)(59450400001)(2906002)(6506007)(76176011)(6512007)(102836004)(53936002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0920;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: DEqOQOdPclelrqCqPS7/BaMUUxymUHZrS+XpCgQutx/ya0cOrFs29d1JAJrVqBV4QqRvjT5Kjqxr5fNAXYJnMQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a6e462a-0153-4450-3264-08d562e0f297 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:22.3123 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0920 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liu Bo [ Upstream commit 56a0e706fcf870270878d6d72b71092ae42d229c ] If a file's DIR_ITEM key is invalid (due to memory errors) and gets written to disk, a future lookup_path can end up with kernel panic due to BUG_ON(). This gets rid of the BUG_ON(), meanwhile output the corrupted key and return ENOENT if it's invalid. Signed-off-by: Liu Bo Reported-by: Guillaume Bouchard Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d94e3f68b9b1..c71afd424900 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5500,6 +5500,14 @@ static int btrfs_inode_by_name(struct inode *dir, st= ruct dentry *dentry, goto out_err; =20 btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); + if (location->type !=3D BTRFS_INODE_ITEM_KEY && + location->type !=3D BTRFS_ROOT_ITEM_KEY) { + btrfs_warn(root->fs_info, +"%s gets something invalid in DIR_ITEM (name %s, directory ino %llu, locat= ion(%llu %u %llu))", + __func__, name, btrfs_ino(BTRFS_I(dir)), + location->objectid, location->type, location->offset); + goto out_err; + } out: btrfs_free_path(path); return ret; @@ -5816,8 +5824,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, = struct dentry *dentry) return inode; } =20 - BUG_ON(location.type !=3D BTRFS_ROOT_ITEM_KEY); - index =3D srcu_read_lock(&fs_info->subvol_srcu); ret =3D fixup_tree_root_location(fs_info, dir, dentry, &location, &sub_root); --=20 2.11.0