From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD7D11C03 for ; Mon, 20 Mar 2023 15:10:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F400C433D2; Mon, 20 Mar 2023 15:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1679325047; bh=J1YMVGx+DGZ8fV037d/5C6ODa7GDmi33/nUll+mkgR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=edXjptbMXGncM/qb+Xu8wsGGh/qdBGFNf34zubZ2/+9Hy3/aQWrUW9uIEsJHZEETe kF/PbJ/FF2rFBNzH8vX47YPfYar/CXTAdW4pOiVcwtDGU5TMz7UhgaPMo96Kbl4uis qKrz0D9LZ6cDSRUykU8QPvueNfAs6NwePZSIvJU8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dave Chinner , "Darrick J. Wong" , Amir Goldstein Subject: [PATCH 5.10 87/99] xfs: fallocate() should call file_modified() Date: Mon, 20 Mar 2023 15:55:05 +0100 Message-Id: <20230320145447.058613112@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230320145443.333824603@linuxfoundation.org> References: <20230320145443.333824603@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Dave Chinner commit fbe7e520036583a783b13ff9744e35c2a329d9a4 upstream. In XFS, we always update the inode change and modification time when any fallocate() operation succeeds. Furthermore, as various fallocate modes can change the file contents (extending EOF, punching holes, zeroing things, shifting extents), we should drop file privileges like suid just like we do for a regular write(). There's already a VFS helper that figures all this out for us, so use that. The net effect of this is that we no longer drop suid/sgid if the caller is root, but we also now drop file capabilities. We also move the xfs_update_prealloc_flags() function so that it now is only called by the scope that needs to set the the prealloc flag. Based on a patch from Darrick Wong. Signed-off-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Amir Goldstein Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_file.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -895,6 +895,10 @@ xfs_file_fallocate( goto out_unlock; } + error = file_modified(file); + if (error) + goto out_unlock; + if (mode & FALLOC_FL_PUNCH_HOLE) { error = xfs_free_file_space(ip, offset, len); if (error) @@ -996,11 +1000,12 @@ xfs_file_fallocate( if (error) goto out_unlock; } - } - error = xfs_update_prealloc_flags(ip, flags); - if (error) - goto out_unlock; + error = xfs_update_prealloc_flags(ip, XFS_PREALLOC_SET); + if (error) + goto out_unlock; + + } /* Change file size if needed */ if (new_size) {