]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
udf: Fix NULL pointer dereference in udf_symlink function
authorArturo Giusti <koredump@protonmail.com>
Tue, 18 May 2021 10:34:57 +0000 (12:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Jul 2021 14:22:37 +0000 (16:22 +0200)
[ Upstream commit fa236c2b2d4436d9f19ee4e5d5924e90ffd7bb43 ]

In function udf_symlink, epos.bh is assigned with the value returned
by udf_tgetblk. The function udf_tgetblk is defined in udf/misc.c
and returns the value of sb_getblk function that could be NULL.
Then, epos.bh is used without any check, causing a possible
NULL pointer dereference when sb_getblk fails.

This fix adds a check to validate the value of epos.bh.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=213083
Signed-off-by: Arturo Giusti <koredump@protonmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/udf/namei.c

index f34c545f4e54967a69fd0b25538e634138b9ec35..074560ad190e6cf7b4dbaa30c663adf9347f4c18 100644 (file)
@@ -945,6 +945,10 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
                                iinfo->i_location.partitionReferenceNum,
                                0);
                epos.bh = udf_tgetblk(sb, block);
+               if (unlikely(!epos.bh)) {
+                       err = -ENOMEM;
+                       goto out_no_entry;
+               }
                lock_buffer(epos.bh);
                memset(epos.bh->b_data, 0x00, bsize);
                set_buffer_uptodate(epos.bh);