[Cluster-devel] [PATCH] fs: gfs2: Fix a null-pointer dereference in gfs2_alloc_inode()

Steven Whitehouse swhiteho at redhat.com
Wed Jul 24 08:48:38 UTC 2019


Hi,

On 24/07/2019 09:43, Jia-Ju Bai wrote:
> 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.

The bug is in the tool I'm afraid. Since i_inode is the first element of 
ip, there is no NULL dereference here. A pointer to ip->i_inode and a 
pointer to ip are one and the same (bar the differing types) which is 
the reason that we return &ip->i_inode rather than just ip,

Steve.


>
> Signed-off-by: Jia-Ju Bai <baijiaju1990 at 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)




More information about the Cluster-devel mailing list