linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: gfs2: Fix a null-pointer dereference in gfs2_alloc_inode()
@ 2019-07-24  8:43 Jia-Ju Bai
  2019-07-24 10:00 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2019-07-24  8:43 UTC (permalink / raw)
  To: rpeterso, agruenba; +Cc: cluster-devel, linux-kernel, Jia-Ju Bai

In gfs2_alloc_inode(), when kmem_cache_alloc() on line 1724 returns
NULL, ip is assigned to NULL. In this case, "return &ip->i_inode" will
cause a null-pointer dereference.

To fix this null-pointer dereference, NULL is returned when ip is NULL.

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 fs/gfs2/super.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 0acc5834f653..c07c3f4f8451 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1728,8 +1728,9 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
 		memset(&ip->i_res, 0, sizeof(ip->i_res));
 		RB_CLEAR_NODE(&ip->i_res.rs_node);
 		ip->i_rahead = 0;
-	}
-	return &ip->i_inode;
+		return &ip->i_inode;
+	} else
+		return NULL;
 }
 
 static void gfs2_free_inode(struct inode *inode)
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs: gfs2: Fix a null-pointer dereference in gfs2_alloc_inode()
  2019-07-24  8:43 [PATCH] fs: gfs2: Fix a null-pointer dereference in gfs2_alloc_inode() Jia-Ju Bai
@ 2019-07-24 10:00 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2019-07-24 10:00 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: rpeterso, agruenba, cluster-devel, linux-kernel

On Wed, Jul 24, 2019 at 04:43:03PM +0800, Jia-Ju Bai wrote:
> index 0acc5834f653..c07c3f4f8451 100644
> --- a/fs/gfs2/super.c
> +++ b/fs/gfs2/super.c
> @@ -1728,8 +1728,9 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
>  		memset(&ip->i_res, 0, sizeof(ip->i_res));
>  		RB_CLEAR_NODE(&ip->i_res.rs_node);
>  		ip->i_rahead = 0;
> -	}
> -	return &ip->i_inode;
> +		return &ip->i_inode;
> +	} else
> +		return NULL;
>  }

No need for an else after a return.  You probably just want to
return early for the NULL case.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-24 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-24  8:43 [PATCH] fs: gfs2: Fix a null-pointer dereference in gfs2_alloc_inode() Jia-Ju Bai
2019-07-24 10:00 ` Christoph Hellwig

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).