Skip to content

Commit

Permalink
[IPV6]: Fix potential net leak and oops in ipv6 routing code.
Browse files Browse the repository at this point in the history
The commits f3db485 ([NETNS][IPV6] ip6_fib - fib6_clean_all handle several 
network namespaces) and 69ddb80 ([NETNS][IPV6] route6 - Make proc entry 
/proc/net/rt6_stats per namespace) made some proc files per net.

Both of them introduced potential OOPS - get_proc_net can return NULL, but
this check is lost - and a struct net leak - in case single_open() fails the
previously got net is not put.

Kill all these bugs with one patch.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Mar 26, 2008
1 parent 9b674e8 commit a233352
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions net/ipv6/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2390,10 +2390,18 @@ static int ipv6_route_show(struct seq_file *m, void *v)

static int ipv6_route_open(struct inode *inode, struct file *file)
{
int err;
struct net *net = get_proc_net(inode);
if (!net)
return -ENXIO;
return single_open(file, ipv6_route_show, net);

err = single_open(file, ipv6_route_show, net);
if (err < 0) {
put_net(net);
return err;
}

return 0;
}

static int ipv6_route_release(struct inode *inode, struct file *file)
Expand Down Expand Up @@ -2429,8 +2437,18 @@ static int rt6_stats_seq_show(struct seq_file *seq, void *v)

static int rt6_stats_seq_open(struct inode *inode, struct file *file)
{
int err;
struct net *net = get_proc_net(inode);
return single_open(file, rt6_stats_seq_show, net);
if (!net)
return -ENXIO;

err = single_open(file, rt6_stats_seq_show, net);
if (err < 0) {
put_net(net);
return err;
}

return 0;
}

static int rt6_stats_seq_release(struct inode *inode, struct file *file)
Expand Down

0 comments on commit a233352

Please sign in to comment.