Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3393031ybp; Sun, 6 Oct 2019 10:57:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzX8mK6SAhfv23trnHOfBAPo0dq1E01i23HSPGu2DQHMDXZrNLa3ggxc6rhMx2eJRTdMKvO X-Received: by 2002:a50:a41c:: with SMTP id u28mr25476353edb.185.1570384644290; Sun, 06 Oct 2019 10:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384644; cv=none; d=google.com; s=arc-20160816; b=lc0SA8ZBsy0HSrTMkjnRmMMRsSGoPDeQYT+B6BV7b+GHUCq7IVclAoFASFtof693Lf bgUh4/3/ApmZBvR8b6VTh6Qv7nGlRU44sGFiOQns8Zk/AJ04zYkh5Y/VJxCiBOufFsXQ /dh6IYR9hBHEVhfXW1bWTqaK1wr45hTt6xTUfKXblL6YhId2UR5jxQ+eoT2NhmsT2Fx6 nN9Fa84G/+00qf33TfSpPl2S7vdLbimdcQIHwOPh6d4tfspAfY405ojRIMlpe3Tfm5VV Gr9aGYW4uZd4G7G/wLiGYolCE80F57ox830GU4QV0yIUJkZKIZ42WTsKPcAWKMl+PLLQ TMVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pChrkyKVDPfAIHqUYyBCz4EGSMFobf34ZN3JInbsj+g=; b=HQs4vVsH/SO/FmbFaDCs31O4/DJ0MYKvSa9s31x3kltmyEccnZvjfScS1uHCHYOSpa VY8Vx67CbdqCVKxYNZSHsIUNqIzviIRBf6WdpGRe/z+9S4VJ1CY0WoaTKeeuiTuiVWOb tXX7mtRCWIzYOcRESBc7LyqnT/c+gjTMOrsxY6rveJH1SSbRH8/t8NvEfVvo5z81OT25 o8pDnJ8TG0zjlSV1jml81Ikv5rwyDSlz5ErkHkkcd0WFPpRN18A1RssO8E6YkSDOFrrC WqbxojgumQU5CHRCXyal0haJgVYJFpj5l97uFpiE+Duy8juh0gHIkm/OjSzzpZy3uoDz n4rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K+Y3iu45; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e25si7628958edb.308.2019.10.06.10.57.00; Sun, 06 Oct 2019 10:57:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K+Y3iu45; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729935AbfJFReX (ORCPT + 99 others); Sun, 6 Oct 2019 13:34:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:32888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729927AbfJFReU (ORCPT ); Sun, 6 Oct 2019 13:34:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 460352080F; Sun, 6 Oct 2019 17:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383259; bh=Jbi6amqW/v8CYVXQA06UFDffvZQJOUPYCkTYaT+G2XU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K+Y3iu45/D5nBL5xrYSl7lvrRt25v/GM5byiz2KIEKTcAsakKpZCvIXQRXpoPjrsl NtJFE0TN4iCNVVYmEC9y/30Jr4vqhZPnn9v8AMOl3m6Oi2hFi9nldr3AYwoW4EDUL6 qgoCFN80h0vuzPx89/z8FsRsMxjB0EV2sjthQPxM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rajendra Dendukuri , David Ahern , Eric Dumazet , "David S. Miller" Subject: [PATCH 5.2 005/137] ipv6: Handle missing host route in __ipv6_ifa_notify Date: Sun, 6 Oct 2019 19:19:49 +0200 Message-Id: <20191006171210.032118824@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Ahern [ Upstream commit 2d819d250a1393a3e725715425ab70a0e0772a71 ] Rajendra reported a kernel panic when a link was taken down: [ 6870.263084] BUG: unable to handle kernel NULL pointer dereference at 00000000000000a8 [ 6870.271856] IP: [] __ipv6_ifa_notify+0x154/0x290 [ 6870.570501] Call Trace: [ 6870.573238] [] ? ipv6_ifa_notify+0x26/0x40 [ 6870.579665] [] ? addrconf_dad_completed+0x4c/0x2c0 [ 6870.586869] [] ? ipv6_dev_mc_inc+0x196/0x260 [ 6870.593491] [] ? addrconf_dad_work+0x10a/0x430 [ 6870.600305] [] ? __switch_to_asm+0x34/0x70 [ 6870.606732] [] ? process_one_work+0x18a/0x430 [ 6870.613449] [] ? worker_thread+0x4d/0x490 [ 6870.619778] [] ? process_one_work+0x430/0x430 [ 6870.626495] [] ? kthread+0xd9/0xf0 [ 6870.632145] [] ? __switch_to_asm+0x34/0x70 [ 6870.638573] [] ? kthread_park+0x60/0x60 [ 6870.644707] [] ? ret_from_fork+0x57/0x70 [ 6870.650936] Code: 31 c0 31 d2 41 b9 20 00 08 02 b9 09 00 00 0 addrconf_dad_work is kicked to be scheduled when a device is brought up. There is a race between addrcond_dad_work getting scheduled and taking the rtnl lock and a process taking the link down (under rtnl). The latter removes the host route from the inet6_addr as part of addrconf_ifdown which is run for NETDEV_DOWN. The former attempts to use the host route in __ipv6_ifa_notify. If the down event removes the host route due to the race to the rtnl, then the BUG listed above occurs. Since the DAD sequence can not be aborted, add a check for the missing host route in __ipv6_ifa_notify. The only way this should happen is due to the previously mentioned race. The host route is created when the address is added to an interface; it is only removed on a down event where the address is kept. Add a warning if the host route is missing AND the device is up; this is a situation that should never happen. Fixes: f1705ec197e7 ("net: ipv6: Make address flushing on ifdown optional") Reported-by: Rajendra Dendukuri Signed-off-by: David Ahern Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/addrconf.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -5962,13 +5962,20 @@ static void __ipv6_ifa_notify(int event, switch (event) { case RTM_NEWADDR: /* - * If the address was optimistic - * we inserted the route at the start of - * our DAD process, so we don't need - * to do it again + * If the address was optimistic we inserted the route at the + * start of our DAD process, so we don't need to do it again. + * If the device was taken down in the middle of the DAD + * cycle there is a race where we could get here without a + * host route, so nothing to insert. That will be fixed when + * the device is brought up. */ - if (!rcu_access_pointer(ifp->rt->fib6_node)) + if (ifp->rt && !rcu_access_pointer(ifp->rt->fib6_node)) { ip6_ins_rt(net, ifp->rt); + } else if (!ifp->rt && (ifp->idev->dev->flags & IFF_UP)) { + pr_warn("BUG: Address %pI6c on device %s is missing its host route.\n", + &ifp->addr, ifp->idev->dev->name); + } + if (ifp->idev->cnf.forwarding) addrconf_join_anycast(ifp); if (!ipv6_addr_any(&ifp->peer_addr))