Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3224941pxb; Mon, 18 Apr 2022 19:46:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygCx6OrGbJ4XzNB9eO39eNvQWluOnMJbiOwxCUhgrm7NbvtPmOMeVxzJglr0muL079oL0m X-Received: by 2002:a17:906:7f02:b0:6cf:86d8:c31c with SMTP id d2-20020a1709067f0200b006cf86d8c31cmr12167824ejr.518.1650336419398; Mon, 18 Apr 2022 19:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650336419; cv=none; d=google.com; s=arc-20160816; b=o7VY1ro5caSzGEy1tV0tOfdfgMfi0iGhAJoT6xwVNXG/7Js25ZhcRuGeC3S60r9stv jK3+JV1lK6LoOrViKD26wW7eBV11aPC7vVZ/5ABI0b42WjHusAGtgqbxVo4ZZzVMFqmu NYhADhsfHZZXUDt5mkYRjKu0B1aiZPIV+l/KESgtQ5x8UEFse7VcQp0IkAPT/ZlXiKlm 7Rn6Jk/lv5/nD+fa+dsNe6zpDeD5DG8DvgJmirJjDaeiPCMaGmyERGMQ69AFZD4xfzYs j1B8Z0VtvK21Q2fzwpBjsqd5JU5hQcTZ/pk/iepEDQ4ReeT343gk2vsxvfHOFgDBy8eX KeUw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gAKd9OgIEkVuc9Uq3OxbMt7VJM0LYxk1cJjJCOMnTf8=; b=rAxDPc8VFK7yBXHk1D/F/wBiGKJ3wOPFWZwFbVg/dfyFR2qwOchvfh87ZTVxEhep4V mqnqHRKdoG6qQROUisG+40LLMmcz5X3NAFrhvdf1dwh0NLeBAJ6hiR5WQPAIURLeE5TL OArY7MiGNPKrJmUeqKpz5ePJPkGwzrCGfPaUBjLRxOlyJQY+Fzqb83sLxBKok9skecoq TYO5w57wmmuNnAdFuJxDNn/p6Mbntfyk0JK4DAlnwaF2ooc3KS3jsWhQTZSfOp4/V+xq QtNhbqC7PcFHl2mwWTIKdKSD37A4ixIg0HZ4QXMGZIRfDQg/3Hmv7mfj1UtQyDjmBkxE LPJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LL7XocXY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a056402440f00b0041d130a5087si10054553eda.427.2022.04.18.19.46.36; Mon, 18 Apr 2022 19:46:59 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=LL7XocXY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239183AbiDRMcd (ORCPT + 99 others); Mon, 18 Apr 2022 08:32:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239689AbiDRM2l (ORCPT ); Mon, 18 Apr 2022 08:28:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EED7201A6; Mon, 18 Apr 2022 05:22:22 -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 C65EEB80EDE; Mon, 18 Apr 2022 12:22:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F948C385A7; Mon, 18 Apr 2022 12:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284539; bh=qQSYxwQ0a1zzq3hdUWO+WEoi8GCOsoUpjcM8TqNU80Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LL7XocXYd4vG563boaAwKIV2w7qnbwd+4pfPxisMcpA4BgzT+qPycpzhB/ZSFqRMY doSavBsDWO4kfcO1A1101DwncCw0AHlTeGbEE+rwUeCQwxQ3UhPFhed98ZfG8Bcm9N nttEN6c2WYqd/0lt7udYxEUEK8jkfLbWjx3EkQBU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , "Darrick J. Wong" , David Sterba , Sasha Levin Subject: [PATCH 5.17 131/219] btrfs: fix fallocate to use file_modified to update permissions consistently Date: Mon, 18 Apr 2022 14:11:40 +0200 Message-Id: <20220418121210.562765021@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 a0179cc62913..28ddd9cf2069 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2918,8 +2918,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; @@ -2951,6 +2952,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; @@ -3391,7 +3396,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 @@ -3413,6 +3418,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