Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
pkt_sched: Stop using NLA_PUT*().
Browse files Browse the repository at this point in the history
These macros contain a hidden goto, and are thus extremely error
prone and make code hard to audit.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
davem330 committed Apr 1, 2012
1 parent 9360ffd commit 1b34ec4
Show file tree
Hide file tree
Showing 40 changed files with 263 additions and 157 deletions.
9 changes: 6 additions & 3 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
nest = nla_nest_start(skb, a->order);
if (nest == NULL)
goto nla_put_failure;
NLA_PUT_STRING(skb, TCA_KIND, a->ops->kind);
if (nla_put_string(skb, TCA_KIND, a->ops->kind))
goto nla_put_failure;
for (i = 0; i < (hinfo->hmask + 1); i++) {
p = hinfo->htab[tcf_hash(i, hinfo->hmask)];

Expand All @@ -139,7 +140,8 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
p = s_p;
}
}
NLA_PUT_U32(skb, TCA_FCNT, n_i);
if (nla_put_u32(skb, TCA_FCNT, n_i))
goto nla_put_failure;
nla_nest_end(skb, nest);

return n_i;
Expand Down Expand Up @@ -437,7 +439,8 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
if (a->ops == NULL || a->ops->dump == NULL)
return err;

NLA_PUT_STRING(skb, TCA_KIND, a->ops->kind);
if (nla_put_string(skb, TCA_KIND, a->ops->kind))
goto nla_put_failure;
if (tcf_action_copy_stats(skb, a, 0))
goto nla_put_failure;
nest = nla_nest_start(skb, TCA_OPTIONS);
Expand Down
6 changes: 4 additions & 2 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,13 @@ static int tcf_csum_dump(struct sk_buff *skb,
};
struct tcf_t t;

NLA_PUT(skb, TCA_CSUM_PARMS, sizeof(opt), &opt);
if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt))
goto nla_put_failure;
t.install = jiffies_to_clock_t(jiffies - p->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - p->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(p->tcf_tm.expires);
NLA_PUT(skb, TCA_CSUM_TM, sizeof(t), &t);
if (nla_put(skb, TCA_CSUM_TM, sizeof(t), &t))
goto nla_put_failure;

return skb->len;

Expand Down
9 changes: 6 additions & 3 deletions net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a, int bind, int
};
struct tcf_t t;

NLA_PUT(skb, TCA_GACT_PARMS, sizeof(opt), &opt);
if (nla_put(skb, TCA_GACT_PARMS, sizeof(opt), &opt))
goto nla_put_failure;
#ifdef CONFIG_GACT_PROB
if (gact->tcfg_ptype) {
struct tc_gact_p p_opt = {
Expand All @@ -171,13 +172,15 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a, int bind, int
.ptype = gact->tcfg_ptype,
};

NLA_PUT(skb, TCA_GACT_PROB, sizeof(p_opt), &p_opt);
if (nla_put(skb, TCA_GACT_PROB, sizeof(p_opt), &p_opt))
goto nla_put_failure;
}
#endif
t.install = jiffies_to_clock_t(jiffies - gact->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - gact->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(gact->tcf_tm.expires);
NLA_PUT(skb, TCA_GACT_TM, sizeof(t), &t);
if (nla_put(skb, TCA_GACT_TM, sizeof(t), &t))
goto nla_put_failure;
return skb->len;

nla_put_failure:
Expand Down
14 changes: 8 additions & 6 deletions net/sched/act_ipt.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,17 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int
c.refcnt = ipt->tcf_refcnt - ref;
strcpy(t->u.user.name, ipt->tcfi_t->u.kernel.target->name);

NLA_PUT(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t);
NLA_PUT_U32(skb, TCA_IPT_INDEX, ipt->tcf_index);
NLA_PUT_U32(skb, TCA_IPT_HOOK, ipt->tcfi_hook);
NLA_PUT(skb, TCA_IPT_CNT, sizeof(struct tc_cnt), &c);
NLA_PUT_STRING(skb, TCA_IPT_TABLE, ipt->tcfi_tname);
if (nla_put(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t) ||
nla_put_u32(skb, TCA_IPT_INDEX, ipt->tcf_index) ||
nla_put_u32(skb, TCA_IPT_HOOK, ipt->tcfi_hook) ||
nla_put(skb, TCA_IPT_CNT, sizeof(struct tc_cnt), &c) ||
nla_put_string(skb, TCA_IPT_TABLE, ipt->tcfi_tname))
goto nla_put_failure;
tm.install = jiffies_to_clock_t(jiffies - ipt->tcf_tm.install);
tm.lastuse = jiffies_to_clock_t(jiffies - ipt->tcf_tm.lastuse);
tm.expires = jiffies_to_clock_t(ipt->tcf_tm.expires);
NLA_PUT(skb, TCA_IPT_TM, sizeof (tm), &tm);
if (nla_put(skb, TCA_IPT_TM, sizeof (tm), &tm))
goto nla_put_failure;
kfree(t);
return skb->len;

Expand Down
6 changes: 4 additions & 2 deletions net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, i
};
struct tcf_t t;

