Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp797461imu; Tue, 11 Dec 2018 07:45:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/VfXH8lVe7a0dVXF72O1rKiEoiUg2K3B3himmrYLB90Z+IXc+FEP8LDziqF9gqSxJLZc1Bw X-Received: by 2002:a17:902:346:: with SMTP id 64mr16914629pld.337.1544543106717; Tue, 11 Dec 2018 07:45:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543106; cv=none; d=google.com; s=arc-20160816; b=fpUPf9dRYYFnfQh/p98NmQFEsxwRgqH00cfBrU7lMRcfXXSsYA1ZbYzz+DTZRLVAZc bCZoEW0o7+UeRT/cZlKKQRM0tK0PVPrpl2dmT35RjPOx5CfKLgOnySJKxiJxp7nvQTNd KFGEIufjWo0HmTvaMTtbgSxS31K7DelS2FaelQMotGtbon13ZRrkzJFnmuSNGm2UDQf0 mMcyHvR/mmmHWn2dNwXxz2OGo2cVO4csdoGceqcYLU8uLJlK6UyBrd96JpLakBZvHroC 2mvdg8I6uRqxmZGyqo8U7rXx0mUGxLMLUVf/JZ2Jq63XbeEvGbWjag4Rb31S2p6jx6Er Q12A== 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=usbjRWbK6J7PXqc0p07RMI7ieFYFG7fEoWBd6dqXw2c=; b=N4ueaxkS4+VAz2hyooF3ckANpqyflJRJJigmjUzEtye2V126CkRv8sISDTx4mAFkt6 E/8wo5psQ+PtaJxTszoG2Yy4L2MqIpvuOSMC+g408Fn/3Mn5dI7ub7OL62q50dk5LMrh CK9ZrLmFLRHkissSxSJJaGolRoeT1i9/hGCDVyNtapCrmLIdy1E65HwoRzge7Yqm5uJS WYt3SF27uE4m0B8DC39IExjJGyUvmbb6ksMkjI5bfNS4R3Ex29gS5dLaAoZj6Q5ufEAA i8FNJX1BEceYDDk3l9ma9MxfezrNnXBbQwmXyyU+Po1bW1JYOtByX8s3WxjTXrCTcg8g QejA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hQwoap2V; 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 c11si12446002pgj.255.2018.12.11.07.44.51; Tue, 11 Dec 2018 07:45:06 -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=hQwoap2V; 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 S1727087AbeLKPnd (ORCPT + 99 others); Tue, 11 Dec 2018 10:43:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:60024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727547AbeLKPnb (ORCPT ); Tue, 11 Dec 2018 10:43:31 -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 CC69520855; Tue, 11 Dec 2018 15:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543010; bh=JFmfTNeU0gbQQLK98kFKgM7/d274k7+X8ZwvEszv4/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQwoap2VGn2icnAYY2GNFQD6MT99cuyXNsAot20AglCWc70F/vaHIgKgqAC0qLqqL KUIEI47jYrXQzzd3VsibucKBvayGoVPc8wZE+ict4L5ZIZLv7goKNYFqXRDVvi6mgU llGRdF4QqCR5ZU8lZJyxLJSNOmQfATos9Z5OHKAQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Tikhomirov , Vasily Averin , Andrey Ryabinin , Jan Kara , Johannes Weiner , Mel Gorman , Matthew Wilcox , Andi Kleen , Andrew Morton , Linus Torvalds Subject: [PATCH 3.18 32/54] mm: cleancache: fix corruption on missed inode invalidation Date: Tue, 11 Dec 2018 16:41:20 +0100 Message-Id: <20181211151547.914570516@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pavel Tikhomirov commit 6ff38bd40230af35e446239396e5fc8ebd6a5248 upstream. If all pages are deleted from the mapping by memory reclaim and also moved to the cleancache: __delete_from_page_cache (no shadow case) unaccount_page_cache_page cleancache_put_page page_cache_delete mapping->nrpages -= nr (nrpages becomes 0) We don't clean the cleancache for an inode after final file truncation (removal). truncate_inode_pages_final check (nrpages || nrexceptional) is false no truncate_inode_pages no cleancache_invalidate_inode(mapping) These way when reading the new file created with same inode we may get these trash leftover pages from cleancache and see wrong data instead of the contents of the new file. Fix it by always doing truncate_inode_pages which is already ready for nrpages == 0 && nrexceptional == 0 case and just invalidates inode. [akpm@linux-foundation.org: add comment, per Jan] Link: http://lkml.kernel.org/r/20181112095734.17979-1-ptikhomirov@virtuozzo.com Fixes: commit 91b0abe36a7b ("mm + fs: store shadow entries in page cache") Signed-off-by: Pavel Tikhomirov Reviewed-by: Vasily Averin Reviewed-by: Andrey Ryabinin Reviewed-by: Jan Kara Cc: Johannes Weiner Cc: Mel Gorman Cc: Matthew Wilcox Cc: Andi Kleen Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Vasily Averin Signed-off-by: Greg Kroah-Hartman --- mm/truncate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/mm/truncate.c +++ b/mm/truncate.c @@ -457,9 +457,13 @@ void truncate_inode_pages_final(struct a */ spin_lock_irq(&mapping->tree_lock); spin_unlock_irq(&mapping->tree_lock); - - truncate_inode_pages(mapping, 0); } + + /* + * Cleancache needs notification even if there are no pages or shadow + * entries. + */ + truncate_inode_pages(mapping, 0); } EXPORT_SYMBOL(truncate_inode_pages_final);