[lvc-project] [PATCH 1/1] udf: Fix null-ptr-deref in udf_write_fi()

Fedor Pchelkin pchelkin at ispras.ru
Sat Jan 7 22:50:16 MSK 2023


udf_find_entry() can return NULL or an error pointer if it fails. So we
should check its return value to avoid NULL pointer dereferencing in
udf_write_fi() (which is called from udf_delete_entry()). Also, if
udf_find_entry() returns an error pointer, it is possible that ofibh and
ocfi structs hold invalid values which can cause additional problems in
udf_write_fi().

If udf_find_entry() returns an error pointer, udf_rename() should return
with an error code. If udf_find_entry() returns NULL, ofi has probably
already been deleted.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 231473f6ddce ("udf: Return error from udf_find_entry()")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+8a5a459f324d510ea15a at syzkaller.appspotmail.com
Signed-off-by: Fedor Pchelkin <pchelkin at ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov at ispras.ru>
---
 fs/udf/namei.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 7c95c549dd64..6b058c6ebf93 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -1170,7 +1170,12 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
 
 	/* The old fid may have moved - find it again */
 	ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
-	udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);
+	if (ofi && IS_ERR(ofi)) {
+		retval = PTR_ERR(ofi);
+		goto end_rename;
+	} else if (ofi) {
+		udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);
+	}
 
 	if (new_inode) {
 		new_inode->i_ctime = current_time(new_inode);
-- 
2.34.1




More information about the lvc-project mailing list