[NETFILTER]: Replate direct proc_fops assignment with proc_create call.
authorDenis V. Lunev <den@openvz.org>
Thu, 27 Mar 2008 23:55:53 +0000 (16:55 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Mar 2008 23:55:53 +0000 (16:55 -0700)
This elliminates infamous race during module loading when one could lookup
proc entry without proc_fops assigned.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/netfilter/ip_queue.c
net/ipv4/netfilter/ipt_CLUSTERIP.c
net/ipv4/netfilter/ipt_recent.c
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
net/ipv6/netfilter/ip6_queue.c
net/netfilter/nf_conntrack_standalone.c
net/netfilter/nf_log.c
net/netfilter/nf_queue.c
net/netfilter/nfnetlink_log.c
net/netfilter/nfnetlink_queue.c
net/netfilter/xt_hashlimit.c

index fe05da41d6ba6b74947eaaace92eb79d2de408ab..4dc162894cb23261e661235a55bb9aebb60c87b1 100644 (file)
@@ -588,11 +588,9 @@ static int __init ip_queue_init(void)
        }
 
 #ifdef CONFIG_PROC_FS
-       proc = create_proc_entry(IPQ_PROC_FS_NAME, 0, init_net.proc_net);
-       if (proc) {
-               proc->owner = THIS_MODULE;
-               proc->proc_fops = &ip_queue_proc_fops;
-       } else {
+       proc = proc_create(IPQ_PROC_FS_NAME, 0, init_net.proc_net,
+                          &ip_queue_proc_fops);
+       if (!proc) {
                printk(KERN_ERR "ip_queue: failed to create proc entry\n");
                goto cleanup_ipqnl;
        }
index c6cf84c776116a6db394da69947547d20e324b17..52926c8e3cc17266f29269cce5ed061c339d7115 100644 (file)
@@ -167,14 +167,13 @@ clusterip_config_init(struct ipt_clusterip_tgt_info *i, __be32 ip,
 
                /* create proc dir entry */
                sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(ip));
-               c->pde = create_proc_entry(buffer, S_IWUSR|S_IRUSR,
-                                          clusterip_procdir);
+               c->pde = proc_create(buffer, S_IWUSR|S_IRUSR,
+                                    clusterip_procdir, &clusterip_proc_fops);
                if (!c->pde) {
                        kfree(c);
                        return NULL;
                }
        }
-       c->pde->proc_fops = &clusterip_proc_fops;
        c->pde->data = c;
 #endif
 
index 8e8f0425a8ede2b22c02763d4b5282b4bdcf6b40..50e06690eb5b8fa6bceff977ea09127adb18bfb9 100644 (file)
@@ -276,12 +276,11 @@ recent_mt_check(const char *tablename, const void *ip,
        for (i = 0; i < ip_list_hash_size; i++)
                INIT_LIST_HEAD(&t->iphash[i]);
 #ifdef CONFIG_PROC_FS
-       t->proc = create_proc_entry(t->name, ip_list_perms, proc_dir);
+       t->proc = proc_create(t->name, ip_list_perms, proc_dir, &recent_fops);
        if (t->proc == NULL) {
                kfree(t);
                goto out;
        }
-       t->proc->proc_fops = &recent_fops;
        t->proc->uid       = ip_list_uid;
        t->proc->gid       = ip_list_gid;
        t->proc->data      = t;
index 089252e82c01fb93b55efa15c0e7a7f74d36398d..f500b0fdaef422c6ae40cc9ed548a3fecaaf6b0f 100644 (file)
@@ -395,13 +395,10 @@ int __init nf_conntrack_ipv4_compat_init(void)
        if (!proc_exp)
                goto err2;
 
-       proc_stat = create_proc_entry("ip_conntrack", S_IRUGO, init_net.proc_net_stat);
+       proc_stat = proc_create("ip_conntrack", S_IRUGO,
+                               init_net.proc_net_stat, &ct_cpu_seq_fops);
        if (!proc_stat)
                goto err3;
-
-       proc_stat->proc_fops = &ct_cpu_seq_fops;
-       proc_stat->owner = THIS_MODULE;
-
        return 0;
 
 err3:
index cc2f9afcf8087516215f52f8719d7dfa1593a316..8d366f7f2a9a5b3818bfdfddeddff079e7470880 100644 (file)
@@ -591,11 +591,9 @@ static int __init ip6_queue_init(void)
        }
 
 #ifdef CONFIG_PROC_FS
