2019-03-14 07:00:45

by Su, Yanjun

[permalink] [raw]
Subject: [PATCH] xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module

When unloading xfrm6_tunnel module, xfrm6_tunnel_fini directly
frees the xfrm6_tunnel_spi_kmem. Maybe someone has gotten the
xfrm6_tunnel_spi, so need to wait it.

Fixes: 91cc3bb0b04ff("xfrm6_tunnel: RCU conversion")
Signed-off-by: Su Yanjun <[email protected]>
---
net/ipv6/xfrm6_tunnel.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index bc65db7..12cb3aa 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -402,6 +402,10 @@ static void __exit xfrm6_tunnel_fini(void)
xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
unregister_pernet_subsys(&xfrm6_tunnel_net_ops);
+ /* Someone maybe has gotten the xfrm6_tunnel_spi.
+ * So need to wait it.
+ */
+ rcu_barrier();
kmem_cache_destroy(xfrm6_tunnel_spi_kmem);
}

--
2.7.4





2019-03-15 06:25:52

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module

On Thu, Mar 14, 2019 at 02:59:42PM +0800, Su Yanjun wrote:
> When unloading xfrm6_tunnel module, xfrm6_tunnel_fini directly
> frees the xfrm6_tunnel_spi_kmem. Maybe someone has gotten the
> xfrm6_tunnel_spi, so need to wait it.
>
> Fixes: 91cc3bb0b04ff("xfrm6_tunnel: RCU conversion")
> Signed-off-by: Su Yanjun <[email protected]>
> ---
> net/ipv6/xfrm6_tunnel.c | 4 ++++
> 1 file changed, 4 insertions(+)

This looks good to me. And it's not just the matter of accessing
freed memory. A worse problem would be trying to execute code
from an unloaded module.

Acked-by: Herbert Xu <[email protected]>

> diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
> index bc65db7..12cb3aa 100644
> --- a/net/ipv6/xfrm6_tunnel.c
> +++ b/net/ipv6/xfrm6_tunnel.c
> @@ -402,6 +402,10 @@ static void __exit xfrm6_tunnel_fini(void)
> xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
> xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
> unregister_pernet_subsys(&xfrm6_tunnel_net_ops);
> + /* Someone maybe has gotten the xfrm6_tunnel_spi.
> + * So need to wait it.
> + */
> + rcu_barrier();
> kmem_cache_destroy(xfrm6_tunnel_spi_kmem);
> }

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2019-03-17 10:14:38

by Steffen Klassert

[permalink] [raw]
Subject: Re: [PATCH] xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module

On Fri, Mar 15, 2019 at 02:24:38PM +0800, Herbert Xu wrote:
> On Thu, Mar 14, 2019 at 02:59:42PM +0800, Su Yanjun wrote:
> > When unloading xfrm6_tunnel module, xfrm6_tunnel_fini directly
> > frees the xfrm6_tunnel_spi_kmem. Maybe someone has gotten the
> > xfrm6_tunnel_spi, so need to wait it.
> >
> > Fixes: 91cc3bb0b04ff("xfrm6_tunnel: RCU conversion")
> > Signed-off-by: Su Yanjun <[email protected]>
> > ---
> > net/ipv6/xfrm6_tunnel.c | 4 ++++
> > 1 file changed, 4 insertions(+)
>
> This looks good to me. And it's not just the matter of accessing
> freed memory. A worse problem would be trying to execute code
> from an unloaded module.
>
> Acked-by: Herbert Xu <[email protected]>

Applied, thanks everyone!