Received: by 10.213.65.68 with SMTP id h4csp43561imn; Mon, 19 Mar 2018 18:59:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELvW2gVKqrysG5hta7TAGNpsGiRsCvO4G7ewIE8ZrFTJMZ90/OYXfw9JA2GtHgeccd+CO43x X-Received: by 10.99.120.197 with SMTP id t188mr10746403pgc.358.1521511173245; Mon, 19 Mar 2018 18:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521511173; cv=none; d=google.com; s=arc-20160816; b=GkPouqw7ja9V1DSOnmKtoBKGc08fi1BJdd7yTCw5nHzmAVWEDmDxSzWJiYCVZ0F2Gm 6Ok1IstxeIsFQVNOSm2SqrAb4+Pqb1hSJh89MhKOz4J+1ZSB9LAI5hsPpA0BIWlvaeLg Hf5DplLuAsNLle1MtoWAlUt9z/oYxcUbzxNMaH7j2Xiz1BH01R1UShr2rdOpL4BczIHO O5h0KWNDAlJyBKoDS34KNR5ujnlWDM1quJVGN9PlQymYr07iYstwlpSy6eT4rR+0WsMW F2LxahRc3Za5WGhNDtndASS3CPxHqOv5u9yMhSMayfMKwTYjr4q7LKQavEJS9LoRfxYe Dr4Q== 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=1zCksd3A0q/gTbQfMWW/eIwTvhXBcEJh/jeX+vVH2I4=; b=PMS1yMTN2KnRoF5wvmtyQHE+WYdo6wjCGUTeGuCaL8dH0Py0qKQrUfm6MlGREkELNF uaL6N2NeEkcLOD2kCMXtWWErYksBdAOkaVZSOA7JrwLXzp6AK/1jY+BrIeDJlceM29Of FiPBC1zJmJrbeXDBJ3WBKR8ms0PU3/JXap7k6sI3EKeNLRapCF11Ya2cXtgXMcA+Xl6a 5qSEJ3ik8yksk7lnrwaseBBg0d+Ys4Z6HsC/gypm4kAD8K2BoOqa0U1PjF8CtUFJKSTx BYq11oN1fEFSyxd3GAG5dpw7Kih1i6E1EmgWfAYrrFFAdvj2op2g40QwZ9Dqy+VeoQFI d/UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jgyAA1Li; 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 94-v6si515679ple.694.2018.03.19.18.59.19; Mon, 19 Mar 2018 18:59:33 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jgyAA1Li; 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 S1032493AbeCSWRt (ORCPT + 99 others); Mon, 19 Mar 2018 18:17:49 -0400 Received: from mail-sn1nam01on0129.outbound.protection.outlook.com ([104.47.32.129]:20557 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934004AbeCSPtr (ORCPT ); Mon, 19 Mar 2018 11:49:47 -0400 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=1zCksd3A0q/gTbQfMWW/eIwTvhXBcEJh/jeX+vVH2I4=; b=jgyAA1LiAya805kmpnQsUoBttF4Dc6KgQzSr6pj/glH8tvvyeyZ1gkBGxovrh7K4Li1cfSWxQGHOacyGl5gWQEesrSEN/pT8mwcs1L+Ho/by6/Ce+QZ8v5uGBX4WvEe/JRNpIZ3/MyPuXAtXg/x4JglHOi+GXYqL/DcN/ahl2/w= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0981.namprd21.prod.outlook.com (52.132.133.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 15:49:38 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:49:38 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: "Darrick J. Wong" , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 095/124] xfs: harden directory integrity checks some more Thread-Topic: [PATCH AUTOSEL for 4.15 095/124] xfs: harden directory integrity checks some more Thread-Index: AQHTv5nDCcc2Q+izFUeBT3uIALiSTA== Date: Mon, 19 Mar 2018 15:48:45 +0000 Message-ID: <20180319154645.11350-95-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-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;DM5PR2101MB0981;7:FBD7K2D9Vr7vyptoHn5DCMUfQqfoDFdOyB8YcS9oYh5QWR4YCD3XbAYJS+CAPrsMEamUutMUTjXWyr0NyBPhEYj2j09nRiD5g8pWvtJS9jGcQr5RDKddFMfQzmrw0Bbu+UntuFdmZxggo0Urwyn7cT1mW0scxQtfRAnYDdMm00BMKWEbQVR2yAx9/3t87LQ3SzS/0vN7IDPjfEhEVvvOwPgMZbK2pAzGUHxWTMJylwWAYS/6e0Y2ceiliTLCIYth;20:PUv7lEqQYyA65zuGz+JG6EBl6QQ1tqbRTDPWwNMv2zUpHd7NE21MupkUZAV05wLSjQYgG4+rKLEOlWCvFucHwd+Nf+Zfufe5b6klhk5FwAD+7dDEhMJxwzYTkJEw4n835J8MOq72f7p4jlCB/s9c7l42xnxKTWmWHeiFnNdn5iE= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 63aa3423-c2b6-422c-2fcd-08d58db105cc x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0981; x-ms-traffictypediagnostic: DM5PR2101MB0981: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(209352067349851)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0981;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0981; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(396003)(376002)(366004)(39860400002)(39380400002)(189003)(199004)(66066001)(6486002)(26005)(110136005)(5660300001)(54906003)(3280700002)(6512007)(68736007)(102836004)(6436002)(107886003)(10290500003)(53936002)(186003)(59450400001)(72206003)(14454004)(36756003)(6666003)(2950100002)(316002)(6506007)(22452003)(478600001)(10090500001)(106356001)(105586002)(99286004)(7736002)(3660700001)(86362001)(76176011)(305945005)(86612001)(2501003)(97736004)(5250100002)(4326008)(3846002)(6116002)(1076002)(8936002)(25786009)(81156014)(81166006)(8676002)(2900100001)(2906002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0981;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: QoxWb8z2waAC83hN9kffsr64YfH9rkN7K8lu6C22HkTBD85CoJMqOok5EJgYwYlpOlOcCU+u7XmwYJKpNkSX1zRzdX3rMW5zgAyU4c0erP5pbAdUo9zUKpruwVc4gu92srCFkp82Xk+ZWUeGCwp+Z2zrbwCzr3JX2wB9eGcw54Iq4zHuatrCyLKN+6DnAhSBaqgeAqFXhKZkGsCVd+XzGyQ7zogDm+2w++y3ESfoXTzJrr8cEzTh/381aEU6vcDn+heIFI7vvw6Xb4QZFT3p+fvpDMT3WDKQ8Jzf3YG9uy2Qp/PHsl11Axa4qTOLbk3fgMcfJDhgnizzBhZHdNSHpw== 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: 63aa3423-c2b6-422c-2fcd-08d58db105cc X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:48:45.8888 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0981 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Darrick J. Wong" [ Upstream commit 46c59736d8090e602f960aeaf1c6b8292151bf38 ] If a malicious filesystem image contains a block+ format directory wherein the directory inode's core.mode is set such that S_ISDIR(core.mode) =3D=3D 0, and if there are subdirectories of the corrupted directory, an attempt to traverse up the directory tree will crash the kernel in __xfs_dir3_data_check. Running the online scrub's parent checks will tend to do this. The crash occurs because the directory inode's d_ops get set to xfs_dir[23]_nondir_ops (it's not a directory) but the parent pointer scrubber's indiscriminate call to xfs_readdir proceeds past the ASSERT if we have non fatal asserts configured. Fix the null pointer dereference crash in __xfs_dir3_data_check by looking for S_ISDIR or wrong d_ops; and teach the parent scrubber to bail out if it is fed a non-directory "parent". Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_dir2_data.c | 8 ++++++++ fs/xfs/scrub/parent.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c index 8727a43115ef..700acc43289b 100644 --- a/fs/xfs/libxfs/xfs_dir2_data.c +++ b/fs/xfs/libxfs/xfs_dir2_data.c @@ -73,6 +73,14 @@ __xfs_dir3_data_check( */ ops =3D xfs_dir_get_ops(mp, dp); =20 + /* + * If this isn't a directory, or we don't get handed the dir ops, + * something is seriously wrong. Bail out. + */ + if ((dp && !S_ISDIR(VFS_I(dp)->i_mode)) || + ops !=3D xfs_dir_get_ops(mp, NULL)) + return __this_address; + hdr =3D bp->b_addr; p =3D (char *)ops->data_entry_p(hdr); =20 diff --git a/fs/xfs/scrub/parent.c b/fs/xfs/scrub/parent.c index 63a25334fc83..b4d2f8406d22 100644 --- a/fs/xfs/scrub/parent.c +++ b/fs/xfs/scrub/parent.c @@ -171,7 +171,7 @@ xfs_scrub_parent_validate( error =3D xfs_iget(mp, sc->tp, dnum, 0, 0, &dp); if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, 0, &error)) goto out; - if (dp =3D=3D sc->ip) { + if (dp =3D=3D sc->ip || !S_ISDIR(VFS_I(dp)->i_mode)) { xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, 0); goto out_rele; } --=20 2.14.1