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); } }