net_sched: properly handle failure case of tcf_exts_init()
After commit 22dc13c837
("net_sched: convert tcf_exts from list to pointer array")
we do dynamic allocation in tcf_exts_init(), therefore we need
to handle the ENOMEM case properly.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
c1346a7e70
commit
b9a24bb76b
@@ -311,17 +311,19 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
|
||||
if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))
|
||||
return -EINVAL;
|
||||
|
||||
tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
|
||||
ret = tcf_exts_validate(net, tp, tb, est, &exts, ovr);
|
||||
ret = tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = tcf_exts_validate(net, tp, tb, est, &exts, ovr);
|
||||
if (ret < 0)
|
||||
goto errout;
|
||||
|
||||
if (tb[TCA_BPF_FLAGS]) {
|
||||
u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]);
|
||||
|
||||
if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT) {
|
||||
tcf_exts_destroy(&exts);
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT;
|
||||
@@ -331,10 +333,8 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
|
||||
|
||||
ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) :
|
||||
cls_bpf_prog_from_efd(tb, prog, tp);
|
||||
if (ret < 0) {
|
||||
tcf_exts_destroy(&exts);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
goto errout;
|
||||
|
||||
if (tb[TCA_BPF_CLASSID]) {
|
||||
prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]);
|
||||
@@ -343,6 +343,10 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
|
||||
|
||||
tcf_exts_change(tp, &prog->exts, &exts);
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
tcf_exts_destroy(&exts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
|
||||
@@ -388,7 +392,9 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
|
||||
if (!prog)
|
||||
return -ENOBUFS;
|
||||
|
||||
tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
|
||||
ret = tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
|
||||
if (ret < 0)
|
||||
goto errout;
|
||||
|
||||
if (oldprog) {
|
||||
if (handle && oldprog->handle != handle) {
|
||||
@@ -420,9 +426,10 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
|
||||
|
||||
*arg = (unsigned long) prog;
|
||||
return 0;
|
||||
errout:
|
||||
kfree(prog);
|
||||
|
||||
errout:
|
||||
tcf_exts_destroy(&prog->exts);
|
||||
kfree(prog);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user