Commit 696ecdc1 authored by Hiroaki SHIMODA's avatar Hiroaki SHIMODA Committed by David S. Miller

net_sched: gact: Fix potential panic in tcf_gact().

gact_rand array is accessed by gact->tcfg_ptype whose value
is assumed to less than MAX_RAND, but any range checks are
not performed.

So add a check in tcf_gact_init(). And in tcf_gact(), we can
reduce a branch.
Signed-off-by: default avatarHiroaki SHIMODA <shimoda.hiroaki@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f3f9f332
...@@ -67,6 +67,9 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, ...@@ -67,6 +67,9 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est,
struct tcf_common *pc; struct tcf_common *pc;
int ret = 0; int ret = 0;
int err; int err;
#ifdef CONFIG_GACT_PROB
struct tc_gact_p *p_parm = NULL;
#endif
if (nla == NULL) if (nla == NULL)
return -EINVAL; return -EINVAL;
...@@ -82,6 +85,12 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, ...@@ -82,6 +85,12 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est,
#ifndef CONFIG_GACT_PROB #ifndef CONFIG_GACT_PROB
if (tb[TCA_GACT_PROB] != NULL) if (tb[TCA_GACT_PROB] != NULL)
return -EOPNOTSUPP; return -EOPNOTSUPP;
#else
if (tb[TCA_GACT_PROB]) {
p_parm = nla_data(tb[TCA_GACT_PROB]);
if (p_parm->ptype >= MAX_RAND)
return -EINVAL;
}
#endif #endif
pc = tcf_hash_check(parm->index, a, bind, &gact_hash_info); pc = tcf_hash_check(parm->index, a, bind, &gact_hash_info);
...@@ -103,8 +112,7 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, ...@@ -103,8 +112,7 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est,
spin_lock_bh(&gact->tcf_lock); spin_lock_bh(&gact->tcf_lock);
gact->tcf_action = parm->action; gact->tcf_action = parm->action;
#ifdef CONFIG_GACT_PROB #ifdef CONFIG_GACT_PROB
if (tb[TCA_GACT_PROB] != NULL) { if (p_parm) {
struct tc_gact_p *p_parm = nla_data(tb[TCA_GACT_PROB]);
gact->tcfg_paction = p_parm->paction; gact->tcfg_paction = p_parm->paction;
gact->tcfg_pval = p_parm->pval; gact->tcfg_pval = p_parm->pval;
gact->tcfg_ptype = p_parm->ptype; gact->tcfg_ptype = p_parm->ptype;
...@@ -133,7 +141,7 @@ static int tcf_gact(struct sk_buff *skb, const struct tc_action *a, ...@@ -133,7 +141,7 @@ static int tcf_gact(struct sk_buff *skb, const struct tc_action *a,
spin_lock(&gact->tcf_lock); spin_lock(&gact->tcf_lock);
#ifdef CONFIG_GACT_PROB #ifdef CONFIG_GACT_PROB
if (gact->tcfg_ptype && gact_rand[gact->tcfg_ptype] != NULL) if (gact->tcfg_ptype)
action = gact_rand[gact->tcfg_ptype](gact); action = gact_rand[gact->tcfg_ptype](gact);
else else
action = gact->tcf_action; action = gact->tcf_action;
......
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