From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794063351; b=aaxFTz/4yOdVkPeNnMWGFNWd04uq+qz4ZCY7o6z07AegFXpUkGhHQMu6H07HMwiXUF5l CSepho0NdY31U1CsCg2JjMVrxEPOf/T8WWsQYOfUzt3NzXX7yAel66E3Ys0Wy5wdEgzJf 8xrXUu+gxfrxuYRxja+/rSNt0QuwM03zNlb0zE3+bbu6dvtKwgqhKye9OkFmw3VQZXKf2 pDb6pfdlAWtfUxzIM2AwjthVp0dN1F7KHJBAz5kOkjh66lQ6DJLrR55h3P50nVGqTAkih J9F8Hp6npUhIn+NHzYHxFzUyi+FzrnTBjgRsqDObdlh0hOTVaUVovBBxpu1fGb+qrIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794063351; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=m62Vh5CtbvpXO9/U9s98MbUNZ/mkCctjaGBlNHzvF6M=; b=vDMEpWqqAuz2KXuwbzvp31W8gB+ShkV9pI8SEUh4AxcLt69bT+nboOMFC3AemWLwwNEl +rS+no4dmINp6x7f2FE5dCGCfKR4/6dOolR2lKdg7z2tAOQLqmiyqKiCx0ZxHLQajgitT jUab5Su58AmthLFRP4msIcRCqBansLXceyfQIbMgZenww77KyKtiCggXwbnWoeHn5JARR Zebw9uqOHqLhunXKzEARMuhdqOst1qZYrW0abuT5ycg1xsVEWdBePjJFh/ZeYwEgUB9Y/ +E2fn10/otZktmFwWiOAN5FHQtmbEDGF555s58GQOPWzUEL0ls+XMsFD7RgFC0yfLow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=SAtJ8gpz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EA0B606D831; Sat, 7 Nov 2026 14:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=SAtJ8gpz Received: by smtp.kernel.org (Postfix) with ESMTPSA id C08AA1F0089F; Sat, 7 Nov 2026 14:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794063351; bh=m62Vh5CtbvpXO9/U9s98MbUNZ/mkCctjaGBlNHzvF6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SAtJ8gpzP3gBo7wNVO3yvod6yJy8U3xtum5nLwqDWrwUvlIBOOnr3UF236oW8a7Ta xYGNmg/+9oRB5SpzZEFJybjGarz1snhcLXtRBT3vUP5vEfLbe4S/cXVfQvvFcKNU4I lKHsfP7rSeBsPeYu91LRi8lEgeLuKpvr/Wovyw1s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Daeho Jeong , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.18 532/869] f2fs: disallow mmap write and data-modifying fallocate on atomic files Date: Sat, 7 Nov 2026 08:53:34 -0500 Message-ID: <20261107134911.496288032@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134852.069646174@linuxfoundation.org> References: <20261107134852.069646174@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daeho Jeong [ Upstream commit 06dfe4a7eb696d868b196c2a49873142f19bd862 ] Stores through a shared writable mapping and fallocate with FALLOC_FL_PUNCH_HOLE, FALLOC_FL_ZERO_RANGE, FALLOC_FL_COLLAPSE_RANGE or FALLOC_FL_INSERT_RANGE do not go through ->write_begin, so they bypass the COW inode and modify the original inode directly. Reject them while the file is in atomic write mode, as fallocate already does for pinned and compressed files. A write fault gets SIGBUS and fallocate gets -EOPNOTSUPP. fallocate without these flags only preallocates blocks and stays allowed. f2fs_vm_page_mkwrite() cannot take inode_lock, so check the flag under invalidate_lock, and hold invalidate_lock in f2fs_ioc_start_atomic_write() from the flush until the flag is set. Otherwise a fault could check the flag, then start_atomic_write could flush and set the flag, and the fault would dirty the folio afterwards. Cc: stable@kernel.org Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Daeho Jeong Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 86f1f734caaac..8211ee75fb8f7 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -177,6 +177,17 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) file_update_time(vmf->vma->vm_file); filemap_invalidate_lock_shared(inode->i_mapping); + /* + * mmap stores bypass the COW inode and would break atomicity. Check + * under invalidate_lock: f2fs_ioc_start_atomic_write() holds it while + * flushing dirty folios and setting FI_ATOMIC_FILE, so either it sees + * our dirty folio and writes it back, or we see the flag. + */ + if (unlikely(f2fs_is_atomic_file(inode))) { + err = -EOPNOTSUPP; + goto out_sem; + } + folio_lock(folio); /* * A concurrent buffered write can extend isize, so we store isize in a @@ -2081,9 +2092,11 @@ static long f2fs_fallocate(struct file *file, int mode, /* * Pinned file should not support partial truncation since the block - * can be used by applications. + * can be used by applications. Atomic files should not either, since + * these modify the original inode directly and break atomicity. */ - if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && + if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode) || + f2fs_is_atomic_file(inode)) && (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) { ret = -EOPNOTSUPP; @@ -2368,6 +2381,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) f2fs_down_write(&fi->i_gc_rwsem[WRITE]); f2fs_down_write(&fi->i_gc_rwsem[READ]); + /* serialize with f2fs_vm_page_mkwrite(), see the comment there */ + filemap_invalidate_lock(inode->i_mapping); /* * Should wait end_io to count F2FS_WB_CP_DATA correctly by @@ -2423,6 +2438,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) f2fs_i_size_write(fi->cow_inode, isize); out_unlock: + filemap_invalidate_unlock(inode->i_mapping); f2fs_up_write(&fi->i_gc_rwsem[READ]); f2fs_up_write(&fi->i_gc_rwsem[WRITE]); if (ret) -- 2.53.0