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); 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); } From patchwork Thu Feb 2 20:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp463974wrn; Thu, 2 Feb 2023 12:45:33 -0800 (PST) X-Google-Smtp-Source: AK7set9zEH0sn4QoORKbiNHoE/u9PvrMw4AdV7KlMlm2AIFQcEBrr7U0r8wfQw/+rVFqQsUbn8tX X-Received: by 2002:a05:6a20:bc96:b0:be:39b0:42e0 with SMTP id fx22-20020a056a20bc9600b000be39b042e0mr7116146pzb.19.1675370733295; Thu, 02 Feb 2023 12:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370733; cv=none; d=google.com; s=arc-20160816; b=c7rsDYcywU6QXQ3cdJPGR2in5ZLNLQGkyUqeePhkm75u86mkoY4RBB8kX6O+uzFcbs ceeruxD0bSN3fHUTqCwoCaAm1JXpwi6Z/kMxui79gSOdFMFbdAqARiBzB96vmxRUafA5 pQXSDkEvxc/Pj2n1ba0JO6qKZ6PHh8ExKam6ZWW9essoepNmnSBZzneF0L9PcoRoHtnV 8tKLm5JSDihpwGD01fhewhOF9FrOZE/Ow4UjAtzHIHJSeQ7p5HDBwGqnwvdVwwjKupca fGc6ZWR2SoGHj1GIum++3EPM3Y3L/C6gR1k9dKixXLVeVbRsnJpiI676SUBe3+sOwCuP 5UAQ== 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=7vw66D2vDIhBX9oEFJWgWei9pEvFRsbTDrfadEvnVH0=; b=WRca0+gez7KYFHw7zss50gHYcCwTB7nhaTXU73+FM02a/a/TnzIFBFvKXCjhpLabol oiTsXPnQE2U8cB3THFh4rRrXwbTnYAUaxojR5j/Scd2uuDvFHMpjWbdlgspf9BtmI59x 8pv45X0Ehp9D51zq5sdkLMQaSjHxngvzEuCbt+4/yR//5qS81YnypB6YvGJmIscXytmG cB3k9Wd61SQxxXzZb6SCNFzmge+SQHVHJKJndvJ0E0Eb7qEQku2AB5rRFvUDXqW5ikrd 9HWZ5x0hm/6nr8K+vLFn4+yfIZ9YMuWNVynLGWGCqSQmQ2N7WCBPqVEbfH51+1RzzUFW gRqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="LI7K/fD5"; 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 l2-20020a63be02000000b0049b262ac916si603865pgf.566.2023.02.02.12.45.18; Thu, 02 Feb 2023 12:45:33 -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="LI7K/fD5"; 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 S232959AbjBBUoj (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbjBBUof (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 C4F7746A5; 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=7vw66D2vDIhBX9oEFJWgWei9pEvFRsbTDrfadEvnVH0=; b=LI7K/fD5Vk/tdkvyGHcHCHPIn3 ki8YM6I42VIZSzQNTxPrzW20eQcMlMiBbgoAoAw8253XrGoeMklOlEKMUxU2uC2X6XcBepRXQM2wQ YATyAgvwBIxy4fzWAmTKtS8Uj2OY3SvCwtjfcCu15kPUtBjNTOq46bndEOSVGF8Ub11cNCBl93Vg9 SWkM5MsQ0M+rvDWlwv+bSz97kX6B7VYPTSLxZ9dgDzRfutfB6502mkCo5mEQs0xsV8HA8rHlCRSdS KOTUidRSNdF7Zes+5Cdj1siYfhphWwyw25V0So6hp97947mMQ7zwQbXNCDbg4RdAq7LzH3UQO0x0G oB6KKg6g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRb-00Di7X-Bg; 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 3/5] tmpfs: Zero bytes after 'oldsize' if we're expanding the file Date: Thu, 2 Feb 2023 20:44:25 +0000 Message-Id: <20230202204428.3267832-4-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?1756753542142230666?= X-GMAIL-MSGID: =?utf-8?q?1756753542142230666?= 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) --- mm/shmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 0005ab2c29af..2c8e8b417b00 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1124,6 +1124,8 @@ static int shmem_setattr(struct user_namespace *mnt_userns, if (oldsize > holebegin) unmap_mapping_range(inode->i_mapping, holebegin, 0, 1); + } else { + shmem_truncate_range(inode, oldsize, newsize); } } From patchwork Thu Feb 2 20:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp464816wrn; Thu, 2 Feb 2023 12:47:32 -0800 (PST) X-Google-Smtp-Source: AK7set91v4THOBMkJXC4eM2ineZyOtPsvnMe416zmHnK8FlTE0tFz0Ax3drmKbs/ifi9IBi1apTa X-Received: by 2002:a05:6a20:a8a1:b0:be:bea0:7139 with SMTP id ca33-20020a056a20a8a100b000bebea07139mr2878096pzb.9.1675370852619; Thu, 02 Feb 2023 12:47:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370852; cv=none; d=google.com; s=arc-20160816; b=XOaf837nyzHuX37Jn+hY2Xcch1114BxNeYJmQlXF4/nTM/XDRK/dLBfccnEZF20Dgf UqzHR18pal737D/LaA30FvjQFwT5RfkfHSP8feiOilOnZA/sanGojNJj/pZMJKnva+x6 F1Aj6oB3d/5SXkHwQAen7anc7F5vDshC+8NMIuj1V3meirW/wKIhsrdlBOMjkktslxzV hY5wHksnejCJ2jX13oG7xG3i7+LEh8Y+l7937i7xFh6at3VOEOaeu9xi/l4VsU0PgI3P D1sWakUxVa57F3lF2zBAcTeVzRhHoaViVgGZJuPLFRRGTGcLakKKE1bqKGMBurj/7MjK q+6w== 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=74nszHLks+AFGqdfRGx6vNnWqXDqZ9xHI0qBKa9QcdI=; b=Rv/prI8PAEyIPgKn82K1c+MOzfc51QpCUXb4dikaZS0QQekF+/CMwP9t6Sle55jxko OpoTtHk0cbhZ62hj3Hn7mLcfhgBgod/3Zm5ddEfKe6K0iPWdoLHe9GMbwL+ygKOsd2NS F5tnrLQH9m/SEgxR1KEjxxMJ1U+rY67Swin0IgHnIxBfEuzggq0Nyc7tdyZfi52jE7Tr GLSCgGj+HC+rmVq/Y3F4PLGrs8DWsw5AlM5c6grHUa9wCQ9Z/FeM8P9sn4O9L5Rt7ahZ Oj+Vy2eAv38xA1XmYZJIhyfzSZdA7PWikPBDPZsKtBPPIioBJtmoHwkFuEiPKpaVujUj 6GGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="Bh63M/0n"; 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 s7-20020a63af47000000b004e4b1b01366si495602pgo.805.2023.02.02.12.47.20; Thu, 02 Feb 2023 12:47:32 -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="Bh63M/0n"; 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 S232067AbjBBUox (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232841AbjBBUof (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 C6DAC76AB; 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=74nszHLks+AFGqdfRGx6vNnWqXDqZ9xHI0qBKa9QcdI=; b=Bh63M/0nqGUZZvEkwrwA6JtjLg 6o8uQmpPAbwbDBcLTYskUV04rtjVxAbkRI8ywM/Cpg4QgkiduK6adIw3ab64Pf5IMVgLHdPjVDTBl aFg3fWxnpxmnDgfKBu03xsCHOnK4kcN7ZNcdNL6rFyRosOEDWxJ2OH3HyqGJPOB9okC+kK4RFv5JW x710OIFndtSvYOt8aghfbiSUMaoLwhFO3gM1DyXoahA8R0FHcoR780FR7VUl6VjqZywykxzxsTZsT z7NGee99rYn2z4rassj8Q+UR5edf87SIIhF/tDMjeQicVliVbhgeiEiraaTJYPSgPnMq8cG0Ud4/t ULWEZsfQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRb-00Di7d-Ga; 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 4/5] afs: Zero bytes after 'oldsize' if we're expanding the file Date: Thu, 2 Feb 2023 20:44:26 +0000 Message-Id: <20230202204428.3267832-5-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?1756753667207207466?= X-GMAIL-MSGID: =?utf-8?q?1756753667207207466?= 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) Acked-by: David Howells --- fs/afs/inode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 6d3a3dbe4928..92e2ba7625de 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -854,6 +854,8 @@ static void afs_setattr_edit_file(struct afs_operation *op) if (size < i_size) truncate_pagecache(inode, size); + else + truncate_pagecache(inode, i_size); if (size != i_size) fscache_resize_cookie(afs_vnode_cache(vp->vnode), vp->scb.status.size); From patchwork Thu Feb 2 20:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp464664wrn; Thu, 2 Feb 2023 12:47:10 -0800 (PST) X-Google-Smtp-Source: AK7set8lxnodwsoKammNuhDWHdLJY9ig1ulpwItDKOfCPO2/eazUQCE2aeFU+dSTFrhWCUQomobU X-Received: by 2002:a05:6a20:1446:b0:be:93c7:4f69 with SMTP id a6-20020a056a20144600b000be93c74f69mr9538687pzi.52.1675370830226; Thu, 02 Feb 2023 12:47:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370830; cv=none; d=google.com; s=arc-20160816; b=i/PHC5lzmEFBTOdiiNWisL6fazeN52yYOWHPuoLuEE8UeQYTrtx+Xw2ob5ZRz/RVpO FF9XgrKHD2nUCDuUVuYtwpmHa2RC/prgH8zv0HWaJI6HUZC+xe0QV3bU45412KqLSmur xYa8OEvxB5qE9yGeep4IXz0CJC7sZVAQJHuga5t97vofLpFxUwIk7LtpB/InN2z0RpBh YKERbitvzke8o5ElpjGWre+fnRzr85haoWdIG4hydg36xn5T+ay+EbaaQCTitioWhQWD 3azW1Q1KUHd1GDMzmF1famf++K52uuYJQBuR7rtzNayghGq9Hqx6O1bH769VE4Xk5scs psPQ== 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=EKEz4nt5nAILCQ0WhorvddY3Ohu5ukrqmYNOFRKi6c4=; b=0+PNGUF3azvrCWPfliLFHdITPfy8L9Bz2ibskq8lnmvuNnJktxpukU2Wy0yRiJtfqr B10hpwTZMt9EPAixwjVVz8biMUmHgtA0X+t74/WqvwigE8ceXOxaiNOa8gCMgTH5r3xw s2GMAXJrdiPVZoy/Zn5a2O5qQchM74zeBUUcEp5Od6rbqMAXOeK+biPjtHrEgH5i2PJJ gnBSQ6pQbl2AIqrCAGTgkk6v23NaICr7/fHDvITKU+YgJqFFmgA0FsgES1bfk7RvgWeI UoUvtyARGKPh4OLVrk5r4unA96vhC6dLO53rhivRp55myTHCbBnoOh3YttrW3dADwwGo Uuew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GX1Qllwr; 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 a20-20020a637054000000b004df6eb7dfcasi551710pgn.303.2023.02.02.12.46.58; Thu, 02 Feb 2023 12:47:10 -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=GX1Qllwr; 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 S232922AbjBBUoh (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjBBUof (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 C73128A43; 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=EKEz4nt5nAILCQ0WhorvddY3Ohu5ukrqmYNOFRKi6c4=; b=GX1QllwrfhDN5IKVNAciO3qEvo z1zvwuCrdT1EFPb+2uaPsl1XDsVWPvzn1FMeJ0+uKpjTftB94HKpr9d9x2074LhVEQcw+hsfCA4Ah s0I0YoFtRcRZl1R//0GffZdIIGKtEY0+gAXCMMK0Mm9Ix40T/P2zrT8FUsuOIUPpX32dwL6SOxTnF gk//hnp9hqX5Yqrk1rLBCmuZ4pue3Y9IMSfFWn25PJEwgpTvGYpLCzE5iewZvsAyqxTGcrgxzqePp RKnecjNgS+kjWIwJOXmaxQBJ1Iao/OKNm8LAHXcXxtyy6p30R/c2HxpHN4V3gsFGa6jwPx5TOr/eO tKTST7YQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRb-00Di7j-LB; 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 5/5] btrfs: Zero bytes after 'oldsize' if we're expanding the file Date: Thu, 2 Feb 2023 20:44:27 +0000 Message-Id: <20230202204428.3267832-6-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?1756753643503011501?= X-GMAIL-MSGID: =?utf-8?q?1756753643503011501?= 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/btrfs/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 98a800b8bd43..b61ec4bb9cf0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5234,6 +5234,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) i_size_write(inode, newsize); btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0); pagecache_isize_extended(inode, oldsize, newsize); + truncate_pagecache(inode, oldsize); ret = btrfs_update_inode(trans, root, BTRFS_I(inode)); btrfs_drew_write_unlock(&root->snapshot_lock); btrfs_end_transaction(trans); From patchwork Thu Feb 2 20:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp464146wrn; Thu, 2 Feb 2023 12:45:55 -0800 (PST) X-Google-Smtp-Source: AK7set9HkIfA7t1zrYJYhpVFU9jjStpw7j0sMBUKlh2e2tmTMo5KWYSxHugvWZB/mVR01yqy7ZWP X-Received: by 2002:a05:6a20:2a24:b0:be:e494:4185 with SMTP id e36-20020a056a202a2400b000bee4944185mr6929385pzh.53.1675370754940; Thu, 02 Feb 2023 12:45:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370754; cv=none; d=google.com; s=arc-20160816; b=PAunOqTJXp/olhcHENI/wbSvbyScHi9S+6l6TYc3APd+cMBF0Is/gzHRTgSJHNZHyV 3XWNgHwouMUGA7msN46AuUUs+JeCrnP1rFWxsWVXF9VV5S1/cy5oQCnUJ9QE4rahIb70 jEMrn5hwVlTjA932P7N64V0xtM0o+/vGFT3DxcBzw/wjwtUK11k6TBdN/ikqcop8LOp1 CBIeJjYFwnR+b5mVNo4Iwe8eNQzc2Y/PC0nf/tRJiK+jlv3yfGEJnzLDlVHXepw1I12J 0olMc2ntpkGxK2PpYiCrcujaBoUlZhzMpm2TdpgZivjSqd1Q/nh4WxZfabd2K9KLupMM SK7w== 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=2Gu1J17vUOqah9snYcpOpRqgXozaOqIS6UOuMS3TPDU=; b=uEhgQiYqtxTFqTmvU+w0/7LK4/olgnEO0v1dcy+ClpJKOkJAeGykAUS+GyoEFoliIY 5UsCVqb+ZJC7hJnuSIGXD0fR9E+nprB7//SWd2y3yYf/CBEuq7GO23on5+LeMqY5T6Qn n0yzBOXTdAVh8jDHBhaEOLEa8o4TofcXYxJ1pSoC2meVCPRwkplQpoLe+IqNv0dvOkW4 7jGc2jPenoNu0l1r3YyxML78YBrggz7PtmoALYjV4mPdBwwzvaCp1MS6PQ7ss4bc29j4 4gqGczkjgjs7hPCj5JQljxo44LxzAg5IHEqutOPbHQwsmVrLfC+zYN6yFbFQbi+O8pBx HGSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=nBecBO+l; 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 h10-20020a63384a000000b0047856c2a3dbsi550233pgn.257.2023.02.02.12.45.42; Thu, 02 Feb 2023 12:45:54 -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=nBecBO+l; 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 S232981AbjBBUom (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232515AbjBBUog (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 C68266598; 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=2Gu1J17vUOqah9snYcpOpRqgXozaOqIS6UOuMS3TPDU=; b=nBecBO+le/dfpA61aDSji/IT8c Jtpk5VIkJ0m1vBtuaxptXdJ/oIIbbAH0pqvZqcVxvttuZlRtLDKXIhaa23N1SjMEkbKDNYis6ShNF Rsig0553S1/uylbIfEMobwRyeLj+CgHeUmJPqVvGzNqX88Jd57qQtQegCyncP+63tRKILRWPihjb5 yCGI0RNgt3IIXMzIMmRWkUrf5vPGvU8xF2ShjG7/W+zpd49ew3/BhME1TE88PpbjIZsdOKHx7QGXD WfS4Y1QKwclnEZiFBnuwCJT7n6IYUwe/ERhek6N/j+EKTi458KfQRGCiCnV353LqlnIg/JOWmJmF3 QwgiXE+Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRb-00Di7p-Pr; 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 6/5] generic: test ftruncate zeroes bytes after EOF Date: Thu, 2 Feb 2023 20:44:28 +0000 Message-Id: <20230202204428.3267832-7-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?1756753564838843499?= X-GMAIL-MSGID: =?utf-8?q?1756753564838843499?= https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html specifies that "If the file size is increased, the extended area shall appear as if it were zero-filled." Many filesystems do not currently do this for the portion of the page after EOF. Signed-off-by: Matthew Wilcox (Oracle) --- .gitignore | 1 + src/Makefile | 2 +- src/truncate-zero.c | 50 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/707 | 31 +++++++++++++++++++++++++++ tests/generic/707.out | 2 ++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/truncate-zero.c create mode 100755 tests/generic/707 create mode 100644 tests/generic/707.out diff --git a/.gitignore b/.gitignore index a6f433f1..6aa5bca9 100644 --- a/.gitignore +++ b/.gitignore @@ -169,6 +169,7 @@ tags /src/test-nextquota /src/testx /src/trunc +/src/truncate-zero /src/truncfile /src/unwritten_mmap /src/unwritten_sync diff --git a/src/Makefile b/src/Makefile index afdf6b30..83ca11ac 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ t_ofd_locks t_mmap_collision mmap-write-concurrent \ t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc \ t_mmap_writev_overlap checkpoint_journal mmap-rw-fault allocstale \ - t_mmap_cow_memory_failure fake-dump-rootino + t_mmap_cow_memory_failure fake-dump-rootino truncate-zero LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \ diff --git a/src/truncate-zero.c b/src/truncate-zero.c new file mode 100644 index 00000000..67f53912 --- /dev/null +++ b/src/truncate-zero.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + char *buf; + int i, fd; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + fd = open(argv[1], O_RDWR | O_CREAT, 0644); + if (fd < 0) { + perror(argv[1]); + return 1; + } + + if (ftruncate(fd, 1) < 0) { + perror("ftruncate"); + return 1; + } + + buf = mmap(NULL, 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (buf == MAP_FAILED) { + perror("mmap"); + return 1; + } + + memset(buf, 'a', 10); + + if (ftruncate(fd, 5) < 0) { + perror("ftruncate"); + return 1; + } + + if (memcmp(buf, "a\0\0\0\0", 5) == 0) + return 0; + + fprintf(stderr, "Truncation did not zero new bytes:\n"); + for (i = 0; i < 5; i++) + fprintf(stderr, "%#x ", buf[i]); + fputc('\n', stderr); + + return 2; +} diff --git a/tests/generic/707 b/tests/generic/707 new file mode 100755 index 00000000..ddc82a9a --- /dev/null +++ b/tests/generic/707 @@ -0,0 +1,31 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 Matthew Wilcox for Oracle. All Rights Reserved. +# +# FS QA Test 707 +# +# Test whether we obey this part of POSIX-2017 ftruncate: +# "If the file size is increased, the extended area shall appear as if +# it were zero-filled" +# +. ./common/preamble +_begin_fstest auto quick posix + +_supported_fs generic +_require_test +_require_test_program "truncate-zero" + +test_file=$TEST_DIR/test.$seq + +_cleanup() +{ + cd / + rm -f $test_file +} + +$here/src/truncate-zero $test_file > $seqres.full 2>&1 || + _fail "truncate zero failed!" + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/707.out b/tests/generic/707.out new file mode 100644 index 00000000..8e57a1d8 --- /dev/null +++ b/tests/generic/707.out @@ -0,0 +1,2 @@ +QA output created by 707 +Silence is golden