Hi Hangbin,

On Wed,  6 Feb 2019 20:51:10 +0800
Hangbin Liu <liuhang...@gmail.com> wrote:

> When we add a new GENEVE device with IPv6 remote, checking only for
> IS_ENABLED(CONFIG_IPV6) is not enough as we may disable IPv6 in kernel
> cmd(ipv6.disable=1), which will cause a NULL pointer dereference.
> 
> Reported-by: Jianlin Shi <ji...@redhat.com>
> Signed-off-by: Hangbin Liu <liuhang...@gmail.com>
> ---
>  drivers/net/geneve.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
> index 58bbba8582b0..0658715581e3 100644
> --- a/drivers/net/geneve.c
> +++ b/drivers/net/geneve.c
> @@ -1512,6 +1512,10 @@ static void geneve_link_config(struct net_device *dev,
>       }
>  #if IS_ENABLED(CONFIG_IPV6)
>       case AF_INET6: {
> +             struct inet6_dev *idev = in6_dev_get(dev);
> +             if (!idev)
> +                     break;
> +
>               struct rt6_info *rt = rt6_lookup(geneve->net,
>                                                &info->key.u.ipv6.dst, NULL, 0,
>                                                NULL, 0);

You're mixing declarations and code here, ISO C90 forbids it. You
could rather declare:

                struct inet6_dev *idev = in6_dev_get(dev);
                struct rt6_info *rt;

then check idev, and then call rt6_lookup().

> @@ -1519,6 +1523,8 @@ static void geneve_link_config(struct net_device *dev,
>               if (rt && rt->dst.dev)
>                       ldev_mtu = rt->dst.dev->mtu - GENEVE_IPV6_HLEN;
>               ip6_rt_put(rt);
> +
> +             in6_dev_put(idev);

I think it would be better to put this right after the check on idev,
mostly for readability, but also, marginally, to reduce the scope of
the reference count bump.

-- 
Stefano

Reply via email to