diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2007-09-13 03:18:57 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:49:22 -0400 |
commit | 077130c0cf7d5ba1992f5b51b96136d7b1c8aad5 (patch) | |
tree | c8fd2622e7d633cc504c7543b55e25bd6d99a2fa /fs | |
parent | 4fabcd7118162e36eea5c53e8895ecc13762bef3 (diff) |
[NET]: Fix race when opening a proc file while a network namespace is exiting.
The problem: proc_net files remember which network namespace the are
against but do not remember hold a reference count (as that would pin
the network namespace). So we currently have a small window where
the reference count on a network namespace may be incremented when opening
a /proc file when it has already gone to zero.
To fix this introduce maybe_get_net and get_proc_net.
maybe_get_net increments the network namespace reference count only if it is
greater then zero, ensuring we don't increment a reference count after it
has gone to zero.
get_proc_net handles all of the magic to go from a proc inode to the network
namespace instance and call maybe_get_net on it.
PROC_NET the old accessor is removed so that we don't get confused and use
the wrong helper function.
Then I fix up the callers to use get_proc_net and handle the case case
where get_proc_net returns NULL. In that case I return -ENXIO because
effectively the network namespace has already gone away so the files
we are trying to access don't exist anymore.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Acked-by: Paul E. McKenney <paulmck@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/proc/proc_net.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c index 358930a3142a..85cc8e8bb862 100644 --- a/fs/proc/proc_net.c +++ b/fs/proc/proc_net.c | |||
@@ -51,6 +51,12 @@ void proc_net_remove(struct net *net, const char *name) | |||
51 | } | 51 | } |
52 | EXPORT_SYMBOL_GPL(proc_net_remove); | 52 | EXPORT_SYMBOL_GPL(proc_net_remove); |
53 | 53 | ||
54 | struct net *get_proc_net(const struct inode *inode) | ||
55 | { | ||
56 | return maybe_get_net(PDE_NET(PDE(inode))); | ||
57 | } | ||
58 | EXPORT_SYMBOL_GPL(get_proc_net); | ||
59 | |||
54 | static struct proc_dir_entry *proc_net_shadow; | 60 | static struct proc_dir_entry *proc_net_shadow; |
55 | 61 | ||
56 | static struct dentry *proc_net_shadow_dentry(struct dentry *parent, | 62 | static struct dentry *proc_net_shadow_dentry(struct dentry *parent, |