-       proc = create_proc_entry(IPQ_PROC_FS_NAME, 0, init_net.proc_net);
-       if (proc) {
-               proc->owner = THIS_MODULE;
-               proc->proc_fops = &ip6_queue_proc_fops;
-       } else {
+       proc = proc_create(IPQ_PROC_FS_NAME, 0, init_net.proc_net,
+                          &ip6_queue_proc_fops);
+       if (!proc) {
                printk(KERN_ERR "ip6_queue: failed to create proc entry\n");
                goto cleanup_ipqnl;
        }
index e88e96af613d68938fe989034299be0f2c9fee5f..8599068050ecc6213cee7df3b88fffe76b219532 100644 (file)
@@ -395,7 +395,7 @@ EXPORT_SYMBOL_GPL(nf_ct_log_invalid);
 static int __init nf_conntrack_standalone_init(void)
 {
 #ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *proc, *proc_stat;
+       struct proc_dir_entry *proc;
 #endif
        int ret = 0;
 
@@ -407,12 +407,9 @@ static int __init nf_conntrack_standalone_init(void)
        proc = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops);
        if (!proc) goto cleanup_init;
 
-       proc_stat = create_proc_entry("nf_conntrack", S_IRUGO, init_net.proc_net_stat);
-       if (!proc_stat)
+       if (!proc_create("nf_conntrack", S_IRUGO,
+                        init_net.proc_net_stat, &ct_cpu_seq_fops))
                goto cleanup_proc;
-
-       proc_stat->proc_fops = &ct_cpu_seq_fops;
-       proc_stat->owner = THIS_MODULE;
 #endif
 #ifdef CONFIG_SYSCTL
        nf_ct_sysctl_header = register_sysctl_paths(nf_ct_path,
index cec9976aecbf5c5e8592c8c841d57532f8748655..bc11d7092032fa734051b3853cb6ca946b9c1c87 100644 (file)
@@ -168,13 +168,9 @@ static const struct file_operations nflog_file_ops = {
 int __init netfilter_log_init(void)
 {
 #ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *pde;
-
-       pde = create_proc_entry("nf_log", S_IRUGO, proc_net_netfilter);
-       if (!pde)
+       if (!proc_create("nf_log", S_IRUGO,
+                        proc_net_netfilter, &nflog_file_ops))
                return -1;
-
-       pde->proc_fops = &nflog_file_ops;
 #endif
        return 0;
 }
index ddc80ea114cda13509f5828b2c8f5590a6d7f3e3..bbd26893c0c4f7e46d1c312eeaed743b7834f5be 100644 (file)
@@ -348,12 +348,9 @@ static const struct file_operations nfqueue_file_ops = {
 int __init netfilter_queue_init(void)
 {
 #ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *pde;
-
-       pde = create_proc_entry("nf_queue", S_IRUGO, proc_net_netfilter);
-       if (!pde)
+       if (!proc_create("nf_queue", S_IRUGO,
+                        proc_net_netfilter, &nfqueue_file_ops))
                return -1;
-       pde->proc_fops = &nfqueue_file_ops;
 #endif
        return 0;
 }
index bf3f19b21fe49eb0399ac66b09940bd085fb17ca..b8173af8c24a7d9d1f296123b52dfc05a0063dc0 100644 (file)
@@ -923,9 +923,6 @@ static const struct file_operations nful_file_ops = {
 static int __init nfnetlink_log_init(void)
 {
        int i, status = -ENOMEM;
-#ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *proc_nful;
-#endif
 
        for (i = 0; i < INSTANCE_BUCKETS; i++)
                INIT_HLIST_HEAD(&instance_table[i]);
@@ -943,11 +940,9 @@ static int __init nfnetlink_log_init(void)
        }
 
 #ifdef CONFIG_PROC_FS
-       proc_nful = create_proc_entry("nfnetlink_log", 0440,
-                                     proc_net_netfilter);
-       if (!proc_nful)
+       if (!proc_create("nfnetlink_log", 0440,
+                        proc_net_netfilter, &nful_file_ops))
                goto cleanup_subsys;
-       proc_nful->proc_fops = &nful_file_ops;
 #endif
        return status;
 
index 012cb69108202c6ac1060847a7050a874e12931c..10522c04ed248fe3c8998661ca61393a3f5db970 100644 (file)
@@ -896,9 +896,6 @@ static const struct file_operations nfqnl_file_ops = {
 static int __init nfnetlink_queue_init(void)
 {
        int i, status = -ENOMEM;
-#ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *proc_nfqueue;
-#endif
 
        for (i = 0; i < INSTANCE_BUCKETS; i++)
                INIT_HLIST_HEAD(&instance_table[i]);
@@ -911,11 +908,9 @@ static int __init nfnetlink_queue_init(void)
        }
 
 #ifdef CONFIG_PROC_FS
-       proc_nfqueue = create_proc_entry("nfnetlink_queue", 0440,
-                                        proc_net_netfilter);
-       if (!proc_nfqueue)
+       if (!proc_create("nfnetlink_queue", 0440,
+                        proc_net_netfilter, &nfqnl_file_ops))
                goto cleanup_subsys;
-       proc_nfqueue->proc_fops = &nfqnl_file_ops;
 #endif
 
        register_netdevice_notifier(&nfqnl_dev_notifier);
index 5418ce59ac3aa3689c2adf567aefecd3240af94f..dc29007c52cdbc76f41d9efa0a61af88b68debc8 100644 (file)
@@ -237,14 +237,14 @@ static int htable_create_v0(struct xt_hashlimit_info *minfo, int family)
        hinfo->family = family;
        hinfo->rnd_initialized = 0;
        spin_lock_init(&hinfo->lock);
-       hinfo->pde = create_proc_entry(minfo->name, 0,
-                                      family == AF_INET ? hashlimit_procdir4 :
-                                                          hashlimit_procdir6);
+       hinfo->pde = proc_create(minfo->name, 0,
+                                family == AF_INET ? hashlimit_procdir4 :
+                                                    hashlimit_procdir6,
+                                &dl_file_ops);
        if (!hinfo->pde) {
                vfree(hinfo);
                return -1;
        }
-       hinfo->pde->proc_fops = &dl_file_ops;
        hinfo->pde->data = hinfo;
 
        setup_timer(&hinfo->timer, htable_gc, (unsigned long )hinfo);
@@ -301,14 +301,14 @@ static int htable_create(struct xt_hashlimit_mtinfo1 *minfo,
        hinfo->rnd_initialized = 0;
        spin_lock_init(&hinfo->lock);
 
-       hinfo->pde = create_proc_entry(minfo->name, 0,
-                                      family == AF_INET ? hashlimit_procdir4 :
-                                                          hashlimit_procdir6);
+       hinfo->pde = proc_create(minfo->name, 0,
+                                family == AF_INET ? hashlimit_procdir4 :
+                                                    hashlimit_procdir6,
+                                &dl_file_ops);
        if (hinfo->pde == NULL) {
                vfree(hinfo);
                return -1;
        }
-       hinfo->pde->proc_fops = &dl_file_ops;
        hinfo->pde->data = hinfo;
 
        setup_timer(&hinfo->timer, htable_gc, (unsigned long)hinfo);