[PATCH] udf: Prevent rmdir of deleted directories

Leo Stone posted 1 patch 1 year, 2 months ago
fs/udf/namei.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] udf: Prevent rmdir of deleted directories
Posted by Leo Stone 1 year, 2 months ago
The syzbot reproducer mounts a UDF image with the undelete option
enabled. It then creates a directory, and eventually attempts to call
rmdir on it 65 times. Because the undelete option is set, the
directory still gets found in udf_fiiter_find_entry(), and the link
count of its parent directory is decremented until it triggers the
warning in drop_nlink().

Prevent directories with the FID_FILE_CHAR_DELETED flag set from being
deleted again.

#syz test

Reported-by: syzbot+5df2d3fa14f2d3e49305@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5df2d3fa14f2d3e49305
Signed-off-by: Leo Stone <leocstone@gmail.com>
---
 fs/udf/namei.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 78a603129dd5..0a577b7459de 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -504,6 +504,12 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
 	if (ret)
 		goto out;
 
+	if (iter.fi.fileCharacteristics & FID_FILE_CHAR_DELETED) {
+		udf_warn(inode->i_sb,
+			 "tried to rmdir a directory that was already deleted\n");
+		ret = -ENOENT;
+		goto end_rmdir;
+	}
 	ret = -EFSCORRUPTED;
 	tloc = lelb_to_cpu(iter.fi.icb.extLocation);
 	if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino)
-- 
2.43.0
Re: [PATCH] udf: Prevent rmdir of deleted directories
Posted by Jan Kara 1 year, 2 months ago
On Sun 01-12-24 16:41:02, Leo Stone wrote:
> The syzbot reproducer mounts a UDF image with the undelete option
> enabled. It then creates a directory, and eventually attempts to call
> rmdir on it 65 times. Because the undelete option is set, the
> directory still gets found in udf_fiiter_find_entry(), and the link
> count of its parent directory is decremented until it triggers the
> warning in drop_nlink().
> 
> Prevent directories with the FID_FILE_CHAR_DELETED flag set from being
> deleted again.
> 
> #syz test
> 
> Reported-by: syzbot+5df2d3fa14f2d3e49305@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5df2d3fa14f2d3e49305
> Signed-off-by: Leo Stone <leocstone@gmail.com>

Thanks for looking into this but the fix is already queued into my tree and
I'll send it to Linus today.

								Honza

> ---
>  fs/udf/namei.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/udf/namei.c b/fs/udf/namei.c
> index 78a603129dd5..0a577b7459de 100644
> --- a/fs/udf/namei.c
> +++ b/fs/udf/namei.c
> @@ -504,6 +504,12 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
>  	if (ret)
>  		goto out;
>  
> +	if (iter.fi.fileCharacteristics & FID_FILE_CHAR_DELETED) {
> +		udf_warn(inode->i_sb,
> +			 "tried to rmdir a directory that was already deleted\n");
> +		ret = -ENOENT;
> +		goto end_rmdir;
> +	}
>  	ret = -EFSCORRUPTED;
>  	tloc = lelb_to_cpu(iter.fi.icb.extLocation);
>  	if (udf_get_lb_pblock(dir->i_sb, &tloc, 0) != inode->i_ino)
> -- 
> 2.43.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
Re: [syzbot] [udf?] WARNING in udf_rmdir (2)
Posted by syzbot 1 year, 2 months ago
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+5df2d3fa14f2d3e49305@syzkaller.appspotmail.com
Tested-by: syzbot+5df2d3fa14f2d3e49305@syzkaller.appspotmail.com

Tested on:

commit:         40384c84 Linux 6.13-rc1
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=135195e8580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=55aba29dc49cabd6
dashboard link: https://syzkaller.appspot.com/bug?extid=5df2d3fa14f2d3e49305
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=17faa0df980000

Note: testing is done by a robot and is best-effort only.