From nobody Tue Dec 23 14:23:48 2025 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ED1625777 for ; Fri, 27 Dec 2024 09:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735292098; cv=none; b=Ru7F9wN7S62a0nNEOGruwxEo0k0A1X9d3PPbMj0PCxi/SgUYFhVWg1SrVkDlEkeUeIjmROcCziLi2MpxJs4mv6LZCkW4dRWGOdVjGBv3Oxe34KbTZFDjh9LgYIBFlt6OubgE69btPcf37mm7mZbCCPW3ztlfjbpFSEH3SEp7ZzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735292098; c=relaxed/simple; bh=7sAlP5rYCBTO8bbyocpOdicYA8Z01l8hbQOCTXvJkUg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=goiCrYn1Zc0UaJrZpRAhlwSrIP1BQ/EeEwEi+SCix7YRNhHsSkvkEyXQZWkBp6eeoklV47mZBcbGJznj/Gjs7H8b5GKALZMEHUblztci4s4wcCgmpgCd5jpjnNp5WcohdSbFw55zh8/IkKEIH9Vzy7mKr4Kgmj86N8kG+KqgKIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=RSZwtFak; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="RSZwtFak" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=WaGp5 5VFeVfQ+CP2av31VMxXyNUuax0zO9FIBMwzu+4=; b=RSZwtFakV0aJ9BeMOj4SF /rt4z8XZElcs0RNIoxZHU1u7T0z4FSbppqUN3OKpwticWqbGR+v4aMpwlotDeyDd O9vR8nWTjr2XhcsXA+zf9qmHJuTYZJ3+hno5s/I+ZyW6JdFvAFWxUyzTajT0GkU4 mHk0vgtM4gqUzJ1RnFPwZQ= Received: from czq-PC.mioffice.cn (unknown [1.202.162.71]) by gzsmtp5 (Coremail) with SMTP id QCgvCgC3ROWWdG5nTLAEIg--.63118S2; Fri, 27 Dec 2024 17:34:15 +0800 (CST) From: chenzhangqi79@163.com To: chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Zhangqi Chen , Zhijun Li Subject: [PATCH] f2fs: fix error map extent flag while block not allocated Date: Fri, 27 Dec 2024 17:32:51 +0800 Message-Id: <20241227093251.344503-1-chenzhangqi79@163.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: QCgvCgC3ROWWdG5nTLAEIg--.63118S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WrWrZw4rAw4kZF4rCw1Utrb_yoW8XFWUpa 4Y9F18GFn5uF4Uu39FqF1kWanY93ykKrZYkayruw1qvr13Jr9YkFn8Ka4vqF1xKF4kCF15 tr1SkryfGF4UAFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j7YFAUUUUU= X-CM-SenderInfo: hfkh065kdqw1rlxzqiywtou0bp/1tbi7gXCnWdubFVAwQABsE Content-Type: text/plain; charset="utf-8" From: Zhangqi Chen In the function f2fs_fiemap, when returning the file map extent flag, the flag of the delayed allocation block is set to FIEMAP_EXTENT_UNWRITTEN . At the same time, the phy address of the file map extent reassigned to 0 because it is not a valid address. In this way, the file map extent with address 0 and FIEMAP_EXTENT_UNWRITTEN flag returned by ioctl, and may be used for writing by userspace programs, thereby destroying the superblock of the file system. As mentioned in /Documentation/filesystems/fiemap.txt, FIEMAP_EXTENT_UNWRITTEN should mean that the block has been allocated but not filled with data. However, the actual situation in f2fs is that there is no allocated block, so it should be changed to FIEMAP_EXTENT_UNKNOWN and FIEMAP_EXTENT_DELALLOC. Co-developed-by: Zhijun Li Signed-off-by: Zhijun Li Signed-off-by: Zhangqi Chen --- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 2ec0cfb41260..a945d1f1d40c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2023,7 +2023,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_ex= tent_info *fieinfo, size +=3D F2FS_BLKSIZE; } } else if (map.m_flags & F2FS_MAP_DELALLOC) { - flags =3D FIEMAP_EXTENT_UNWRITTEN; + flags =3D FIEMAP_EXTENT_UNKNOWN | FIEMAP_EXTENT_DELALLOC; } =20 start_blk +=3D F2FS_BYTES_TO_BLK(size); --=20 2.20.1