Skip to content

Commit

Permalink
lwtunnel: fix memory leak
Browse files Browse the repository at this point in the history
The built lwtunnel_state struct has to be freed after comparison.

Fixes: 571e722 ("ipv4: support for fib route lwtunnel encap attributes")
Signed-off-by: Jiri Benc <jbenc@redhat.com>
Acked-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Benc authored and David S. Miller committed Aug 19, 2015
1 parent c938a00 commit df383e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion include/net/lwtunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ struct lwtunnel_encap_ops {
};

#ifdef CONFIG_LWTUNNEL
static inline void lwtstate_free(struct lwtunnel_state *lws)
{
kfree(lws);
}

static inline struct lwtunnel_state *
lwtstate_get(struct lwtunnel_state *lws)
{
Expand All @@ -51,7 +56,7 @@ static inline void lwtstate_put(struct lwtunnel_state *lws)
return;

if (atomic_dec_and_test(&lws->refcnt))
kfree(lws);
lwtstate_free(lws);
}

static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
Expand Down
10 changes: 6 additions & 4 deletions net/ipv4/fib_semantics.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ int fib_encap_match(struct net *net, u16 encap_type,
{
struct lwtunnel_state *lwtstate;
struct net_device *dev = NULL;
int ret;
int ret, result = 0;

if (encap_type == LWTUNNEL_ENCAP_NONE)
return 0;
Expand All @@ -548,10 +548,12 @@ int fib_encap_match(struct net *net, u16 encap_type,
dev = __dev_get_by_index(net, oif);
ret = lwtunnel_build_state(dev, encap_type,
encap, &lwtstate);
if (!ret)
return lwtunnel_cmp_encap(lwtstate, nh->nh_lwtstate);
if (!ret) {
result = lwtunnel_cmp_encap(lwtstate, nh->nh_lwtstate);
lwtstate_free(lwtstate);
}

return 0;
return result;
}

int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
Expand Down

0 comments on commit df383e6

Please sign in to comment.