Skip to content

Commit a162c35

Browse files
congwangdavem330
authored andcommitted
net_sched: properly cancel netlink dump on failure
When nla_put*() fails after nla_nest_start(), we need to call nla_nest_cancel() to cancel the message, otherwise we end up calling nla_nest_end() like a success. Fixes: 0ed5269 ("net/sched: add tunnel option support to act_tunnel_key") Cc: Davide Caratti <[email protected]> Cc: Simon Horman <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8edfe2e commit a162c35

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

net/sched/act_tunnel_key.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
412412
nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE,
413413
opt->type) ||
414414
nla_put(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA,
415-
opt->length * 4, opt + 1))
415+
opt->length * 4, opt + 1)) {
416+
nla_nest_cancel(skb, start);
416417
return -EMSGSIZE;
418+
}
417419

418420
len -= sizeof(struct geneve_opt) + opt->length * 4;
419421
src += sizeof(struct geneve_opt) + opt->length * 4;
@@ -427,7 +429,7 @@ static int tunnel_key_opts_dump(struct sk_buff *skb,
427429
const struct ip_tunnel_info *info)
428430
{
429431
struct nlattr *start;
430-
int err;
432+
int err = -EINVAL;
431433

432434
if (!info->options_len)
433435
return 0;
@@ -439,9 +441,11 @@ static int tunnel_key_opts_dump(struct sk_buff *skb,
439441
if (info->key.tun_flags & TUNNEL_GENEVE_OPT) {
440442
err = tunnel_key_geneve_opts_dump(skb, info);
441443
if (err)
442-
return err;
444+
goto err_out;
443445
} else {
444-
return -EINVAL;
446+
err_out:
447+
nla_nest_cancel(skb, start);
448+
return err;
445449
}
446450

447451
nla_nest_end(skb, start);

0 commit comments

Comments
 (0)