diff mbox

[1/5] net_sched: Fail if missing mandatory action operation methods

Message ID 1386167216-30281-2-git-send-email-jhs@mojatatu.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Jamal Hadi Salim Dec. 4, 2013, 2:26 p.m. UTC
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
 net/sched/act_api.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Eric Dumazet Dec. 4, 2013, 5:03 p.m. UTC | #1
On Wed, 2013-12-04 at 09:26 -0500, Jamal Hadi Salim wrote:
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> ---
>  net/sched/act_api.c |   12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index fd70728..618695e 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -270,6 +270,10 @@ int tcf_register_action(struct tc_action_ops *act)
>  {
>  	struct tc_action_ops *a, **ap;
>  
> +	/* Must supply act, dump, cleanup and init */
> +	if (!act->act || !act->dump || !act->cleanup || !act->init)
> +		return -EINVAL;
> +
>  	write_lock(&act_mod_lock);
>  	for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) {
>  		if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
> @@ -381,7 +385,7 @@ int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act,
>  	}
>  	while ((a = act) != NULL) {
>  repeat:
> -		if (a->ops && a->ops->act) {
> +		if (a->ops) {

Could we remove all these tests on a->ops being NULL or not ?

IMHO a->ops cannot be NULL. If NULL, just crash by NULL deref.




--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jamal Hadi Salim Dec. 4, 2013, 5:21 p.m. UTC | #2
On 12/04/13 12:03, Eric Dumazet wrote:

> Could we remove all these tests on a->ops being NULL or not ?
>

Yes, i think those should go away as well.
I will wait for Dave to swallow these other patches then send one that 
gets rid of those.

cheers,
jamal

> IMHO a->ops cannot be NULL. If NULL, just crash by NULL deref.
>
>
>
>

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index fd70728..618695e 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -270,6 +270,10 @@  int tcf_register_action(struct tc_action_ops *act)
 {
 	struct tc_action_ops *a, **ap;
 
+	/* Must supply act, dump, cleanup and init */
+	if (!act->act || !act->dump || !act->cleanup || !act->init)
+		return -EINVAL;
+
 	write_lock(&act_mod_lock);
 	for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) {
 		if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
@@ -381,7 +385,7 @@  int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act,
 	}
 	while ((a = act) != NULL) {
 repeat:
-		if (a->ops && a->ops->act) {
+		if (a->ops) {
 			ret = a->ops->act(skb, a, res);
 			if (TC_MUNGED & skb->tc_verd) {
 				/* copied already, allow trampling */
@@ -405,7 +409,7 @@  void tcf_action_destroy(struct tc_action *act, int bind)
 	struct tc_action *a;
 
 	for (a = act; a; a = act) {
-		if (a->ops && a->ops->cleanup) {
+		if (a->ops) {
 			if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
 				module_put(a->ops->owner);
 			act = act->next;
@@ -424,7 +428,7 @@  tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
 {
 	int err = -EINVAL;
 
-	if (a->ops == NULL || a->ops->dump == NULL)
+	if (a->ops == NULL)
 		return err;
 	return a->ops->dump(skb, a, bind, ref);
 }
@@ -436,7 +440,7 @@  tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
 	unsigned char *b = skb_tail_pointer(skb);
 	struct nlattr *nest;
 
-	if (a->ops == NULL || a->ops->dump == NULL)
+	if (a->ops == NULL)
 		return err;
 
 	if (nla_put_string(skb, TCA_KIND, a->ops->kind))