Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1995393imu; Fri, 14 Dec 2018 04:14:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/U/hRlRXIi7GQgtQTXbfWKPJqvASYunW6jFnxxa/zUaPcSw4Y/reHAN80yuM9EbWizu+n3v X-Received: by 2002:a62:de06:: with SMTP id h6mr2697991pfg.158.1544789642559; Fri, 14 Dec 2018 04:14:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789642; cv=none; d=google.com; s=arc-20160816; b=sw9CTS05+xgDm3nyS0JGW+qku4l7oCX0pAY3F1htAZcijUZ/3OF/iJmioPXwjMMHhq wHpXJxbx4cgNzvRWbu4PFova1P6t6d8FZGpcNqVvhAiCUZx7/T2EfgyM3GMZoaehq8t0 y7wfo5kzO9jLU7iZvOQG45DHSpbHldlSLqsoEdwKp6szbz+2EN79Zgbyt+c1s+wq53Cg NXEvwLOnT8thdz02W1zAhhNSZacXb//E0JPm+3MvYmmTXzCMbBcOmVjkRK0vn9bsvrZR nXOcrli/Ua5A1ZtKxHS+wtbGX0DHe9lYY3p12PBL2y+98WOFZXIKzOUng1fFcKOrkY7d CC5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lrO80L0wgRBp2uCkPNLrH9sgf1+KwGUXoY5kX44MdGY=; b=mlOALqLBtZoD1PeftmcaO9lfqW0rKj5s0HP3sH10soCzbNCqg3VcxYnIC1qd2yFwWw p/vNkORlg89ycxyjE3c2FL6f/OArtZv9s8n3Ohspr0zFAlAWqj+cPgzO9qquKXOkZSgV XHrjjdaIb9PRS2dUclc7+oCl23Qw19MDkcCDrAhG2UEDH/q1dhNPWvQ5XGXehr/q8fyq vv3zcAawahbImC0Gh5uajtissvxbUlrOWbdLc41wf4PpIYwO37rf6i0/kvEw1bG+w24x juDFZDfao4ZtmExZr4Z85BsZRseFoCVLLQANEooqZ4tSAt2TEPGcNdJ3/5k0qqmuANM7 Mg9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ibR7tBWf; 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 j70si3747130pgd.138.2018.12.14.04.13.47; Fri, 14 Dec 2018 04:14:02 -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=@kernel.org header.s=default header.b=ibR7tBWf; 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 S1731975AbeLNMMh (ORCPT + 99 others); Fri, 14 Dec 2018 07:12:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:59768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731731AbeLNMMe (ORCPT ); Fri, 14 Dec 2018 07:12:34 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2FB332133F; Fri, 14 Dec 2018 12:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789553; bh=pNt/MnqlVWqKNC6/6twPQBAIKPcA87P8OFW80F5vi+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ibR7tBWfKXZcEi3jFMCDeKDVu2xuSDt4C2rsTA0LwTFt7AIWf0cZJQWFd9z+XalSe 8jjdh/BJDnEkq7UXkjb9dH5fJiL4rmBLX/DFqm4L1UvqYjOlI6tbx5tNbQNRdhcqwz 4yN0d/J6L0JKu7/faMVg2gwLD7InCiBRE5CQ1ils= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Axtens , Shantanu Goel , Kiran Kumar Modukuri , David Howells , Sasha Levin Subject: [PATCH 4.9 37/51] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active Date: Fri, 14 Dec 2018 13:00:39 +0100 Message-Id: <20181214115716.476269131@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115713.244259772@linuxfoundation.org> References: <20181214115713.244259772@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. ------------------ [ Upstream commit 9a24ce5b66f9c8190d63b15f4473600db4935f1f ] [Description] In a heavily loaded system where the system pagecache is nearing memory limits and fscache is enabled, pages can be leaked by fscache while trying read pages from cachefiles backend. This can happen because two applications can be reading same page from a single mount, two threads can be trying to read the backing page at same time. This results in one of the threads finding that a page for the backing file or netfs file is already in the radix tree. During the error handling cachefiles does not clean up the reference on backing page, leading to page leak. [Fix] The fix is straightforward, to decrement the reference when error is encountered. [dhowells: Note that I've removed the clearance and put of newpage as they aren't attested in the commit message and don't appear to actually achieve anything since a new page is only allocated is newpage!=NULL and any residual new page is cleared before returning.] [Testing] I have tested the fix using following method for 12+ hrs. 1) mkdir -p /mnt/nfs ; mount -o vers=3,fsc :/export /mnt/nfs 2) create 10000 files of 2.8MB in a NFS mount. 3) start a thread to simulate heavy VM presssure (while true ; do echo 3 > /proc/sys/vm/drop_caches ; sleep 1 ; done)& 4) start multiple parallel reader for data set at same time find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & .. .. find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & 5) finally check using cat /proc/fs/fscache/stats | grep -i pages ; free -h , cat /proc/meminfo and page-types -r -b lru to ensure all pages are freed. Reviewed-by: Daniel Axtens Signed-off-by: Shantanu Goel Signed-off-by: Kiran Kumar Modukuri [dja: forward ported to current upstream] Signed-off-by: Daniel Axtens Signed-off-by: David Howells Signed-off-by: Sasha Levin --- fs/cachefiles/rdwr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index 5e3bc9de7a16..8d43306c038b 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -537,7 +537,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object, netpage->index, cachefiles_gfp); if (ret < 0) { if (ret == -EEXIST) { + put_page(backpage); + backpage = NULL; put_page(netpage); + netpage = NULL; fscache_retrieval_complete(op, 1); continue; } @@ -610,7 +613,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object, netpage->index, cachefiles_gfp); if (ret < 0) { if (ret == -EEXIST) { + put_page(backpage); + backpage = NULL; put_page(netpage); + netpage = NULL; fscache_retrieval_complete(op, 1); continue; } -- 2.19.1