get_net_ns_by_fd() oopses if proc_ns_fget() returns an error

BTW, looking through the code related to struct net lifetime rules has
caught something else:

struct net *get_net_ns_by_fd(int fd)
{
        ...
        file = proc_ns_fget(fd);
        if (!file)
                goto out;

        ei = PROC_I(file->f_dentry->d_inode);

while in proc_ns_fget() we have two return ERR_PTR(...) and not a single
path that would return NULL.  The other caller of proc_ns_fget() treats
ERR_PTR() correctly...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Al Viro 2011-06-05 00:37:35 +00:00 committed by David S. Miller
parent 23c79d31a3
commit c316e6a308

View File

@ -310,18 +310,16 @@ struct net *get_net_ns_by_fd(int fd)
struct file *file; struct file *file;
struct net *net; struct net *net;
net = ERR_PTR(-EINVAL);
file = proc_ns_fget(fd); file = proc_ns_fget(fd);
if (!file) if (IS_ERR(file))
goto out; return ERR_CAST(file);
ei = PROC_I(file->f_dentry->d_inode); ei = PROC_I(file->f_dentry->d_inode);
if (ei->ns_ops != &netns_operations) if (ei->ns_ops == &netns_operations)
goto out;
net = get_net(ei->ns); net = get_net(ei->ns);
out: else
if (file) net = ERR_PTR(-EINVAL);
fput(file); fput(file);
return net; return net;
} }