Fix a drop_nlink warning in minix_rmdir
PATCH 1/1 Fix a drop_nlink warning in minix_rmdir
Syzbot found a drop_nlink warning that is triggered by an easy to detect nlink corruption of a directory. This patch adds a sanity check to minix_rmdir to prevent the warning and instead return EFSCORRUPTED to the caller.
The changes were tested using the syzbot reproducer as well as local testing.
--- fs/minix/minix.h | 2 ++ fs/minix/namei.c | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)
fs/minix/minix.h +2 -0
@@ -168,4 +168,6 @@ static inline int minix_test_bit(int nr, const void *vaddr)#endif +#define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */ +#endif /* FS_MINIX_H */
fs/minix/namei.c +18 -8
@@ -161,15 +161,25 @@ static int minix_unlink(struct inode * dir, struct dentry *dentry)static int minix_rmdir (struct inode * dir,struct dentry *dentry) {struct inode * inode =d_inode (dentry); -int err = -ENOTEMPTY ; - -if (minix_empty_dir (inode)) { - err =minix_unlink (dir, dentry); -if (!err) { -inode_dec_link_count (dir); -inode_dec_link_count (inode); - } +int err = -EFSCORRUPTED ; + +if (dir->i_nlink <=2 ) { +printk (KERN_CRIT "minix-fs error: directory inode has " +"corrupted nlink" ); + goto out; } + + err = -ENOTEMPTY ; +if (!minix_empty_dir (inode)) + goto out; + + err =minix_unlink (dir, dentry); +if (!err) { +inode_dec_link_count (dir); +inode_dec_link_count (inode); + } + +out:return err; }
Signature · 1 line
2.51.1.dirty
Quoted 11 lines · Jori Koolstra
Syzbot found a
drop_nlinkwarning that is triggered by an easy to detect nlink corruption of a directory. This patch adds a sanity check tominix_rmdirto prevent the warning and instead return EFSCORRUPTED to the caller.The changes were tested using the syzbot reproducer as well as local testing.
Signed-off-by Jori Koolstra <[email protected]>Reported-by [email protected]
Looks good, just one nit below. With that fixed feel free to add:
Quoted 11 lines
fs/minix/namei.c +0
-3@@ -161,15 +161,25 @@ static int minix_unlink(struct inode * dir, struct dentry *dentry)static int minix_rmdir (struct inode * dir,struct dentry *dentry) {struct inode * inode =d_inode (dentry); -int err = -ENOTEMPTY ; - -if (minix_empty_dir (inode)) {
fs/minix/namei.c static int minix_unlink(struct inode * dir, struct dentry *dentry) · line 168
Quoted 10 lines
fs/minix/namei.c +5
-5- err =minix_unlink (dir, dentry); -if (!err) { -inode_dec_link_count (dir); -inode_dec_link_count (inode); - } +int err = -EFSCORRUPTED ; + +if (dir->i_nlink <=2 ) { +printk (KERN_CRIT "minix-fs error: directory inode has " +"corrupted nlink" );
We usually print inode number (dir->i_ino) with such errors in minix.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Hello Jan,
Quoted 5 lines
Looks good, just one nit below. With that fixed feel free to add:
Reviewed-by Jan Kara <[email protected]>
Will do. Question: I have fixed another syzbot bug report in minix_rename/unlink and posted the patch. I figured that because they target different syzbot reports, they should be separate patches. However, I forgot to add the EFSCORRUPTED define in that patch (but did include it in the #syz test). What is the best way to rectify that and add your suggestion to this patch? Or should it be a single patch, or a series? I want to cause as little work as possible for you and other maintainers.
Thanks,
Jori.
Hello Jori!
Quoted 11 lines · Jori Koolstra
Quoted 3 lines
Looks good, just one nit below. With that fixed feel free to add:
Reviewed-by Jan Kara <[email protected]>Will do. Question: I have fixed another syzbot bug report in minix_rename/unlink and posted the patch. I figured that because they target different syzbot reports, they should be separate patches. However, I forgot to add the EFSCORRUPTED define in that patch (but did include it in the #syz test). What is the best way to rectify that and add your suggestion to this patch? Or should it be a single patch, or a series? I want to cause as little work as possible for you and other maintainers.
The most natural would be to submit these two patches in a single series since they are actually related.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR