Received: by 10.223.176.46 with SMTP id f43csp276278wra; Tue, 23 Jan 2018 20:52:10 -0800 (PST) X-Google-Smtp-Source: AH8x226CEHHnCNLTRYwGToJ9mW5vVJrng8NMoZVsvCrlFbhKlaRbqEgfIxOYQPxvNNXmBP70ztt8 X-Received: by 10.98.63.214 with SMTP id z83mr11677190pfj.95.1516769530353; Tue, 23 Jan 2018 20:52:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769530; cv=none; d=google.com; s=arc-20160816; b=0RJXqT4cehtciINTJSQchim4G0PXS75p568XNWPFpaAS/rsxAJVhLaB173sCkl47+4 0Z3zRoP8zA7SftlHwHflqNKh7KJu0OCB+Km82CdSV2FEK8q+hu1/bPZKUnjoqOoXNmJM SZ4l7QIkR4JF8xUJ5RBUCcsJiui3qdhpWxA+lvkqelllqBGJ8OP+5fsHQtTUcknOgYei hr5fOR+aoTzMXpd06xm5jezVu+qOkE9koggTDoebbsEdvgsKKIJ13pOQAgz/w4F1TN3R td1mFU38mhFvPcaDygSr9huhvTx5nmjTX8gyVUTaniZ85oo03cYmykGDxsCW90jZF1J3 RP6A== 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=38IrIFzTKw17Dfn9+H4llAKDGXdZEG8ZCX+6rTpxXLI=; b=NrD2r4dQZ9Y/h+HtOHW+fjPyQN/7xsKJh8hVTMiL9vEPziWbOH4I5dG+DtwDV76UUm SWhZF7wsL50jE6mbjxWC96VVoggMykURRUk18xkdkTSQrL/cDjCNFoHYcyJxFajKTgdE 7QSN3SZz7KP8/vwy8QKiAP1JZYDNkikKcTrq730rFgMWAnasROg8iF2ZQHy/sgpujgpP S69F5LnNgFwYtA1A5BNg/2aXCivHOT6cddZDECbChfYndMoDstgtyCJJVK0OsLwkGiso DV2LQaB2YYgbhm1cQWftdhpaLauPO4cSen5m4u2lsW/2x5wllzsv4JjbrEfxfGQB/0eZ cooQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=bqEv6LNj; 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 y92-v6si5533963plb.584.2018.01.23.20.51.56; Tue, 23 Jan 2018 20:52:10 -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=bqEv6LNj; 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 S932779AbeAXEve (ORCPT + 99 others); Tue, 23 Jan 2018 23:51:34 -0500 Received: from mail-by2nam03on0117.outbound.protection.outlook.com ([104.47.42.117]:41259 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932466AbeAXEQD (ORCPT ); Tue, 23 Jan 2018 23:16:03 -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=38IrIFzTKw17Dfn9+H4llAKDGXdZEG8ZCX+6rTpxXLI=; b=bqEv6LNjQbdarjfOCCCaIhhWeUFXZp4I90zWBU+mai2s8Ln1IT+kNJzq9l6H/0rMu657BNZo2vwQcXShdGEHHCFiofHjTdh8JwYD7PRb/Os4OmqU/Z9a0FeiP/yn/+xzVgEe1LVywqcJQm0/zvYkpkH0QxH6JaMomDGnbqve1So= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1078.namprd21.prod.outlook.com (52.132.130.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.1; Wed, 24 Jan 2018 04:15:57 +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:15:57 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Michal Hocko , "Darrick J . Wong" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 071/100] xfs: fortify xfs_alloc_buftarg error handling Thread-Topic: [PATCH AUTOSEL for 4.14 071/100] xfs: fortify xfs_alloc_buftarg error handling Thread-Index: AQHTlMnnioU5zE4hNUKIqD50nad2dw== Date: Wed, 24 Jan 2018 04:15:01 +0000 Message-ID: <20180124041414.32065-71-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;DM5PR2101MB1078;6:aWLgiGseqn155yh27VWg0/LxbflNE/q1bMbsEXpC/vg14spnY5KqULDDJ/1yE0bv4dnUrNj3Z676eLKsooioFQ3hb47U9Gs6ZKVKFnzBvQrDKzVhPb3kw4toCorKELtvMLH+EaS0cVLNFG3JCuQS/oH1oViLKUhvzzLxhqyNuk9Ijw/X1+72Y0mHLR/AXvg6tZ9U6neoYf8P2rbVLMG58jZOjsKO2LpYevhz7iJPbkWBImEXOYs4lnnUd39CoEbl7qPVoNMFlYZ0pC53jqx82tBt2cop6KZRb4Fc9hfw639F7Y7G4NQFujSVBNtG9zAq8cMiHp4/y3fieJtJqo3kg7gQjqT6QqLZwZAkjHEuI+munp/6n6bfn6zbblWYa07p;5:NF41aRLCzqC6+eDgiYliQXPhRSANlZrCtyvIYy3fYj5qDJtjiNuPl5j+LrLyHZVix9PKAVpyALkpm/LzfYjobkq1uvj9tN9P12+KDyApcHdQ9SMmo7yyh5EmHUgvoZ9F+tUSkqCARBwOYtusXE7azP3lkJhlyL2n3gIzkHrAD5I=;24:GU5lfQFxC5Dif79910fH5tSLgaMB2gyO7BlM6ywLnKu4NvuB8D50n3BioUWWFvTfudQxM+jyQ4mzXIiPTmF8l4HJp2BlzkJbI3TxJXYs3QU=;7:SmFjjFcT7ViMz2lCLlv6RlDdruX3HO7xDyiv1qdO0cDUYp+5eU9rE9r/OfxJM1pBfSOI8g9pm6QWNeh6rL4T7KwnRukBtqeXJu+ThPdq8/UdlvvD54nbwd//gsnUHURGvW4qW6jmAaLNQSKzHAy1VkRSw4qISiDAn1KPnifJcUvJAuZAkUKET4N0JNHi22YgjAAziijQOzSHpcBv73nCBaKBR5vE3fn2Yjb6+nfJBZNO/jFJhavSK46zN/thR3Dm x-ms-office365-filtering-correlation-id: 5d588415-6ff0-442e-4973-08d562e12b1f 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:DM5PR2101MB1078; x-ms-traffictypediagnostic: DM5PR2101MB1078: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(274141268393343)(89211679590171)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231046)(2400081)(944501161)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1078;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1078; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(376002)(346002)(39860400002)(366004)(396003)(39380400002)(199004)(189003)(86612001)(22452003)(6436002)(106356001)(107886003)(102836004)(105586002)(305945005)(5250100002)(2501003)(14454004)(3280700002)(4326008)(7736002)(97736004)(59450400001)(6512007)(36756003)(8936002)(2950100002)(3846002)(6116002)(6506007)(86362001)(54906003)(76176011)(110136005)(2906002)(6666003)(53936002)(66066001)(72206003)(6346003)(5660300001)(8676002)(478600001)(10290500003)(68736007)(81156014)(10090500001)(1076002)(3660700001)(25786009)(316002)(2900100001)(99286004)(26005)(6486002)(81166006)(22906009)(217873001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1078;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX: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: gQomGEhcOH/NJqoOFvgDTmp1ezyWo7EMJ2Y5DDeeNY6MlCFO5Q+2qHC746sIPKe0J8fSGpyky5b/XfA034JZVQ== 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: 5d588415-6ff0-442e-4973-08d562e12b1f X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:15:01.3990 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1078 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Hocko [ Upstream commit d210a9874b8f6166579408131cb74495caff1958 ] percpu_counter_init failure path doesn't clean up &btp->bt_lru list. Call list_lru_destroy in that error path. Similarly register_shrinker error path is not handled. While it is unlikely to trigger these error path, it is not impossible especially the later might fail with large NUMAs. Let's handle the failure to make the code more robust. Noticed-by: Tetsuo Handa Signed-off-by: Michal Hocko Acked-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/xfs/xfs_buf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 2f97c12ca75e..16f93d7356b7 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1813,22 +1813,27 @@ xfs_alloc_buftarg( btp->bt_daxdev =3D dax_dev; =20 if (xfs_setsize_buftarg_early(btp, bdev)) - goto error; + goto error_free; =20 if (list_lru_init(&btp->bt_lru)) - goto error; + goto error_free; =20 if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) - goto error; + goto error_lru; =20 btp->bt_shrinker.count_objects =3D xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects =3D xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks =3D DEFAULT_SEEKS; btp->bt_shrinker.flags =3D SHRINKER_NUMA_AWARE; - register_shrinker(&btp->bt_shrinker); + if (register_shrinker(&btp->bt_shrinker)) + goto error_pcpu; return btp; =20 -error: +error_pcpu: + percpu_counter_destroy(&btp->bt_io_count); +error_lru: + list_lru_destroy(&btp->bt_lru); +error_free: kmem_free(btp); return NULL; } --=20 2.11.0