NLA_PUT(skb, TCA_MIRRED_PARMS, sizeof(opt), &opt);
if (nla_put(skb, TCA_MIRRED_PARMS, sizeof(opt), &opt))
goto nla_put_failure;
t.install = jiffies_to_clock_t(jiffies - m->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - m->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(m->tcf_tm.expires);
NLA_PUT(skb, TCA_MIRRED_TM, sizeof(t), &t);
if (nla_put(skb, TCA_MIRRED_TM, sizeof(t), &t))
goto nla_put_failure;
return skb->len;

nla_put_failure:
Expand Down
6 changes: 4 additions & 2 deletions net/sched/act_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a,
};
struct tcf_t t;

NLA_PUT(skb, TCA_NAT_PARMS, sizeof(opt), &opt);
if (nla_put(skb, TCA_NAT_PARMS, sizeof(opt), &opt))
goto nla_put_failure;
t.install = jiffies_to_clock_t(jiffies - p->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - p->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(p->tcf_tm.expires);
NLA_PUT(skb, TCA_NAT_TM, sizeof(t), &t);
if (nla_put(skb, TCA_NAT_TM, sizeof(t), &t))
goto nla_put_failure;

return skb->len;

Expand Down
6 changes: 4 additions & 2 deletions net/sched/act_pedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,
opt->refcnt = p->tcf_refcnt - ref;
opt->bindcnt = p->tcf_bindcnt - bind;

NLA_PUT(skb, TCA_PEDIT_PARMS, s, opt);
if (nla_put(skb, TCA_PEDIT_PARMS, s, opt))
goto nla_put_failure;
t.install = jiffies_to_clock_t(jiffies - p->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - p->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(p->tcf_tm.expires);
NLA_PUT(skb, TCA_PEDIT_TM, sizeof(t), &t);
if (nla_put(skb, TCA_PEDIT_TM, sizeof(t), &t))
goto nla_put_failure;
kfree(opt);
return skb->len;

Expand Down
13 changes: 8 additions & 5 deletions net/sched/act_police.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,14 @@ tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
opt.rate = police->tcfp_R_tab->rate;
if (police->tcfp_P_tab)
opt.peakrate = police->tcfp_P_tab->rate;
NLA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt);
if (police->tcfp_result)
NLA_PUT_U32(skb, TCA_POLICE_RESULT, police->tcfp_result);
if (police->tcfp_ewma_rate)
NLA_PUT_U32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate);
if (nla_put(skb, TCA_POLICE_TBF, sizeof(opt), &opt))
goto nla_put_failure;
if (police->tcfp_result &&
nla_put_u32(skb, TCA_POLICE_RESULT, police->tcfp_result))
goto nla_put_failure;
if (police->tcfp_ewma_rate &&
nla_put_u32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate))
goto nla_put_failure;
return skb->len;

