From patchwork Thu Feb 2 20:44:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp464114wrn; Thu, 2 Feb 2023 12:45:51 -0800 (PST) X-Google-Smtp-Source: AK7set8hrs4Hm7e4TkVu891GqExaLh7EvqDuwvwR449JuM1pZAjxkc8r8zXMO2IC8eHJm9Zfb/bu X-Received: by 2002:a17:90a:1904:b0:22c:504a:dc76 with SMTP id 4-20020a17090a190400b0022c504adc76mr7700361pjg.41.1675370751223; Thu, 02 Feb 2023 12:45:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370751; cv=none; d=google.com; s=arc-20160816; b=js/LhcTXZY6XvT3/sazMYrqRWqhJpoVvvReFSC5yAlrL2qUwAEc0CrFvQlYVRHyAag tpvrBe7RQTLpbLzxQrvGJS4uOlRzp8S1Y5Kha9XhxB7rDTOn+0xGcbHx/hJvxD0yjQ8I 4SXbapN1zNVgJqkg04HgAxbLbzLRFg+AARHAHT70NrL5jcMrjN3Maw+3KGSNOYw7YpsQ iiqEGFNuH/GZK5CtMZBkhjvESxeofFLRr/XwvRjdivnk0wpXmKvXFFq7de0sORPYFRYF ULpTST85WDvkKEDEByz04o1fPq2j4i72hcpC3vONPbVgoVZq1WXbJsTw29Eoby7aef1y EjVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CHTViCFku/KBgg0p6DZbUUb80eMrbMHO+BwTMmLL/c8=; b=k2ohFY2G64I7V2PftZqxjbPNU/GKAzYAE8G/4+QSnBcULvgsFxGjqZcI7rvVKkZ7PY XqyjGINGc91UaHj9pdyCHCLrKJO1PJz/AYjUuyA1yPuQEWF8UDK6PtrgBSEoBuhB10mp QtsNU3ix2cFOXk+LrM4ga/VraG8dq+o1YJ4xXBWQ1709R29lVGeQpyS3czIgWy5Iznra TgZfyUFtMeV8NRxzm5n6+hqzgKjAMpb3pVyq8wptGh/V13K0lIMP5ujk3Bmgxe4BZq4j kvGneMER7neNQlJSF7cCIK2edROZSvLbQk4sfdgooScV20+LwmvobzYGYwkIvDoBtNYs bo0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Cnpe1akX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020a17090a850500b00225c1d3a26asi5404942pjn.110.2023.02.02.12.45.38; Thu, 02 Feb 2023 12:45:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Cnpe1akX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233009AbjBBUop (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232067AbjBBUof (ORCPT ); Thu, 2 Feb 2023 15:44:35 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C74C48A58; Thu, 2 Feb 2023 12:44:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=CHTViCFku/KBgg0p6DZbUUb80eMrbMHO+BwTMmLL/c8=; b=Cnpe1akXRcTjrbOFxM+9HrW+ur d1lfcvyzmUOAlYVR9x6xYmCbrq53KnUEe+yqtSAHOPbH7OHm0rewQg2RMYzAmtBFcYZE4oSeqLxMi eCHHJ8dFrq4kz9d/JcMQzW5XpXnfBUje4e46WGl4WZgLZJBy7/sDkudm3R/iXLIpz5Vh7F5wllJ7I OUkIXT5U0OkITUYHT6Dd+ODvKs5q3qcDfvn3fcX5d53emCWIimY8ED0Y5esijwiT7AN7seZkhU+G+ eFufWstFTegm87OA4SkZuEQOD6F1ZgjDbt9nNJNndVfqGOf533nK3ibsN/iH0hY3EkdfhgfQTwKHm GPQu7rFA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRa-00Di7O-Ue; Thu, 02 Feb 2023 20:44:31 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, Hugh Dickins , linux-kernel@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 2/5] ext4: Zero bytes after 'oldsize' if we're expanding the file Date: Thu, 2 Feb 2023 20:44:24 +0000 Message-Id: <20230202204428.3267832-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230202204428.3267832-1-willy@infradead.org> References: <20230202204428.3267832-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756753561099590733?= X-GMAIL-MSGID: =?utf-8?q?1756753561099590733?= POSIX requires that "If the file size is increased, the extended area shall appear as if it were zero-filled". It is possible to use mmap to write past EOF and that data will become visible instead of zeroes. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext4/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9d9f414f99fe..14e3fa99f733 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5604,6 +5604,7 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, if (!shrink) { pagecache_isize_extended(inode, oldsize, inode->i_size); + truncate_pagecache(inode, oldsize); } else if (ext4_should_journal_data(inode)) { ext4_wait_for_tail_page_commit(inode); }