From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B686CC169C4 for ; Wed, 6 Feb 2019 14:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9119320844 for ; Wed, 6 Feb 2019 14:58:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730960AbfBFO6f (ORCPT ); Wed, 6 Feb 2019 09:58:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43050 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbfBFO6e (ORCPT ); Wed, 6 Feb 2019 09:58:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 657E28DA29; Wed, 6 Feb 2019 14:58:34 +0000 (UTC) Received: from localhost (ovpn-200-19.brq.redhat.com [10.40.200.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BABF62FAC; Wed, 6 Feb 2019 14:58:32 +0000 (UTC) Date: Wed, 6 Feb 2019 15:58:27 +0100 From: Stefano Brivio To: Hangbin Liu Cc: netdev@vger.kernel.org, David Miller Subject: Re: [PATCH net 1/2] geneve: should not call rt6_lookup() when ipv6 was disabled Message-ID: <20190206155827.222bb25e@redhat.com> In-Reply-To: <20190206125111.5286-2-liuhangbin@gmail.com> References: <20190206125111.5286-1-liuhangbin@gmail.com> <20190206125111.5286-2-liuhangbin@gmail.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 06 Feb 2019 14:58:34 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi Hangbin, On Wed, 6 Feb 2019 20:51:10 +0800 Hangbin Liu 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 > Signed-off-by: Hangbin Liu > --- > 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