* [PATCH 0/2] nilfs2: improve sanity checks in dirty state propagation
@ 2025-04-28 17:37 Ryusuke Konishi
2025-04-28 17:37 ` [PATCH 1/2] nilfs2: Add pointer check for nilfs_direct_propagate() Ryusuke Konishi
2025-04-28 17:37 ` [PATCH 2/2] nilfs2: do not propagate ENOENT error from nilfs_btree_propagate() Ryusuke Konishi
0 siblings, 2 replies; 3+ messages in thread
From: Ryusuke Konishi @ 2025-04-28 17:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-nilfs, linux-kernel, Wentao Liang
Hi Andrew, please queue this series for the next merge cycle.
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.
Thanks,
Ryusuke Konishi
Ryusuke Konishi (1):
nilfs2: do not propagate ENOENT error from nilfs_btree_propagate()
Wentao Liang (1):
nilfs2: Add pointer check for nilfs_direct_propagate()
fs/nilfs2/btree.c | 4 +++-
fs/nilfs2/direct.c | 3 +++
2 files changed, 6 insertions(+), 1 deletion(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] nilfs2: Add pointer check for nilfs_direct_propagate()
2025-04-28 17:37 [PATCH 0/2] nilfs2: improve sanity checks in dirty state propagation Ryusuke Konishi
@ 2025-04-28 17:37 ` Ryusuke Konishi
2025-04-28 17:37 ` [PATCH 2/2] nilfs2: do not propagate ENOENT error from nilfs_btree_propagate() Ryusuke Konishi
1 sibling, 0 replies; 3+ messages in thread
From: Ryusuke Konishi @ 2025-04-28 17:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-nilfs, linux-kernel, Wentao Liang
From: Wentao Liang <vulab@iscas.ac.cn>
In nilfs_direct_propagate(), the printer get from nilfs_direct_get_ptr()
need to be checked to ensure it is not an invalid pointer.
If the pointer value obtained by nilfs_direct_get_ptr() is
NILFS_BMAP_INVALID_PTR, means that the metadata (in this case,
i_bmap in the nilfs_inode_info struct) that should point to the data
block at the buffer head of the argument is corrupted and the data
block is orphaned, meaning that the file system has lost consistency.
Add a value check and return -EINVAL when it is an invalid pointer.
Fixes: 36a580eb489f ("nilfs2: direct block mapping")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
fs/nilfs2/direct.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/nilfs2/direct.c b/fs/nilfs2/direct.c
index 893ab36824cc..2d8dc6b35b54 100644
--- a/fs/nilfs2/direct.c
+++ b/fs/nilfs2/direct.c
@@ -273,6 +273,9 @@ 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;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] nilfs2: do not propagate ENOENT error from nilfs_btree_propagate()
2025-04-28 17:37 [PATCH 0/2] nilfs2: improve sanity checks in dirty state propagation Ryusuke Konishi
2025-04-28 17:37 ` [PATCH 1/2] nilfs2: Add pointer check for nilfs_direct_propagate() Ryusuke Konishi
@ 2025-04-28 17:37 ` Ryusuke Konishi
1 sibling, 0 replies; 3+ messages in thread
From: Ryusuke Konishi @ 2025-04-28 17:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-nilfs, linux-kernel, Wentao Liang
In preparation for writing logs, in nilfs_btree_propagate(), which
makes parent and ancestor node blocks dirty starting from a modified
data block or b-tree node block, if the starting block does not belong
to the b-tree, i.e. is isolated, nilfs_btree_do_lookup() called within
the function fails with -ENOENT.
In this case, even though -ENOENT is an internal code, it is
propagated to the log writer via nilfs_bmap_propagate() and may be
erroneously returned to system calls such as fsync().
Fix this issue by changing the error code to -EINVAL in this case, and
having the bmap layer detect metadata corruption and convert the error
code appropriately.
Fixes: 1f5abe7e7dbc ("nilfs2: replace BUG_ON and BUG calls triggerable from ioctl")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
fs/nilfs2/btree.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 0d8f7fb15c2e..dd0c8e560ef6 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -2102,11 +2102,13 @@ static int nilfs_btree_propagate(struct nilfs_bmap *btree,
ret = nilfs_btree_do_lookup(btree, path, key, NULL, level + 1, 0);
if (ret < 0) {
- if (unlikely(ret == -ENOENT))
+ if (unlikely(ret == -ENOENT)) {
nilfs_crit(btree->b_inode->i_sb,
"writing node/leaf block does not appear in b-tree (ino=%lu) at key=%llu, level=%d",
btree->b_inode->i_ino,
(unsigned long long)key, level);
+ ret = -EINVAL;
+ }
goto out;
}
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-28 17:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-28 17:37 [PATCH 0/2] nilfs2: improve sanity checks in dirty state propagation Ryusuke Konishi
2025-04-28 17:37 ` [PATCH 1/2] nilfs2: Add pointer check for nilfs_direct_propagate() Ryusuke Konishi
2025-04-28 17:37 ` [PATCH 2/2] nilfs2: do not propagate ENOENT error from nilfs_btree_propagate() Ryusuke Konishi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®