Skip to content

Commit 7396ba8

Browse files
Conchy-Conchydavem330
authored andcommitted
net: fix potential refcount leak in ndisc_router_discovery()
The issue happens on specific paths in the function. After both the object `rt` and `neigh` are grabbed successfully, when `lifetime` is nonzero but the metric needs change, the function just deletes the route and set `rt` to NULL. Then, it may try grabbing `rt` and `neigh` again if above conditions hold. The function simply overwrite `neigh` if succeeds or returns if fails, without decreasing the reference count of previous `neigh`. This may result in memory leaks. Fix it by decrementing the reference count of `neigh` in place. Fixes: 6b2e04b ("net: allow user to set metric on default route learned via Router Advertisement") Signed-off-by: Xin Xiong <[email protected]> Signed-off-by: Xin Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 27b8d4d commit 7396ba8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/ipv6/ndisc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
13781378
if (!rt && lifetime) {
13791379
ND_PRINTK(3, info, "RA: adding default router\n");
13801380

1381+
if (neigh)
1382+
neigh_release(neigh);
1383+
13811384
rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr,
13821385
skb->dev, pref, defrtr_usr_metric);
13831386
if (!rt) {

0 commit comments

Comments
 (0)