[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230107195016.290627-2-pchelkin@ispras.ru>
Date: Sat, 7 Jan 2023 22:50:16 +0300
From: Fedor Pchelkin <pchelkin@...ras.ru>
To: Jan Kara <jack@...e.com>
Cc: Fedor Pchelkin <pchelkin@...ras.ru>, linux-kernel@...r.kernel.org,
Alexey Khoroshilov <khoroshilov@...ras.ru>,
lvc-project@...uxtesting.org,
syzbot+8a5a459f324d510ea15a@...kaller.appspotmail.com
Subject: [PATCH 1/1] udf: Fix null-ptr-deref in udf_write_fi()
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@...kaller.appspotmail.com
Signed-off-by: Fedor Pchelkin <pchelkin@...ras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@...ras.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
Powered by blists - more mailing lists