Commit 09f2947d authored by Rusty Russell's avatar Rusty Russell Committed by David S. Miller

[NETFILTER]: Fix Module Usage in ipchains and ipfwadm.

Gets rid of some warnings.  Manipulating our own module count inside the
sockopt is safe, because unregistering that sockopt will block.
parent 6a83d262
......@@ -839,7 +839,9 @@ static int clear_fw_chain(struct ip_chain *chainptr)
i->branch->refcount--;
kfree(i);
i = tmp;
MOD_DEC_USE_COUNT;
/* We will block in cleanup's unregister sockopt if unloaded,
so this is safe. */
module_put(THIS_MODULE);
}
return 0;
}
......@@ -870,6 +872,11 @@ static int append_to_chain(struct ip_chain *chainptr, struct ip_fwkernel *rule)
struct ip_fwkernel *i;
FWC_HAVE_LOCK(fwc_wlocks);
/* Are we unloading now? We will block on nf_unregister_sockopt */
if (!try_module_get(THIS_MODULE))
return ENOPROTOOPT;
/* Special case if no rules already present */
if (chainptr->chain == NULL) {
......@@ -886,7 +893,6 @@ static int append_to_chain(struct ip_chain *chainptr, struct ip_fwkernel *rule)
if (rule->branch) rule->branch->refcount++;
append_successful:
MOD_INC_USE_COUNT;
return 0;
}
......@@ -900,6 +906,11 @@ static int insert_in_chain(struct ip_chain *chainptr,
struct ip_fwkernel *f = chainptr->chain;
FWC_HAVE_LOCK(fwc_wlocks);
/* Are we unloading now? We will block on nf_unregister_sockopt */
if (!try_module_get(THIS_MODULE))
return ENOPROTOOPT;
/* special case if the position is number 1 */
if (position == 1) {
frwl->next = chainptr->chain;
......@@ -917,7 +928,6 @@ static int insert_in_chain(struct ip_chain *chainptr,
f->next = frwl;
insert_successful:
MOD_INC_USE_COUNT;
return 0;
}
......@@ -952,7 +962,9 @@ static int del_num_from_chain(struct ip_chain *chainptr, __u32 rulenum)
kfree(tmp);
}
MOD_DEC_USE_COUNT;
/* We will block in cleanup's unregister sockopt if unloaded,
so this is safe. */
module_put(THIS_MODULE);
return 0;
}
......@@ -1059,7 +1071,9 @@ static int del_rule_from_chain(struct ip_chain *chainptr,
else
chainptr->chain = ftmp->next;
kfree(ftmp);
MOD_DEC_USE_COUNT;
/* We will block in cleanup's unregister sockopt if unloaded,
so this is safe. */
module_put(THIS_MODULE);
break;
}
......@@ -1101,7 +1115,9 @@ static int del_chain(ip_chainlabel label)
tmp->next = tmp2->next;
kfree(tmp2);
MOD_DEC_USE_COUNT;
/* We will block in cleanup's unregister sockopt if unloaded,
so this is safe. */
module_put(THIS_MODULE);
return 0;
}
......@@ -1149,12 +1165,15 @@ static int create_chain(ip_chainlabel label)
if (strcmp(tmp->label,label) == 0)
return EEXIST;
/* Are we unloading now? We will block on nf_unregister_sockopt */
if (!try_module_get(THIS_MODULE))
return ENOPROTOOPT;
tmp->next = ip_init_chain(label, 0, FW_SKIP); /* refcount is
* zero since this is a
* user defined chain *
* and therefore can be
* deleted */
MOD_INC_USE_COUNT;
return 0;
}
......
......@@ -707,7 +707,9 @@ static void free_fw_chain(struct ip_fw *volatile* chainptr)
ftmp = *chainptr;
*chainptr = ftmp->fw_next;
kfree(ftmp);
MOD_DEC_USE_COUNT;
/* We will block in cleanup's unregister sockopt if unloaded,
so this is safe. */
module_put(THIS_MODULE);
}
WRITE_UNLOCK(&ip_fw_lock);
}
......@@ -718,6 +720,10 @@ static int insert_in_chain(struct ip_fw *volatile* chainptr, struct ip_fw *frwl,
{
struct ip_fw *ftmp;
/* Are we unloading now? We will block on nf_unregister_sockopt */
if (!try_module_get(THIS_MODULE))
return ENOPROTOOPT;
ftmp = kmalloc( sizeof(struct ip_fw), GFP_KERNEL );
if ( ftmp == NULL )
{
......@@ -748,7 +754,6 @@ static int insert_in_chain(struct ip_fw *volatile* chainptr, struct ip_fw *frwl,
ftmp->fw_next = *chainptr;
*chainptr=ftmp;
WRITE_UNLOCK(&ip_fw_lock);
MOD_INC_USE_COUNT;
return(0);
}
......@@ -758,6 +763,10 @@ static int append_to_chain(struct ip_fw *volatile* chainptr, struct ip_fw *frwl,
struct ip_fw *chtmp=NULL;
struct ip_fw *volatile chtmp_prev=NULL;
/* Are we unloading now? We will block on nf_unregister_sockopt */
if (!try_module_get(THIS_MODULE))
return ENOPROTOOPT;
ftmp = kmalloc( sizeof(struct ip_fw), GFP_KERNEL );
if ( ftmp == NULL )
{
......@@ -796,7 +805,6 @@ static int append_to_chain(struct ip_fw *volatile* chainptr, struct ip_fw *frwl,
else
*chainptr=ftmp;
WRITE_UNLOCK(&ip_fw_lock);
MOD_INC_USE_COUNT;
return(0);
}
......@@ -869,7 +877,9 @@ static int del_from_chain(struct ip_fw *volatile*chainptr, struct ip_fw *frwl)
}
WRITE_UNLOCK(&ip_fw_lock);
if (was_found) {
MOD_DEC_USE_COUNT;
/* We will block in cleanup's unregister sockopt if unloaded,
so this is safe. */
module_put(THIS_MODULE);
return 0;
} else
return(EINVAL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment