Re: [syzbot] net-next boot error: WARNING: refcount bug in fib_create_info

From: David Ahern
Date: Tue Aug 03 2021 - 18:32:14 EST


On 8/3/21 3:04 PM, Jakub Kicinski wrote:
>>>
>>> diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
>>> index f29feb7772da..bb9949f6bb70 100644
>>> --- a/net/ipv4/fib_semantics.c
>>> +++ b/net/ipv4/fib_semantics.c
>>> @@ -1428,6 +1428,7 @@ struct fib_info *fib_create_info(struct fib_config
>>> *cfg,
>>> }
>>>
>>> fib_info_cnt++;
>>> + refcount_set(&fi->fib_treeref, 1);
>>> fi->fib_net = net;
>>> fi->fib_protocol = cfg->fc_protocol;
>>> fi->fib_scope = cfg->fc_scope;
>>
>> Oops, it's already fixed in -next, so
>>
>> #syz fix: ipv4: Fix refcount warning for new fib_info
>>
>>
>> BTW: there is one more bug with refcounts:
>>
>> link_it:
>> ofi = fib_find_info(fi);
>> if (ofi) {
>> fi->fib_dead = 1;
>> free_fib_info(fi);
>> refcount_inc(&ofi->fib_treeref);
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^
>> / *fib_treeref is 0 here */
>
> Why 0? ofi is an existing object it's already initialized.

yes, it is an existing object with a non-0 refcount.

>
>> return ofi;
>> }
>>
>> refcount_set(&fi->fib_treeref, 1);
>>
>>
>> diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
>> index f29feb7772da..38d1fc4d0be1 100644
>> --- a/net/ipv4/fib_semantics.c
>> +++ b/net/ipv4/fib_semantics.c
>> @@ -1543,6 +1543,8 @@ struct fib_info *fib_create_info(struct fib_config
>> *cfg,
>> }
>>
>> link_it:
>> + refcount_set(&fi->fib_treeref, 1);

moving the refcount_set here causes all kinds of problems with the
release and error paths in this function.