linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] jfs: Fix NULL pointer dereference in diFree
@ 2021-08-26 11:16 Wang Hai
  0 siblings, 0 replies; only message in thread
From: Wang Hai @ 2021-08-26 11:16 UTC (permalink / raw)
  To: shaggy; +Cc: jfs-discussion, linux-kernel

I got a NULL pointer dereference report when doing fuzz test:

 jfs_mount: diMount failed w/rc = -5
 BUG: kernel NULL pointer dereference, address: 0000000000000004
 [...]
 RIP: 0010:diFree+0x5d/0xc70
 [...]
 jfs_evict_inode+0x136/0x180
 jfs_write_inode+0xc0/0xc0
 evict+0x102/0x1f0
 iput+0x220/0x2e0
 diFreeSpecial+0x44/0x70
 jfs_mount+0x1b1/0x460
 jfs_fill_super+0x1a5/0x460
 mount_bdev+0x1d7/0x220
 jfs_do_mount+0x39/0x50
 legacy_get_tree+0x2f/0x80
 vfs_get_tree+0x2f/0x100
 path_mount+0x8e8/0xc7
 do_mount+0x9e/0xc0
 __x64_sys_mount+0xc5/0x140
 do_syscall_64+0x34/0xb0
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Similar to commit 9d574f985fe3 ("jfs: fix GPF in diFree"),
diFreeSpecial(ipimap)->..->diFree() will be called if diMount(ipimap)
fails in jfs_mount(). This will result in a null pointer reference in
diFree() because the imap is not allocated in diFreeSpecial().

int diFree(struct inode *ip)
{
	...
	struct inomap *imap = JFS_IP(ipimap)->i_imap; // imap == NULL
	...
	if (iagno >= imap->im_nextiag) { // null pointer reference
	...
}

If diFreeSpecial(ipimap) in jfs_mount() fails, there is no need to
call diFree(), because diAlloc() is not called in the mount process.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 fs/jfs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 57ab424c05ff..e8303d47a4a4 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -146,12 +146,14 @@ void jfs_evict_inode(struct inode *inode)
 		dquot_initialize(inode);
 
 		if (JFS_IP(inode)->fileset == FILESYSTEM_I) {
+			struct inode *ipimap = JFS_SBI(inode->i_sb)->ipimap;
+
 			truncate_inode_pages_final(&inode->i_data);
 
 			if (test_cflag(COMMIT_Freewmap, inode))
 				jfs_free_zero_link(inode);
 
-			if (JFS_SBI(inode->i_sb)->ipimap)
+			if (ipimap && JFS_IP(ipimap)->i_imap)
 				diFree(inode);
 
 			/*
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-26 11:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 11:16 [PATCH] jfs: Fix NULL pointer dereference in diFree Wang Hai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).