[Cluster-devel] [PATCH] GFS2: Fix potential NULL dereference in gfs2_alloc_inode

Andrew Price anprice at redhat.com
Mon Mar 2 16:30:06 UTC 2015


On 02/03/15 16:17, Steven Whitehouse wrote:
> Hi,
>
> On 02/03/15 16:15, Andrew Price wrote:
>> Return NULL when ip is NULL instead of dereferencing it.
>>
>> Signed-off-by: Andrew Price <anprice at redhat.com>
>> ---
>>   fs/gfs2/super.c | 13 +++++++------
>>   1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
>> index 1666382..37c59ee 100644
>> --- a/fs/gfs2/super.c
>> +++ b/fs/gfs2/super.c
>> @@ -1628,12 +1628,13 @@ static struct inode *gfs2_alloc_inode(struct
>> super_block *sb)
>>       struct gfs2_inode *ip;
>>       ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
>> -    if (ip) {
>> -        ip->i_flags = 0;
>> -        ip->i_gl = NULL;
>> -        ip->i_rgd = NULL;
>> -        ip->i_res = NULL;
>> -    }
>> +    if (!ip)
>> +        return NULL;
>> +
>> +    ip->i_flags = 0;
>> +    ip->i_gl = NULL;
>> +    ip->i_rgd = NULL;
>> +    ip->i_res = NULL;
>>       return &ip->i_inode;
>>   }
>
> I'm not sure that I see the problem here... it should just return NULL
> if ip is NULL, since ip->i_inode is the first element of ip,

Ah, so it is. Self-NACK then.

Andy




More information about the Cluster-devel mailing list