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: 13126713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D151C64EC5 for ; Thu, 2 Feb 2023 20:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232948AbjBBUoj (ORCPT ); Thu, 2 Feb 2023 15:44:39 -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 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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: 13126714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED1BDC05027 for ; Thu, 2 Feb 2023 20:44:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232933AbjBBUoi (ORCPT ); Thu, 2 Feb 2023 15:44:38 -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 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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: 13126710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D715DC05027 for ; Thu, 2 Feb 2023 20:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232909AbjBBUoh (ORCPT ); Thu, 2 Feb 2023 15:44:37 -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 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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: 13126715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B27AC64EC4 for ; Thu, 2 Feb 2023 20:44:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232680AbjBBUou (ORCPT ); Thu, 2 Feb 2023 15:44:50 -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 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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: 13126709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C1A7C61DA4 for ; Thu, 2 Feb 2023 20:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232897AbjBBUog (ORCPT ); Thu, 2 Feb 2023 15:44:36 -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 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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: 13126712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6199FC63797 for ; Thu, 2 Feb 2023 20:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232921AbjBBUoh (ORCPT ); Thu, 2 Feb 2023 15:44:37 -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 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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