nla_put_failure:
Expand Down
8 changes: 5 additions & 3 deletions net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a,
};
struct tcf_t t;

NLA_PUT(skb, TCA_DEF_PARMS, sizeof(opt), &opt);
NLA_PUT_STRING(skb, TCA_DEF_DATA, d->tcfd_defdata);
if (nla_put(skb, TCA_DEF_PARMS, sizeof(opt), &opt) ||
nla_put_string(skb, TCA_DEF_DATA, d->tcfd_defdata))
goto nla_put_failure;
t.install = jiffies_to_clock_t(jiffies - d->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - d->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(d->tcf_tm.expires);
NLA_PUT(skb, TCA_DEF_TM, sizeof(t), &t);
if (nla_put(skb, TCA_DEF_TM, sizeof(t), &t))
goto nla_put_failure;
return skb->len;

nla_put_failure:
Expand Down
27 changes: 16 additions & 11 deletions net/sched/act_skbedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,25 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
};
struct tcf_t t;

NLA_PUT(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt);
if (d->flags & SKBEDIT_F_PRIORITY)
NLA_PUT(skb, TCA_SKBEDIT_PRIORITY, sizeof(d->priority),
&d->priority);
if (d->flags & SKBEDIT_F_QUEUE_MAPPING)
NLA_PUT(skb, TCA_SKBEDIT_QUEUE_MAPPING,
sizeof(d->queue_mapping), &d->queue_mapping);
if (d->flags & SKBEDIT_F_MARK)
NLA_PUT(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),
&d->mark);
if (nla_put(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt))
goto nla_put_failure;
if ((d->flags & SKBEDIT_F_PRIORITY) &&
nla_put(skb, TCA_SKBEDIT_PRIORITY, sizeof(d->priority),
&d->priority))
goto nla_put_failure;
if ((d->flags & SKBEDIT_F_QUEUE_MAPPING) &&
nla_put(skb, TCA_SKBEDIT_QUEUE_MAPPING,
sizeof(d->queue_mapping), &d->queue_mapping))
goto nla_put_failure;
if ((d->flags & SKBEDIT_F_MARK) &&
nla_put(skb, TCA_SKBEDIT_MARK, sizeof(d->mark),
&d->mark))
goto nla_put_failure;
t.install = jiffies_to_clock_t(jiffies - d->tcf_tm.install);
t.lastuse = jiffies_to_clock_t(jiffies - d->tcf_tm.lastuse);
t.expires = jiffies_to_clock_t(d->tcf_tm.expires);
NLA_PUT(skb, TCA_SKBEDIT_TM, sizeof(t), &t);
if (nla_put(skb, TCA_SKBEDIT_TM, sizeof(t), &t))
goto nla_put_failure;
return skb->len;

nla_put_failure:
Expand Down
3 changes: 2 additions & 1 deletion net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex;
tcm->tcm_parent = tp->classid;
tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
NLA_PUT_STRING(skb, TCA_KIND, tp->ops->kind);
if (nla_put_string(skb, TCA_KIND, tp->ops->kind))
goto nla_put_failure;
tcm->tcm_handle = fh;
if (RTM_DELTFILTER != event) {
tcm->tcm_handle = 0;
Expand Down
5 changes: 3 additions & 2 deletions net/sched/cls_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh,
if (nest == NULL)
goto nla_put_failure;

if (f->res.classid)
NLA_PUT_U32(skb, TCA_BASIC_CLASSID, f->res.classid);
if (f->res.classid &&
nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid))
goto nla_put_failure;

if (tcf_exts_dump(skb, &f->exts, &basic_ext_map) < 0 ||
tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0)
Expand Down
35 changes: 21 additions & 14 deletions net/sched/cls_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,25 +572,32 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh,
if (nest == NULL)
goto nla_put_failure;

