Skip to content

Commit 114414b

Browse files
edumazetgregkh
authored andcommitted
ipv4: fix NULL dereference in free_fib_info_rcu()
[ Upstream commit 187e5b3ac84d3421d2de3aca949b2791fbcad554 ] If fi->fib_metrics could not be allocated in fib_create_info() we attempt to dereference a NULL pointer in free_fib_info_rcu() : m = fi->fib_metrics; if (m != &dst_default_metrics && atomic_dec_and_test(&m->refcnt)) kfree(m); Before my recent patch, we used to call kfree(NULL) and nothing wrong happened. Instead of using RCU to defer freeing while we are under memory stress, it seems better to take immediate action. This was reported by syzkaller team. Fixes: 3fb07daff8e9 ("ipv4: add reference counting to metrics") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c207ec4 commit 114414b

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

net/ipv4/fib_semantics.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,17 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
10441044
fi = kzalloc(sizeof(*fi)+nhs*sizeof(struct fib_nh), GFP_KERNEL);
10451045
if (!fi)
10461046
goto failure;
1047-
fib_info_cnt++;
10481047
if (cfg->fc_mx) {
10491048
fi->fib_metrics = kzalloc(sizeof(*fi->fib_metrics), GFP_KERNEL);
1050-
if (!fi->fib_metrics)
1051-
goto failure;
1049+
if (unlikely(!fi->fib_metrics)) {
1050+
kfree(fi);
1051+
return ERR_PTR(err);
1052+
}
10521053
atomic_set(&fi->fib_metrics->refcnt, 1);
1053-
} else
1054+
} else {
10541055
fi->fib_metrics = (struct dst_metrics *)&dst_default_metrics;
1055-
1056+
}
1057+
fib_info_cnt++;
10561058
fi->fib_net = net;
10571059
fi->fib_protocol = cfg->fc_protocol;
10581060
fi->fib_scope = cfg->fc_scope;

0 commit comments

Comments
 (0)