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 AE6BD1E6DD5; Wed, 6 Nov 2024 13:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730898411; cv=none; b=FFc7GxVAKdlLDe9xXqDnF1W6wjvEDaAGm4A8IAYMG2VRcFphEhgg9+CnbRv+gCVshtwnqYJ3QcTlgfpte/4WutHgrPCFzjtzg7UDU1/e40uuoWVBrS6H+QAl2NndosYGqQvVBZ8Yo3qp4bc3w5HwILLFMcR0uS685tX5UMOXynA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730898411; c=relaxed/simple; bh=7cyssFWYn4nbrn9XoIfH3UFr10ifFfvUYWbsH4+hnd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cbSLad+5g3WVQ5KsBU3PqB2FbCXyArHKcp5zwE+wOoUWp48ijqYhTYnU9oIEbZnEuuAKZiWyyGDiRpRzIYGBfWIrtlHIesnZ7Z/r9YHZoYZN9j9ncpSrJHIrxfMgmeTATOeGJkXgDiKyH8unHrrlDFetB1W68QAmRF63/0iRzOU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=iEBKnqUd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="iEBKnqUd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 363C8C4CECD; Wed, 6 Nov 2024 13:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730898411; bh=7cyssFWYn4nbrn9XoIfH3UFr10ifFfvUYWbsH4+hnd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iEBKnqUdO7y2p5nJ2MsCItpnuepVz2PSmWjON6SIPmOZ4GX85MfIwhWPLTy/zcJ0I X90zJwQ2cuTfEQbprMjOJMBcK+v8nSsh4uwqkZ2UK5YoM2IJf3MapLqDXX04LwRFpC 7W1SmZH0v4hNlM13kqDpQ9yLUPI3GLuMp6H9HQGo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jann Horn , Chao Yu , Eric Biggers , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.4 193/462] f2fs: Require FMODE_WRITE for atomic write ioctls Date: Wed, 6 Nov 2024 13:01:26 +0100 Message-ID: <20241106120336.281404576@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120331.497003148@linuxfoundation.org> References: <20241106120331.497003148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit 4f5a100f87f32cb65d4bb1ad282a08c92f6f591e upstream. The F2FS ioctls for starting and committing atomic writes check for inode_owner_or_capable(), but this does not give LSMs like SELinux or Landlock an opportunity to deny the write access - if the caller's FSUID matches the inode's UID, inode_owner_or_capable() immediately returns true. There are scenarios where LSMs want to deny a process the ability to write particular files, even files that the FSUID of the process owns; but this can currently partially be bypassed using atomic write ioctls in two ways: - F2FS_IOC_START_ATOMIC_REPLACE + F2FS_IOC_COMMIT_ATOMIC_WRITE can truncate an inode to size 0 - F2FS_IOC_START_ATOMIC_WRITE + F2FS_IOC_ABORT_ATOMIC_WRITE can revert changes another process concurrently made to a file Fix it by requiring FMODE_WRITE for these operations, just like for F2FS_IOC_MOVE_RANGE. Since any legitimate caller should only be using these ioctls when intending to write into the file, that seems unlikely to break anything. Fixes: 88b88a667971 ("f2fs: support atomic writes") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn Reviewed-by: Chao Yu Reviewed-by: Eric Biggers Signed-off-by: Jaegeuk Kim Signed-off-by: Eric Biggers Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 030152219c4d6..0057e7a6596d0 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1862,6 +1862,9 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) struct f2fs_sb_info *sbi = F2FS_I_SB(inode); int ret; + if (!(filp->f_mode & FMODE_WRITE)) + return -EBADF; + if (!inode_owner_or_capable(inode)) return -EACCES; @@ -1928,6 +1931,9 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) struct inode *inode = file_inode(filp); int ret; + if (!(filp->f_mode & FMODE_WRITE)) + return -EBADF; + if (!inode_owner_or_capable(inode)) return -EACCES; @@ -1970,6 +1976,9 @@ static int f2fs_ioc_start_volatile_write(struct file *filp) struct inode *inode = file_inode(filp); int ret; + if (!(filp->f_mode & FMODE_WRITE)) + return -EBADF; + if (!inode_owner_or_capable(inode)) return -EACCES; @@ -2005,6 +2014,9 @@ static int f2fs_ioc_release_volatile_write(struct file *filp) struct inode *inode = file_inode(filp); int ret; + if (!(filp->f_mode & FMODE_WRITE)) + return -EBADF; + if (!inode_owner_or_capable(inode)) return -EACCES; @@ -2034,6 +2046,9 @@ static int f2fs_ioc_abort_volatile_write(struct file *filp) struct inode *inode = file_inode(filp); int ret; + if (!(filp->f_mode & FMODE_WRITE)) + return -EBADF; + if (!inode_owner_or_capable(inode)) return -EACCES; -- 2.43.0