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 (Oracle)" X-Patchwork-Id: 13126705 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A6FDC64EC5 for ; Thu, 2 Feb 2023 20:44:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0AF66B0074; Thu, 2 Feb 2023 15:44:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD4766B007E; Thu, 2 Feb 2023 15:44:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82E8B6B0075; Thu, 2 Feb 2023 15:44:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 416666B007E for ; Thu, 2 Feb 2023 15:44:40 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1889640884 for ; Thu, 2 Feb 2023 20:44:40 +0000 (UTC) X-FDA: 80423530320.01.4E03933 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 515EA12001D for ; Thu, 2 Feb 2023 20:44:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=My+pp2jn; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675370678; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3DLfbYeltsUE3NkYQxzmRoc7Gye1xXr71K3DBJBtYI8=; b=2RIDLBBjO7P358xlmsTtM2FjrbvgNRzrK6JjMSrd+Bkr9dQvNkjoI3u+nEYPDH92UYKv7K MK3hhxckXzgi4LhH0KmccC+f16c7LKwXqVPwC5w8f1sBtj78V7l01yblmgJhoH9tWMUV4x 2a5vVdG7PXdQC3TVnSoLud8WlRbUx/M= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=My+pp2jn; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675370678; a=rsa-sha256; cv=none; b=mFgjyE6JSawwp/MVaNfqaFZKSN22yeJz+KgP4wvFrc2V65rsiWzkCOftIOyxh/exdFbaSD +5hB/lZyRKv+UjjebcoAlODHld9uVnUd8HsoeipRARL7Zv1P2d9S6K9sD3CBx5enYgKg2s 5jiH/0rooZVDP5AFj+MCBBMT/E9RtE8= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: grcqafmbgwz1g5dabbts7fewu1ps7g6u X-Rspamd-Queue-Id: 515EA12001D X-HE-Tag: 1675370677-944460 X-HE-Meta: U2FsdGVkX1+k0Jz6tRoqtEbIrZuzltQhVLs0cdc77BJC2fC5SB7IXOEMw+u/HOaTRNHUpNDz8vySqbyIZ+HG3xKu/b6M6op/cCJZ3v9B4QvW0pMQH3UNSoLkZ6JKdvg7VNoTZWnpKABCCBjCjkN4Di4P3mNWmDaYFdUNhGK+7erw42YzrHFbc+9G/vgML8Hc8IW2qXGkavHx8DAOWSnQa70D9XeYSeIdnrMTWgf2rVHaFHQHbFcPD5vuxSjJ0ZPMlc/m7nLJbSX+k8ciXoqkVY2XWfPv34ezMAl2AZERs+1asXb9h9284et/wn3kMr6E5jQQw/S0FH+tTh7CEH8XQWgWQicLbOY5kqHMBQ9hR2hSCcPPyP0DBr7xWdg6mh78KrT7hkZvF0IP6Se00T2ZBc3uTXNbh1brMBvli+bKbWnx32jMClxRTikyGOLCqigDPnACJsRw/LWCe4q5mXenx8AT7p0UH40gYDLy6UhagAjondaP22unzuOneX89HEdSoUzBTsJBFJW5snv79Y/h70kvczTTHFVfghQhlmZlp+X7yW28k5Rt0x/eZ5CUM5SliQNtHdjpfAdDHy+qGWn6Ga4Re3av4Fpm4y9qHqnqf4FSG+GyyXK+M4x7EZrDAUEQee/w9j3pHzokrodanwAhkRhSj518vvgOO030VUbyFy3uXxq0ap6GAPlh2WRsuzQXsT24SSWBz4eeah9rML0X11OqjiiKhMyKNVcshLUaI5xeQj+mzBQ55VgKB+vNZzJns9BBTZdmIIwbDjZP9OR8kmcZDvisApELmthJKrbd9SmE2+m7jDTBTEG/ILq0VoyW4Bs2etWDLKFFHsxo/8HVVKxJpr5Q3gCKdsUHHT86Wjh19AgURwZBj4sThAnT5lQ0cgEwm7MScDvTFvsw/JmGdH3XUIfVWwDFBYPG+jkURhw2md+dY8et6gd1a84XwO1IyS91xVARfQUY1MK5Vqt TVlShlau XKSRmEZ9Uxc0YQZvfFcWmupO5oIgRSbbzHRXNJ9fDh25EqQLolI4ZgPLTBeMvah730Lz1oAau18YhT/qz7MYs1OTFZeVVl9uDEOF1z83YAfHvGOtCCyApZx86gE8D6upDWR1mvcG/SmY5QmMwviT25x2DSc46Nc+1FEl4fc1sXtD1Y5RLyk1N82jzOjgnQujzubkY X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);