Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2016684imu; Fri, 14 Dec 2018 04:33:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/WprZ4gFM0hHTrANCOcFNDReM6+zQT/LKmycImM2g5KeSnwuyjlTmQ554QaN1+1AYD6A+3l X-Received: by 2002:a63:6704:: with SMTP id b4mr2606651pgc.100.1544790825713; Fri, 14 Dec 2018 04:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544790825; cv=none; d=google.com; s=arc-20160816; b=JHonG3OqSfqFPo5Jwkpv+Uekr1PQKjFWfBkLJt3bqkoPLwQ8wjLU9LIpGVZePO/IGN PP9W1TmxPa2bIzT0Mon6p2JutDp/mYMbdzcSIm+jfgEVGwDHdsk4OT6DeNN3IsgXDdwD Cp0+/IjdGfPbV1pnbCe0oWrpMZKs8kuUIwecoq6RoBtbnghzWsSrza2UDlZYH01h4l30 EgMsrf2OJDcOSFyZ0LCr6s+oi/1/ely8jjzGbJ1JQWLRiWTjmS8wdwmX/bhozHWi/+eo RmltRLDbT17cRZiS/r0VLq9FhriBGp6XC7ZOU6DbQxCHF4vJIF5elnFikI+k5M+JnGLZ Ectg== 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=KO/p0faoCyCSWiuFtDHQ8nrjByZTzgBkhWV/DIMcw+E=; b=LVBpRNfhm181/sZq8CjIiJWbbzLac630A4iSMmFCzs/sOJZOrEPlfnpgL8WDOLJlZm CZT3TQ0qgvpJTwOOItozjFHs0GgjnsxMLvPCNObX1nlpjuG1lXhw7+NDL7dUU9LrVQBP WyKDP2VZ5NtlmVKk6THUOkU/XCeyET/cOSNERdlQyQW9n6VPzIw1f2mgvySarj5VN4nr 1DOjMCMjUG0vwDaTmMdWrgRaYRYKrOd7JK4fcobUdL0IQPaeIs5cla1NGpHHSNC7HW82 T9Br3P4vdlVdwUSy4VoTYjEK/CKfylztrekS17m8fn3hmC7hk2e/Md7RqkWN38JlMND+ 3NOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eo2m0ycs; 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 u3si3987978pgj.300.2018.12.14.04.33.29; Fri, 14 Dec 2018 04:33:45 -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=Eo2m0ycs; 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 S1731043AbeLNMb0 (ORCPT + 99 others); Fri, 14 Dec 2018 07:31:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:55446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730924AbeLNMJn (ORCPT ); Fri, 14 Dec 2018 07:09:43 -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 E1E78214C4; Fri, 14 Dec 2018 12:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789382; bh=mjchHDLhIi21CM8SBQVto3Z+iDaMXCcy/GCRgBM/KYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eo2m0ycsYpUiSJzsnuFKPic2q2CBAbO8JjbNXPxR5k0hnKXoCCoPn8VDYZc3osAXn J1Z2sLD/rL0VWs4MipkJ8cZAh4dbmHao293fKJ1H9J+gGYxElnIzTDaOw5n05hWfgn i91WBozCB8WR5Uh5vuNFvek2c7dTENIBSjNfgGEs= 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.14 60/89] cachefiles: Fix page leak in cachefiles_read_backing_file while vmscan is active Date: Fri, 14 Dec 2018 13:00:13 +0100 Message-Id: <20181214115732.637232860@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115729.658859279@linuxfoundation.org> References: <20181214115729.658859279@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.14-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 199eb396a1bb..54379cf7db7f 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