Commit c316e6a3084cef1a5857cd66bb5429c969f06c93

Authored by Al Viro
Committed by David S. Miller
1 parent 23c79d31a3

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>

Showing 1 changed file with 7 additions and 9 deletions Side-by-side Diff

net/core/net_namespace.c
... ... @@ -310,19 +310,17 @@
310 310 struct file *file;
311 311 struct net *net;
312 312  
313   - net = ERR_PTR(-EINVAL);
314 313 file = proc_ns_fget(fd);
315   - if (!file)
316   - goto out;
  314 + if (IS_ERR(file))
  315 + return ERR_CAST(file);
317 316  
318 317 ei = PROC_I(file->f_dentry->d_inode);
319   - if (ei->ns_ops != &netns_operations)
320   - goto out;
  318 + if (ei->ns_ops == &netns_operations)
  319 + net = get_net(ei->ns);
  320 + else
  321 + net = ERR_PTR(-EINVAL);
321 322  
322   - net = get_net(ei->ns);
323   -out:
324   - if (file)
325   - fput(file);
  323 + fput(file);
326 324 return net;
327 325 }
328 326