xfrm_user: use xfrm_state_put to free xfrm_state_alloc return value
Subsystems (3)
From: Pan Bian <[email protected]>
The memory chunk allocated by xfrm_state_alloc() should be released with xfrm_state_put(), not kfree.
--- net/xfrm/xfrm_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_user.c +2 -2
@@ -2288,13 +2288,13 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, } -kfree (x); +xfrm_state_put (x);kfree (xp);return 0 ; free_state: -kfree (x); +xfrm_state_put (x); nomem:return err; }
Signature · 1 line
2.7.4
Herbert Xu
maintainerQuoted 6 lines · Pan Bian
From: Pan Bian <[email protected]>
The memory chunk allocated by
xfrm_state_alloc()should be released withxfrm_state_put(), not kfree.Signed-off-by Pan Bian <[email protected]>
This bug was introduced by
commit 565f0fa902b64020d5d147ff1708567e9e0b6e49 Author: Mathias Krause <[email protected]> Date: Thu May 3 10:55:07 2018 +0200
While using xfrm_state_put may work it's certainly not the designed to do this. We should instead export a function that calls kmem_cache_free on xfrm_state directly and use that here.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 6 lines · Herbert Xu
Quoted 5 lines · Pan Bian
From: Pan Bian <[email protected]>
The memory chunk allocated by
xfrm_state_alloc()should be released withxfrm_state_put(), not kfree.
Quoted 8 lines
Quoted 1 line
Signed-off-by Pan Bian <[email protected]>This bug was introduced by
commit 565f0fa902b64020d5d147ff1708567e9e0b6e49 Author: Mathias Krause <[email protected]> Date: Thu May 3 10:55:07 2018 +0200
Oh, snap. You're totally right. I missed the kfree() in xfrm_user.c. Sorry for that!
Quoted 3 lines
While using
xfrm_state_putmay work it's certainly not the designed to do this. We should instead export a function that callskmem_cache_freeonxfrm_statedirectly and use that here.
Maybe something like the below patch? Steffen?
-- >8 --
Subject: [PATCH] xfrm_user: fix freeing of xfrm states on acquire
Commit 565f0fa902b6 ("xfrm: use a dedicated slab cache for struct xfrm_state") moved xfrm state objects to use their own slab cache. However, it missed to adapt xfrm_user to use this new cache when freeing xfrm states.
Fix this by introducing and make use of a new helper for freeing xfrm_state objects.
--- include/net/xfrm.h | 1 + net/xfrm/xfrm_state.c | 8 +++++++- net/xfrm/xfrm_user.c | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-)
include/net/xfrm.h +1 -0
@@ -1552,6 +1552,7 @@ int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk, int (*func)(struct xfrm_state *, int, void*), void *);void xfrm_state_walk_done (struct xfrm_state_walk *walk,struct net *net);struct xfrm_state *xfrm_state_alloc (struct net *net); +void xfrm_state_free (struct xfrm_state *x); struct xfrm_state *xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr, const struct flowi *fl,
net/xfrm/xfrm_state.c +7 -1
@@ -426,6 +426,12 @@ static void xfrm_put_mode(struct xfrm_mode *mode)module_put (mode->owner); } +void xfrm_state_free (struct xfrm_state *x) +{ +kmem_cache_free (xfrm_state_cache, x); +} +EXPORT_SYMBOL (xfrm_state_free); +static void xfrm_state_gc_destroy (struct xfrm_state *x) {tasklet_hrtimer_cancel (&x->mtimer);
@@ -452,7 +458,7 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x) }xfrm_dev_state_free (x);security_xfrm_state_free (x); -kmem_cache_free (xfrm_state_cache, x); +xfrm_state_free (x); }static void xfrm_state_gc_task (struct work_struct *work)
net/xfrm/xfrm_user.c +2 -2
@@ -2288,13 +2288,13 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, } -kfree (x); +xfrm_state_free (x);kfree (xp);return 0 ; free_state: -kfree (x); +xfrm_state_free (x); nomem:return err; }
Quoted 10 lines · Mathias Krause
-- >8 --
Subject: [PATCH]
xfrm_user: fix freeing of xfrm states on acquireCommit
565f0fa902b6("xfrm: use a dedicated slab cache for structxfrm_state") moved xfrm state objects to use their own slab cache. However, it missed to adaptxfrm_userto use this new cache when freeing xfrm states.
Quoted 7 lines
Fix this by introducing and make use of a new helper for freeing
xfrm_stateobjects.Fixes 565f0fa902b6 ("xfrm: use a dedicated slab cache for struct xfrm_state")Reported-by Pan Bian <[email protected]>Cc <[email protected]> # v4.18+Signed-off-by Mathias Krause <[email protected]>
Looks good to me. Thanks!
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 14 lines · Herbert Xu
Quoted 13 lines · Mathias Krause
-- >8 --
Subject: [PATCH]
xfrm_user: fix freeing of xfrm states on acquireCommit
565f0fa902b6("xfrm: use a dedicated slab cache for structxfrm_state") moved xfrm state objects to use their own slab cache. However, it missed to adaptxfrm_userto use this new cache when freeing xfrm states.Fix this by introducing and make use of a new helper for freeing
xfrm_stateobjects.
Quoted 6 lines
Quoted 4 lines
Fixes 565f0fa902b6 ("xfrm: use a dedicated slab cache for struct xfrm_state")Reported-by Pan Bian <[email protected]>Cc <[email protected]> # v4.18+Signed-off-by Mathias Krause <[email protected]>Acked-by Herbert Xu <[email protected]>
Applied, thanks everyone!