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 (Oracle)" X-Patchwork-Id: 13126703 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 6BD9CC636D3 for ; Thu, 2 Feb 2023 20:44:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A808D6B007D; Thu, 2 Feb 2023 15:44:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DDE96B0078; 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 521236B007B; Thu, 2 Feb 2023 15:44:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1B72B6B0075 for ; Thu, 2 Feb 2023 15:44:40 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CA4CCC0FFA for ; Thu, 2 Feb 2023 20:44:39 +0000 (UTC) X-FDA: 80423530278.05.C18E46B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id 26BD88001B for ; Thu, 2 Feb 2023 20:44:37 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="LI7K/fD5"; spf=none (imf30.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=7vw66D2vDIhBX9oEFJWgWei9pEvFRsbTDrfadEvnVH0=; b=h1jLZ55A8XBLFzi95DGifEeSC1S5q9u8oT8eXO9ecYcgj6Gun1ne+lNCjYPxEgUZOX76Pg S+BHrX+GzmwHp/SN9/gzE/HAghmbwGxv2uX9w3Ua9/irocK7RHZyeetYIxcIFnGJtSbUo3 Wikf/sEeP0+FLm6yO9nShQIHqUTcj6o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="LI7K/fD5"; spf=none (imf30.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=fAIbd45sxsReex1B5MACTmPtf2UhuXaMr4ZcEr+JzCsbJ+0xKtEeZpCFYKrPMSC1idFAZl P6N46IEDEZsDiipCsQItiKni7XzW0900zHEsFd+iyoNb8WsdB7+zkpwWCBzTd8LfLDjv0c OCr7LerrXnFVhQ9rCFKwYA3xfFEj1/o= 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 26BD88001B X-Rspam-User: X-Stat-Signature: 1t8ca3qimbpczrserng1osuzcqpuhgdy X-HE-Tag: 1675370677-107599 X-HE-Meta: U2FsdGVkX18kTa1d6FnNRv9sDztPxgFChujvg8Cs+xr5ucB0j1efz7FEA13MtqF7B50zG5kBlChhM3c5sBUtprEEjE2XNplM1tenWEymarS3wjGB4qmmxd2VghhMh8R5cgieI+rfKvcEu3JclPnF4Tj13Oy4RdKf+7BHYTXZG692fYEsSVxRtvxltfGgewXK3aeAnBzgIxOIISVZDCkY356mJaV2J/02ecKdbS+lQiC/GygZbV/N834fDUGmZP6pFkFsUqCyMTHp1sBqgGygJ+TB9HURFzQnMnmdCJeFig2GqYSedktQCnHsvvaRHWYKLQRQo5AI4SGd9D0G090kmHE80JCYRjCyUrREhTCIr5BCqt4eYfZ/pz6TbQKWymoLaTBmC/DpyNkpa+wNBwxQX5WcEv8kZXzTe8Pki/OwErdmhzCo2Rjb9ub8CJUWsAndfUQNdZc8DbPCttqfRVBJP4K+mGVKk0ZUzNbz6bk6W0Pmh/BIZsCFRUqF5XSC1Nly+ipK+SwaH/8RyrGsKUQqf8cCSghPkdca/jpWniDLhe1TS1Tkhc7MfuYZ9Swhv8qHjZKgwONpwNQquowkKK2SPa2MdZ5Fvj9lsxi5n318n+A+nFIibXXmOSuTCfNCd3t95kmfLw5vca4I900Udd5HbugXgNUiCll4uAMcCMj7kWB4Gp5y2LTCLaWPatfFABxO3BL49rR6OTema2JYkD6vUcvcPl7VBXXhLFRMHecO7+ZCqndn3ftyTjN0ZVJXm+fRrRLMSGwUAK9R8kR95rhODTtVIsnbEHwpITTXMXBIuIZHHkQkKdzEdugAPqxGMEVlsOTAiwZ9ndI9tzq5sIM9VUOj2oYjLV3YlYiDDAAdeFPzR8/Z48yjT5rJwCD4DggCxgHSWwCZyEfa+EcZylwpbCOZwswJadpkFlFlVJznxTmMrMBnBFBUru3ecoKimnsZPQd2Eah6NLFlmYmm36Q zJHb4nF+ H7NfVX2q/dT44eBqvkLyV+QJaSD3jxNosmPcUOj7vWRq0+3EKqo0hk5m0f5LDfLU/xsybQack6bOeThQBe5ZZvHna9htGVqp5l5pzXEwVHEBbml490r+v2K2gTXF+goKOFdvJytZpN8XEsNilpIHGc+FSAS6efpv3xNp+HH2EfAJ74YDeqBOY7BvUG1Xf1Lw5MBU/ 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. 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); } }