Received: by 10.223.176.5 with SMTP id f5csp1026628wra; Fri, 2 Feb 2018 09:56:46 -0800 (PST) X-Google-Smtp-Source: AH8x226q+WNHHk5S7TDGJBGF0GgYcZWIt1s0Emds3udUJXsrerS4bgiYTsANxbLGQB6WFrocLVe4 X-Received: by 10.99.167.75 with SMTP id w11mr32712373pgo.215.1517594206443; Fri, 02 Feb 2018 09:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517594206; cv=none; d=google.com; s=arc-20160816; b=AscE3mT9sC0g6K5gL7uUQxGD5H2WqNrvk81suartgoo1VOZCsszSVhFzZ7VYyFsMfa wOIz7/gT3Q2PcK7N6YxFU7tiv/QVe0mzVjwcolojzyIKToc3FYoqTbF7CYLYtMrcZi// 9Q/Vv681IvUqKvMC5BtoqjFT46fYXlhARzdKP0lrj11DGdfLYQf+t8Sfiu95ebTfIW6W dMES3sUdXmvD5wKe3ZgfJQmWkEgB1GbnVUVP9uy/S3Iyff3vklm7kfJh82ILgC7kEH8y luIoyeH+eqrQbDEDLJnKAiXtdxf44EPkoHTR0R4sWDwIeim1FUygBIWpObk4qNeuKQ5f MrIw== 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=zaKbRa+T4U0XzoW8jaMvirD5R7lkbeG4spSOCb4/o38=; b=bVaMFsj0EluMBUxbUIACHkgwqlUOeb1YeeJkZcJnI4bQUYlXu9fy3aq1JBpimPPvsJ RXrQ1NIVxEBFUrVwMhgEUxbQehoOnSPmQtWsrtx6Cpe/64j2pYcCSHAkZZrGLN44hjv0 Cuc9+FKJvhqLGnFtozpdyhhXQNJYrz6v1zuCN5C6obulFE07QNuez9IxGP7oBdIF6WuL qKc3bZ1iZPgzmL48P/Uh0fiDyKPhMIpzAH+r1Pa+65zm7/mMtXVDKbJii1A/r5+s8FEK VsqdmE4Vh7kR1lTW8J5fhaaMlTc7c8XR7leXt055HUECKWh8o7ZdQsC+/KvFaSyKO52X Yk7Q== 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 w2si1695775pgp.680.2018.02.02.09.56.31; Fri, 02 Feb 2018 09:56:46 -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 S1752693AbeBBRzc (ORCPT + 99 others); Fri, 2 Feb 2018 12:55:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38688 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753125AbeBBRLg (ORCPT ); Fri, 2 Feb 2018 12:11:36 -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 67842F0A; Fri, 2 Feb 2018 17:11:34 +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.14 098/156] xfs: fortify xfs_alloc_buftarg error handling Date: Fri, 2 Feb 2018 17:57:59 +0100 Message-Id: <20180202140844.647380902@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@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.14-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 @@ -1813,22 +1813,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev; 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; }