NLA_PUT_U32(skb, TCA_FLOW_KEYS, f->keymask);
NLA_PUT_U32(skb, TCA_FLOW_MODE, f->mode);
if (nla_put_u32(skb, TCA_FLOW_KEYS, f->keymask) ||
nla_put_u32(skb, TCA_FLOW_MODE, f->mode))
goto nla_put_failure;

if (f->mask != ~0 || f->xor != 0) {
NLA_PUT_U32(skb, TCA_FLOW_MASK, f->mask);
NLA_PUT_U32(skb, TCA_FLOW_XOR, f->xor);
if (nla_put_u32(skb, TCA_FLOW_MASK, f->mask) ||
nla_put_u32(skb, TCA_FLOW_XOR, f->xor))
goto nla_put_failure;
}
if (f->rshift)
NLA_PUT_U32(skb, TCA_FLOW_RSHIFT, f->rshift);
if (f->addend)
NLA_PUT_U32(skb, TCA_FLOW_ADDEND, f->addend);
if (f->rshift &&
nla_put_u32(skb, TCA_FLOW_RSHIFT, f->rshift))
goto nla_put_failure;
if (f->addend &&
nla_put_u32(skb, TCA_FLOW_ADDEND, f->addend))
goto nla_put_failure;

if (f->divisor)
NLA_PUT_U32(skb, TCA_FLOW_DIVISOR, f->divisor);
if (f->baseclass)
NLA_PUT_U32(skb, TCA_FLOW_BASECLASS, f->baseclass);
if (f->divisor &&
nla_put_u32(skb, TCA_FLOW_DIVISOR, f->divisor))
goto nla_put_failure;
if (f->baseclass &&
nla_put_u32(skb, TCA_FLOW_BASECLASS, f->baseclass))
goto nla_put_failure;

if (f->perturb_period)
NLA_PUT_U32(skb, TCA_FLOW_PERTURB, f->perturb_period / HZ);
if (f->perturb_period &&
nla_put_u32(skb, TCA_FLOW_PERTURB, f->perturb_period / HZ))
goto nla_put_failure;

if (tcf_exts_dump(skb, &f->exts, &flow_ext_map) < 0)
goto nla_put_failure;
Expand Down
15 changes: 9 additions & 6 deletions net/sched/cls_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh,
if (nest == NULL)
goto nla_put_failure;

if (f->res.classid)
NLA_PUT_U32(skb, TCA_FW_CLASSID, f->res.classid);
if (f->res.classid &&
nla_put_u32(skb, TCA_FW_CLASSID, f->res.classid))
goto nla_put_failure;
#ifdef CONFIG_NET_CLS_IND
if (strlen(f->indev))
NLA_PUT_STRING(skb, TCA_FW_INDEV, f->indev);
if (strlen(f->indev) &&
nla_put_string(skb, TCA_FW_INDEV, f->indev))
goto nla_put_failure;
#endif /* CONFIG_NET_CLS_IND */
if (head->mask != 0xFFFFFFFF)
NLA_PUT_U32(skb, TCA_FW_MASK, head->mask);
if (head->mask != 0xFFFFFFFF &&
nla_put_u32(skb, TCA_FW_MASK, head->mask))
goto nla_put_failure;

if (tcf_exts_dump(skb, &f->exts, &fw_ext_map) < 0)
goto nla_put_failure;
Expand Down
16 changes: 10 additions & 6 deletions net/sched/cls_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,17 +571,21 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh,

