From patchwork Thu Feb 2 20:44:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp464636wrn; Thu, 2 Feb 2023 12:47:06 -0800 (PST) X-Google-Smtp-Source: AK7set8oBTwup9Mo5s43EqtRokR9D7X0c1Z+3ml34SDjalpU7QOp0KMGjxqVD9l7PPB0O1kJxXN0 X-Received: by 2002:a17:90a:34b:b0:22c:6b8e:1ccb with SMTP id 11-20020a17090a034b00b0022c6b8e1ccbmr7763332pjf.21.1675370825734; Thu, 02 Feb 2023 12:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370825; cv=none; d=google.com; s=arc-20160816; b=wrL9Sas7dpoXEdcwZW3lF9v76BsC4GoXX2vvGCsDVMkTiK1XtLqWHsLfNTgOLb1DRh gjTjYrv0MeoCTSeoBiP3qUML60Rr7TMFERGsA6QBABfHJCQ4L9RRZ0XZhJ3WZCJIfNyp U6JudDSmp/VcarUiDjAK2vNBhrzfunoQDyQDU5AZ/xa6GurxGbwQ8p3K/9QjK+5P2iNk uETYGnBdiD9sZ0x2j486hkBK3S54YWRc5v7iJjYd0Mzx7oFRTLwRe7T9e8iBp67xmZel HQxdzU914XRd+rzGfN6q7VliSOraUFM7+eUUe1Y3mUfiM7xwu3rqlaMih6VIYa+N8tSj 4+ZQ== 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=3DLfbYeltsUE3NkYQxzmRoc7Gye1xXr71K3DBJBtYI8=; b=eJ0mKwDsjYhQJJc0zolUL5B00Fvv5/H8y7FOMW6t2UdrFkdL35LDKVEF0ACoBB3A7I XAkiFJWwPrdpV+J16WwfTACfCSkenOC8Az/ypZAQhbJUUyvbZh3tDNUv5O6QjrbedrTh nPs0Fr9lULr85JXvuh+x5c/gzqq2aslWdjAIdugdOu2//2h/rtpbdR3msDF68EDrtJKZ ZSG8AxgkrDQZdmmHwNfOA81mTN9GKYJjtZbvHuTk1cyYDzOtVSsH/pZ0bQe8UydhWfXy 9QWwmYbVMn0VpLqaMwPvL8c3+1T6tesbuUl3Syh+CAMkvcZkIvs5jtYp51iMYstMGrxY AtCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=My+pp2jn; 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 lk16-20020a17090b33d000b00213ff43fdf1si6150871pjb.185.2023.02.02.12.46.53; Thu, 02 Feb 2023 12:47:05 -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=My+pp2jn; 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 S233060AbjBBUov (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232111AbjBBUog (ORCPT ); Thu, 2 Feb 2023 15:44:36 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C76919EEA; 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=3DLfbYeltsUE3NkYQxzmRoc7Gye1xXr71K3DBJBtYI8=; b=My+pp2jnzUtx0mU74aDrHBAfVv 47t6HILhQnY1KaWUmZhAh5Wqw/ZzWZ6ELcjVHzxBAaJVU/zPNhUYV+Oyu8b8NUlzlznAT7362AF5Q gSQhH0el02AH+zggm7MaQts0TQfCLVs/ET3zZFTx6kLY0UFy7JiwRH5IpJXhmrrpwqnp6dChipQdC PEYc0G6v9HjbUwlt4SWnW8UNsQnyNapLR7lOnkWFSFia65JmJyVQlKc6deSxOSY62WoNxa79NTi5h pyqzpXh91k9bcb2gbuVSWm4A6vmNmeqVjxhn6iRYRNaJwId/QFcOjPBC/JShhXajsyYYE1HBY8GMI sUEu9Ryw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRa-00Di7L-PL; Thu, 02 Feb 2023 20:44:30 +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 1/5] truncate: Zero bytes after 'oldsize' if we're expanding the file Date: Thu, 2 Feb 2023 20:44:23 +0000 Message-Id: <20230202204428.3267832-2-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?1756753638700853729?= X-GMAIL-MSGID: =?utf-8?q?1756753638700853729?= 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. This fixes the problem for the filesystems which simply call truncate_setsize(). More complex filesystems will need their own patches. Signed-off-by: Matthew Wilcox (Oracle) --- mm/truncate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 7b4ea4c4a46b..cebfc5415e9a 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -763,9 +763,12 @@ void truncate_setsize(struct inode *inode, loff_t newsize) loff_t oldsize = inode->i_size; i_size_write(inode, newsize); - if (newsize > oldsize) + if (newsize > oldsize) { pagecache_isize_extended(inode, oldsize, newsize); - truncate_pagecache(inode, newsize); + truncate_pagecache(inode, oldsize); + } else { + truncate_pagecache(inode, newsize); + } } EXPORT_SYMBOL(truncate_setsize);