From mboxrd@z Thu Jan 1 00:00:00 1970 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 862ECC433F5 for ; Tue, 12 Apr 2022 00:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243755AbiDLAv0 (ORCPT ); Mon, 11 Apr 2022 20:51:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244329AbiDLAuw (ORCPT ); Mon, 11 Apr 2022 20:50:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4626730566; Mon, 11 Apr 2022 17:47:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8D7FCB819BF; Tue, 12 Apr 2022 00:47:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F28EC385AA; Tue, 12 Apr 2022 00:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649724420; bh=lfWgNDuTl3Fsk91sCVN2UOdFZ9227/ZxwTLk25yq+7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W8rfxafzEZ4tvGtjwTOXAHpNUO4kqif79y0wgXeK9gJ+P5ffH35EQpMRoobAmdvgq OEAVOFAA3ULmLkSPj2R3aBvDHpO0hol8dmClj1DTH2AouxSvvT7o7uOizN0AP+Qt+n xp25/YLUIdaQKpvRStr9EC7wAgDXtHOl+Rw6kM18KExgsUscmLX9U1tkurrcjEFWcD y/YW2BIQ8lFdztuDLXSEHJdv7vMXYx6o4EvAhxIL93j4sOwQVBs4RfuxN3ZpmrWyJY 5KRGfxtHb3IWlo5h7jHUMNDzlHVEUXG+W9ofOJN2X2S0ge6a0aTwAZSHELCHjJ20zg r+iSHgvE3Ep5w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Darrick J. Wong" , Filipe Manana , David Sterba , Sasha Levin , clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 02/41] btrfs: fix fallocate to use file_modified to update permissions consistently Date: Mon, 11 Apr 2022 20:46:14 -0400 Message-Id: <20220412004656.350101-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412004656.350101-1-sashal@kernel.org> References: <20220412004656.350101-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: "Darrick J. Wong" [ Upstream commit 05fd9564e9faf0f23b4676385e27d9405cef6637 ] Since the initial introduction of (posix) fallocate back at the turn of the century, it has been possible to use this syscall to change the user-visible contents of files. This can happen by extending the file size during a preallocation, or through any of the newer modes (punch, zero range). Because the call can be used to change file contents, we should treat it like we do any other modification to a file -- update the mtime, and drop set[ug]id privileges/capabilities. The VFS function file_modified() does all this for us if pass it a locked inode, so let's make fallocate drop permissions correctly. Reviewed-by: Filipe Manana Signed-off-by: Darrick J. Wong Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a1762363f61f..dc1e4d1b7291 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2878,8 +2878,9 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode, return ret; } -static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) +static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len) { + struct inode *inode = file_inode(file); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; struct extent_state *cached_state = NULL; @@ -2911,6 +2912,10 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } + ret = file_modified(file); + if (ret) + goto out_only_mutex; + lockstart = round_up(offset, btrfs_inode_sectorsize(BTRFS_I(inode))); lockend = round_down(offset + len, btrfs_inode_sectorsize(BTRFS_I(inode))) - 1; @@ -3351,7 +3356,7 @@ static long btrfs_fallocate(struct file *file, int mode, return -EOPNOTSUPP; if (mode & FALLOC_FL_PUNCH_HOLE) - return btrfs_punch_hole(inode, offset, len); + return btrfs_punch_hole(file, offset, len); /* * Only trigger disk allocation, don't trigger qgroup reserve @@ -3373,6 +3378,10 @@ static long btrfs_fallocate(struct file *file, int mode, goto out; } + ret = file_modified(file); + if (ret) + goto out; + /* * TODO: Move these two operations after we have checked * accurate reserved space, or fallocate can still fail but -- 2.35.1