Skip to content

Commit

Permalink
net/sched: act_simple: fix parsing of TCA_DEF_DATA
Browse files Browse the repository at this point in the history
use nla_strlcpy() to avoid copying data beyond the length of TCA_DEF_DATA
netlink attribute, in case it is less than SIMP_MAX_DATA and it does not
end with '\0' character.

v2: fix errors in the commit message, thanks Hangbin Liu

Fixes: fa1b1cf ("net_cls_act: Make act_simple use of netlink policy.")
Signed-off-by: Davide Caratti <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
dcaratti authored and davem330 committed Jun 8, 2018
1 parent 6310a88 commit 8d49953
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ static void tcf_simp_release(struct tc_action *a)
kfree(d->tcfd_defdata);
}

static int alloc_defdata(struct tcf_defact *d, char *defdata)
static int alloc_defdata(struct tcf_defact *d, const struct nlattr *defdata)
{
d->tcfd_defdata = kzalloc(SIMP_MAX_DATA, GFP_KERNEL);
if (unlikely(!d->tcfd_defdata))
return -ENOMEM;
strlcpy(d->tcfd_defdata, defdata, SIMP_MAX_DATA);
nla_strlcpy(d->tcfd_defdata, defdata, SIMP_MAX_DATA);
return 0;
}

static void reset_policy(struct tcf_defact *d, char *defdata,
static void reset_policy(struct tcf_defact *d, const struct nlattr *defdata,
struct tc_defact *p)
{
spin_lock_bh(&d->tcf_lock);
d->tcf_action = p->action;
memset(d->tcfd_defdata, 0, SIMP_MAX_DATA);
strlcpy(d->tcfd_defdata, defdata, SIMP_MAX_DATA);
nla_strlcpy(d->tcfd_defdata, defdata, SIMP_MAX_DATA);
spin_unlock_bh(&d->tcf_lock);
}

Expand All @@ -87,7 +87,6 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
struct tcf_defact *d;
bool exists = false;
int ret = 0, err;
char *defdata;

if (nla == NULL)
return -EINVAL;
Expand All @@ -110,16 +109,14 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
return -EINVAL;
}

defdata = nla_data(tb[TCA_DEF_DATA]);

if (!exists) {
ret = tcf_idr_create(tn, parm->index, est, a,
&act_simp_ops, bind, false);
if (ret)
return ret;

d = to_defact(*a);
ret = alloc_defdata(d, defdata);
ret = alloc_defdata(d, tb[TCA_DEF_DATA]);
if (ret < 0) {
tcf_idr_release(*a, bind);
return ret;
Expand All @@ -133,7 +130,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
if (!ovr)
return -EEXIST;

reset_policy(d, defdata, parm);
reset_policy(d, tb[TCA_DEF_DATA], parm);
}

if (ret == ACT_P_CREATED)
Expand Down

0 comments on commit 8d49953

Please sign in to comment.