if (!(f->handle & 0x8000)) {
id = f->id & 0xFF;
NLA_PUT_U32(skb, TCA_ROUTE4_TO, id);
if (nla_put_u32(skb, TCA_ROUTE4_TO, id))
goto nla_put_failure;
}
if (f->handle & 0x80000000) {
if ((f->handle >> 16) != 0xFFFF)
NLA_PUT_U32(skb, TCA_ROUTE4_IIF, f->iif);
if ((f->handle >> 16) != 0xFFFF &&
nla_put_u32(skb, TCA_ROUTE4_IIF, f->iif))
goto nla_put_failure;
} else {
id = f->id >> 16;
NLA_PUT_U32(skb, TCA_ROUTE4_FROM, id);
if (nla_put_u32(skb, TCA_ROUTE4_FROM, id))
goto nla_put_failure;
}
if (f->res.classid)
NLA_PUT_U32(skb, TCA_ROUTE4_CLASSID, f->res.classid);
if (f->res.classid &&
nla_put_u32(skb, TCA_ROUTE4_CLASSID, f->res.classid))
goto nla_put_failure;

if (tcf_exts_dump(skb, &f->exts, &route_ext_map) < 0)
goto nla_put_failure;
Expand Down
16 changes: 10 additions & 6 deletions net/sched/cls_rsvp.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,18 +615,22 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,
if (nest == NULL)
goto nla_put_failure;

NLA_PUT(skb, TCA_RSVP_DST, sizeof(s->dst), &s->dst);
if (nla_put(skb, TCA_RSVP_DST, sizeof(s->dst), &s->dst))
goto nla_put_failure;
pinfo.dpi = s->dpi;
pinfo.spi = f->spi;
pinfo.protocol = s->protocol;
pinfo.tunnelid = s->tunnelid;
pinfo.tunnelhdr = f->tunnelhdr;
pinfo.pad = 0;
NLA_PUT(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo);
if (f->res.classid)
NLA_PUT_U32(skb, TCA_RSVP_CLASSID, f->res.classid);
if (((f->handle >> 8) & 0xFF) != 16)
NLA_PUT(skb, TCA_RSVP_SRC, sizeof(f->src), f->src);
if (nla_put(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo))
goto nla_put_failure;
if (f->res.classid &&
nla_put_u32(skb, TCA_RSVP_CLASSID, f->res.classid))
goto nla_put_failure;
if (((f->handle >> 8) & 0xFF) != 16 &&
nla_put(skb, TCA_RSVP_SRC, sizeof(f->src), f->src))
goto nla_put_failure;

if (tcf_exts_dump(skb, &f->exts, &rsvp_ext_map) < 0)
goto nla_put_failure;
Expand Down
14 changes: 8 additions & 6 deletions net/sched/cls_tcindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,11 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh,

if (!fh) {
t->tcm_handle = ~0; /* whatever ... */
NLA_PUT_U32(skb, TCA_TCINDEX_HASH, p->hash);
NLA_PUT_U16(skb, TCA_TCINDEX_MASK, p->mask);
NLA_PUT_U32(skb, TCA_TCINDEX_SHIFT, p->shift);
NLA_PUT_U32(skb, TCA_TCINDEX_FALL_THROUGH, p->fall_through);
if (nla_put_u32(skb, TCA_TCINDEX_HASH, p->hash) ||
nla_put_u16(skb, TCA_TCINDEX_MASK, p->mask) ||
nla_put_u32(skb, TCA_TCINDEX_SHIFT, p->shift) ||
nla_put_u32(skb, TCA_TCINDEX_FALL_THROUGH, p->fall_through))
goto nla_put_failure;
nla_nest_end(skb, nest);
} else {
if (p->perfect) {
Expand All @@ -460,8 +461,9 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh,
}
}
pr_debug("handle = %d\n", t->tcm_handle);
if (r->res.class)
NLA_PUT_U32(skb, TCA_TCINDEX_CLASSID, r->res.classid);
if (r->res.class &&
nla_put_u32(skb, TCA_TCINDEX_CLASSID, r->res.classid))
goto nla_put_failure;

if (tcf_exts_dump(skb, &r->exts, &tcindex_ext_map) < 0)
goto nla_put_failure;
Expand Down
Loading

0 comments on commit 1b34ec4

Please sign in to comment.