Skip to content

Commit

Permalink
ipv4: Fix refcount warning for new fib_info
Browse files Browse the repository at this point in the history
Ioana reported a refcount warning when booting over NFS:

[    5.042532] ------------[ cut here ]------------
[    5.047184] refcount_t: addition on 0; use-after-free.
[    5.052324] WARNING: CPU: 7 PID: 1 at lib/refcount.c:25 refcount_warn_saturate+0xa4/0x150
...
[    5.167201] Call trace:
[    5.169635]  refcount_warn_saturate+0xa4/0x150
[    5.174067]  fib_create_info+0xc00/0xc90
[    5.177982]  fib_table_insert+0x8c/0x620
[    5.181893]  fib_magic.isra.0+0x110/0x11c
[    5.185891]  fib_add_ifaddr+0xb8/0x190
[    5.189629]  fib_inetaddr_event+0x8c/0x140

fib_treeref needs to be set after kzalloc. The old code had a ++ which
led to the confusion when the int was replaced by a refcount_t.

Fixes: 7997689 ("net: convert fib_treeref from int to refcount_t")
Signed-off-by: David Ahern <[email protected]>
Reported-by: Ioana Ciornei <[email protected]>
Cc: Yajun Deng <[email protected]>
Tested-by: Matthieu Baerts <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
dsahern authored and kuba-moo committed Aug 2, 2021
1 parent 1187c8c commit 28814cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/ipv4/fib_semantics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
return ofi;
}

refcount_inc(&fi->fib_treeref);
refcount_set(&fi->fib_treeref, 1);
refcount_set(&fi->fib_clntref, 1);
spin_lock_bh(&fib_info_lock);
hlist_add_head(&fi->fib_hash,
Expand Down

0 comments on commit 28814cd

Please sign in to comment.