From c240cbb8dce0fda55c526fb6c291da7e04a9ab37 Mon Sep 17 00:00:00 2001 From: Yilin Li <22371230@buaa.edu.cn> Date: Thu, 8 May 2025 10:27:10 +0800 Subject: [PATCH] nilfs2: add pointer check for nilfs_direct_propagate() linux-next inclusion category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/IC61W6 ------------------------------------ from linux-next-20250501 commit df010bbe185f58cd750bdfa827c89703032d8355 This fixes one missed check for block mapping anomalies and one improper return of an error code during a preparation step for log writing, thereby improving checking for filesystem corruption on writeback. This patch (of 2): In nilfs_direct_propagate(), the pointer obtained from nilfs_direct_get_ptr() needs to be checked to ensure it is not an invalid pointer (NILFS_BMAP_INVALID_PTR). Add a check and return -EINVAL when invalid, preventing further corruption. Fixes: 36a580eb489f ("nilfs2: direct block mapping") Signed-off-by: Yilin Li <22371230@buaa.edu.cn> --- fs/nilfs2/direct.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/nilfs2/direct.c b/fs/nilfs2/direct.c index 8d769c5dd5dc..0334b33071c0 100644 --- a/fs/nilfs2/direct.c +++ b/fs/nilfs2/direct.c @@ -273,6 +273,8 @@ static int nilfs_direct_propagate(struct nilfs_bmap *bmap, dat = nilfs_bmap_get_dat(bmap); key = nilfs_bmap_data_get_key(bmap, bh); ptr = nilfs_direct_get_ptr(bmap, key); + if (ptr == NILFS_BMAP_INVALID_PTR) + return -EINVAL; if (!buffer_nilfs_volatile(bh)) { oldreq.pr_entry_nr = ptr; newreq.pr_entry_nr = ptr; -- Gitee