Return-Path: 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 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 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> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: 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