From nobody Tue Dec 23 14:22:01 2025 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A70F231A2C for ; Mon, 13 Jan 2025 05:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736747870; cv=none; b=lsiuas+f/mMEJ7JQ6bdBYodzw51zIw++6nDXnDJBjQkwKOyCfWyTveXQGgiYO+dndebvOcKw9wb9f7kKVihVns3Vx6EaXbqE5TQQ1fLJjylIzCGtzEIqChdnQ/0uDH+8lte3pXpoQxoOO5G2iyaE+xdHyezmaqeGguHy14LKUkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736747870; c=relaxed/simple; bh=7sAlP5rYCBTO8bbyocpOdicYA8Z01l8hbQOCTXvJkUg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=q07AEpf4vpcD2v93sdDVriYd41slbqAf8DlVylZkd5P8zIj36hkqiA4m5M17CcopGusZnKKCjZ1cRWdUAY2DDC0f5VmbC7BtxOFQzm3b7ypVwMyIXsGQhjzDGPd082ENTS9doPaUElDRfx8G5tlHyocL1/xS8DqqhiPZHIwn/FA= 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=JZqIIy9B; arc=none smtp.client-ip=117.135.210.2 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="JZqIIy9B" 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=JZqIIy9Bew8z8gIlqqUtW yyT/fXmQoZP8gFioRGzTqCHIaEMLAYjv+B3dzbqGn0JLXxkGQD9JkUv2nL/LAOLu FT8Bv+jD3D3MRNOYLYWfhKyq0zdXNcppcjbzndzXuGhPIMwHXXaSowpSAQp10XPL AfkJi0d7sPQ4aDIZaWDzeE= Received: from czq-PC.mioffice.cn (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wAXaz4xq4RnZFVJFw--.52282S2; Mon, 13 Jan 2025 13:57:05 +0800 (CST) From: chenzhangqi79@163.com To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chenzhangqi@xiaomi.com, Zhijun Li Subject: [PATCH V0 RESEND] f2fs: fix error map extent flag while block not allocated Date: Mon, 13 Jan 2025 13:57:02 +0800 Message-Id: <20250113055702.1347172-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: _____wAXaz4xq4RnZFVJFw--.52282S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WrWrZw4rAw4kZF4rCw1Utrb_yoW8XFWUpa 4Y9F18GFn5uF4Uu39FqF1kWanY93ykKrZYkayruw1qvr13Jr9YkFn8Ka4vqF1xKF4kCF15 tr1SkryfGF4UAFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j5NVgUUUUU= X-CM-SenderInfo: hfkh065kdqw1rlxzqiywtou0bp/1tbi7gDSnWeDJQE98wABsu 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