}
EXPORT_SYMBOL_GPL(proc_net_remove);
+struct net *get_proc_net(const struct inode *inode)
+{
+ return maybe_get_net(PDE_NET(PDE(inode)));
+}
+EXPORT_SYMBOL_GPL(get_proc_net);
+
static struct proc_dir_entry *proc_net_shadow;
static struct dentry *proc_net_shadow_dentry(struct dentry *parent,
return pde->parent->data;
}
-static inline struct net *PROC_NET(const struct inode *inode)
-{
- return PDE_NET(PDE(inode));
-}
+struct net *get_proc_net(const struct inode *inode);
struct proc_maps_private {
struct pid *pid;
return net;
}
+static inline struct net *maybe_get_net(struct net *net)
+{
+ /* Used when we know struct net exists but we
+ * aren't guaranteed a previous reference count
+ * exists. If the reference count is zero this
+ * function fails and returns NULL.
+ */
+ if (!atomic_inc_not_zero(&net->count))
+ net = NULL;
+ return net;
+}
+
static inline void put_net(struct net *net)
{
if (atomic_dec_and_test(&net->count))
res = seq_open(file, &dev_seq_ops);
if (!res) {
seq = file->private_data;
- seq->private = get_net(PROC_NET(inode));
+ seq->private = get_proc_net(inode);
+ if (!seq->private) {
+ seq_release(inode, file);
+ res = -ENXIO;
+ }
}
return res;
}
res = seq_open(file, &dev_mc_seq_ops);
if (!res) {
seq = file->private_data;
- seq->private = get_net(PROC_NET(inode));
+ seq->private = get_proc_net(inode);
+ if (!seq->private) {
+ seq_release(inode, file);
+ res = -ENXIO;
+ }
}
return res;
}
seq = file->private_data;
seq->private = iter;
- iter->net = get_net(PROC_NET(inode));
+ iter->net = get_proc_net(inode);
+ if (!iter->net) {
+ seq_release_private(inode, file);
+ return -ENXIO;
+ }
return 0;
}
res = seq_open(file, &wireless_seq_ops);
if (!res) {
seq = file->private_data;
- seq->private = get_net(PROC_NET(inode));
+ seq->private = get_proc_net(inode);
+ if (!seq->private) {
+ seq_release(inode, file);
+ res = -ENXIO;
+ }
}
return res;
}