Received: by 10.223.176.5 with SMTP id f5csp1050491wra; Fri, 2 Feb 2018 10:18:15 -0800 (PST) X-Google-Smtp-Source: AH8x224TykiRnUHLvII14JuGVZeLiw6CccG2P2e22ZG/QnTPKsAmam2euVugLBWwejrFD+7HFGGJ X-Received: by 2002:a17:902:7b8f:: with SMTP id w15-v6mr36524815pll.219.1517595495738; Fri, 02 Feb 2018 10:18:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517595495; cv=none; d=google.com; s=arc-20160816; b=tqf/6QuYCd9ib2Xh46gPbKmneQktWcmqfCnpYfvEVM4ocwHJD0AGCFpZIXf11Tw0yf WR6GbffUGjzv1ww1kxGGX4deVeYDey5UkNYK/S3izUcrylZ+He7biTQ8d0v0B2dPoNmc g/mmYlr//tVCbIG5xAZxN+oK4NUPqi24Jjul9l3SPGaBogn6s0B6pP8JaVAmhBJ5jfL+ HZJz7idqBDsQtpSopsg5GGcxtuIRpQnStETBFDLvS0rr97A5IGLk0+BZi8bdInf7kS1J bHbhCtN/LpQQJASqadpnkUk2pqvkd+n/DFHKhfymj2SpJ9Iy7arzQx+5q7m5r17sBVDg 6XiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HN3k4TMW/LH6UZfMxbKQckVtrt7WsPLEg6RzCUiCAUQ=; b=YL7smOZrK4U3U3JwNcizvOHKgiTjkTkiISezb6tA+uXxUjl5nTtqsAXdvF7VG10N5e iVuCjkw7qR2E84rTemUBgltgU2/yu7Lae+88iY9KcNK+yE/Bd12FvQxYBzlzX3/mLBzS b7owWIa6AU6+oKVrlyapgt281knH3XrxxLWb4w4kx49y+ruTAnMpdr56LbuRQYSQ/plC LSl9hHQjAfNyzSAmvf/jNIaZor3h6mZlpdR6/Hykf8Jzm/UDkIO2YO9WtmJe0witZHNi Vv+tIEYvXxEHbCdUAUjghN6ah1uTgqxA2Wb8gAqUzMnmG6lgqH5nn4sG3/gDa5Wfc1gN +nZQ== 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 w123si2247709pfd.95.2018.02.02.10.18.01; Fri, 02 Feb 2018 10:18:15 -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; 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 S1754279AbeBBSRA (ORCPT + 99 others); Fri, 2 Feb 2018 13:17:00 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36396 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752957AbeBBRFK (ORCPT ); Fri, 2 Feb 2018 12:05:10 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C6AB8E16; Fri, 2 Feb 2018 17:05:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Hocko , Dave Chinner , "Darrick J. Wong" , Sasha Levin Subject: [PATCH 4.9 48/86] xfs: fortify xfs_alloc_buftarg error handling Date: Fri, 2 Feb 2018 17:58:08 +0100 Message-Id: <20180202140826.688891482@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140822.679101338@linuxfoundation.org> References: <20180202140822.679101338@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_buf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1785,22 +1785,27 @@ xfs_alloc_buftarg( btp->bt_bdi = blk_get_backing_dev_info(bdev); if (xfs_setsize_buftarg_early(btp, bdev)) - goto error; + goto error_free; if (list_lru_init(&btp->bt_lru)) - goto error; + goto error_free; if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks = DEFAULT_SEEKS; btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; - register_shrinker(&btp->bt_shrinker); + if (register_shrinker(&btp->bt_shrinker)) + goto error_pcpu; return btp; -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; }