Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10791081imu; Thu, 6 Dec 2018 06:53:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/UGki5J/iJgfYQCgBksmlVcOKUVPAfSQwc6UiBMOn8jOP6U90pjhgq6DhuBu7ohwh8SwNRt X-Received: by 2002:a63:ef47:: with SMTP id c7mr24648184pgk.386.1544108009181; Thu, 06 Dec 2018 06:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544108009; cv=none; d=google.com; s=arc-20160816; b=vp3KuWkEtNN7t03hpjhiIlI+0m7vlMnmUCqqprIhlR4yecqm1AeTlEpy83lZHzZ4yW z6VZp4QBgd7YA/UUXhlpkvCLxgOeTpogW6Wibt+HD+nvLpFqhFeRFT8zKKp7B811D8wC qGMzGmj2DU1Ee5kcPBifcdY2PFdOp7COsEy/6FQqrzx5O9Z0KaKAalj0obfwom47b0ME tWOYF8KlM8EEbo+9zO+rh60RMAM34aG29g5opnyWGsPLfuSmCKF2JuYk6ePR1BbuG400 o9KQjd9jQZvympChDf5FBIi1j24ZUAuZtRSO6az3grHSsN/h0quxb7+Pw9ri7NS8s7VX lawQ== 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=IPNzASyrFDm+Vdd1kGfM/CVIPO1NAK3/Cwzuo2TYBhg=; b=I83MEjp8quFernT64YMZlFJs252zpujgrayoMkJAcIFpzvtw05HN3hJIrEGTs8afAZ TbX0h0refICQiRAZEmI/i/MIULFt5Rnf7ZGaS2tO6Dj/9p7VvULQkKG02jJrTSu8CsRo J27YGaw7x05exO5jTsgFuyye23xrgLTpJLtIgvO6rHIrwS5mQEuRtxKSWd289czZFrLv Ehkr7s5m5IIt02q5eW6Tq0RfMw2uhOEMVZmyNHR60AdqHOQxVA4WdcIu3NWxFy9qAZMH rbvkPahBNXWVe1leR3dQTl4JoB1trfqbQaSp7VfQppdCo5jrRcmTZyic2LXXYc+OJdW7 ci2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lMRGZm2o; 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 x5si390466pga.440.2018.12.06.06.53.13; Thu, 06 Dec 2018 06:53:29 -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=lMRGZm2o; 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 S1731394AbeLFOrR (ORCPT + 99 others); Thu, 6 Dec 2018 09:47:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:52048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731380AbeLFOrM (ORCPT ); Thu, 6 Dec 2018 09:47:12 -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 60EA720661; Thu, 6 Dec 2018 14:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107631; bh=CLrj/deo3JVwPbu3+SJaODbAGj13X253vJY6pmx3Prg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMRGZm2oCC8Hi/FYGd86YI9WTKFtdzBwTcJ4LhC9K5d++Y3PQew6lGy7149EC0q9m Vpk9Zqdiaa/LR8bZm+Kp7jxCaT3wAXI98HzKWWx3uJ4gj/HG2yYW68qq25DjRH0euU Btq92rh0y4f8ajmgsCg6d/uvFY2k1mvyEQK/Ks/s= 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 4.9 044/101] mm: cleancache: fix corruption on missed inode invalidation Date: Thu, 6 Dec 2018 15:38:43 +0100 Message-Id: <20181206143014.057240257@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@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. ------------------ 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 @@ -443,9 +443,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);