Skip to content

Commit e773aaf

Browse files
Jiri Pirkodavem330
authored andcommitted
l2tp: fix memory allocation
Since .size is set properly in "struct pernet_operations l2tp_net_ops", allocating space for "struct l2tp_net" by hand is not correct, even causes memory leakage. Signed-off-by: Jiri Pirko <jpirko@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3b51cc9 commit e773aaf

1 file changed

Lines changed: 1 addition & 28 deletions

File tree

‎net/l2tp/l2tp_core.c‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,14 +1617,9 @@ EXPORT_SYMBOL_GPL(l2tp_session_create);
16171617

16181618
static __net_init int l2tp_init_net(struct net *net)
16191619
{
1620-
struct l2tp_net *pn;
1621-
int err;
1620+
struct l2tp_net *pn = net_generic(net, l2tp_net_id);
16221621
int hash;
16231622

1624-
pn = kzalloc(sizeof(*pn), GFP_KERNEL);
1625-
if (!pn)
1626-
return -ENOMEM;
1627-
16281623
INIT_LIST_HEAD(&pn->l2tp_tunnel_list);
16291624
spin_lock_init(&pn->l2tp_tunnel_list_lock);
16301625

@@ -1633,33 +1628,11 @@ static __net_init int l2tp_init_net(struct net *net)
16331628

16341629
spin_lock_init(&pn->l2tp_session_hlist_lock);
16351630

1636-
err = net_assign_generic(net, l2tp_net_id, pn);
1637-
if (err)
1638-
goto out;
1639-
16401631
return 0;
1641-
1642-
out:
1643-
kfree(pn);
1644-
return err;
1645-
}
1646-
1647-
static __net_exit void l2tp_exit_net(struct net *net)
1648-
{
1649-
struct l2tp_net *pn;
1650-
1651-
pn = net_generic(net, l2tp_net_id);
1652-
/*
1653-
* if someone has cached our net then
1654-
* further net_generic call will return NULL
1655-
*/
1656-
net_assign_generic(net, l2tp_net_id, NULL);
1657-
kfree(pn);
16581632
}
16591633

16601634
static struct pernet_operations l2tp_net_ops = {
16611635
.init = l2tp_init_net,
1662-
.exit = l2tp_exit_net,
16631636
.id = &l2tp_net_id,
16641637
.size = sizeof(struct l2tp_net),
16651638
};

0 commit comments

Comments
 (0)