Skip to content

Commit df383e6

Browse files
Jiri Bencdavem330
authored andcommitted
lwtunnel: fix memory leak
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 <[email protected]> Acked-by: Roopa Prabhu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c938a00 commit df383e6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

include/net/lwtunnel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct lwtunnel_encap_ops {
3636
};
3737

3838
#ifdef CONFIG_LWTUNNEL
39+
static inline void lwtstate_free(struct lwtunnel_state *lws)
40+
{
41+
kfree(lws);
42+
}
43+
3944
static inline struct lwtunnel_state *
4045
lwtstate_get(struct lwtunnel_state *lws)
4146
{
@@ -51,7 +56,7 @@ static inline void lwtstate_put(struct lwtunnel_state *lws)
5156
return;
5257

5358
if (atomic_dec_and_test(&lws->refcnt))
54-
kfree(lws);
59+
lwtstate_free(lws);
5560
}
5661

5762
static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)

net/ipv4/fib_semantics.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ int fib_encap_match(struct net *net, u16 encap_type,
539539
{
540540
struct lwtunnel_state *lwtstate;
541541
struct net_device *dev = NULL;
542-
int ret;
542+
int ret, result = 0;
543543

544544
if (encap_type == LWTUNNEL_ENCAP_NONE)
545545
return 0;
@@ -548,10 +548,12 @@ int fib_encap_match(struct net *net, u16 encap_type,
548548
dev = __dev_get_by_index(net, oif);
549549
ret = lwtunnel_build_state(dev, encap_type,
550550
encap, &lwtstate);
551-
if (!ret)
552-
return lwtunnel_cmp_encap(lwtstate, nh->nh_lwtstate);
551+
if (!ret) {
552+
result = lwtunnel_cmp_encap(lwtstate, nh->nh_lwtstate);
553+
lwtstate_free(lwtstate);
554+
}
553555

554-
return 0;
556+
return result;
555557
}
556558

557559
int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)

0 commit comments

Comments
 (0)