Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1942809imn; Mon, 1 Aug 2022 05:53:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sqNbq2rpu6yk2Px2GYFo53TpB3QJ35eOjpXiwnBNO9Jd5aTpkecopjTXE8OHPV2VPnYRoH X-Received: by 2002:a17:906:8a4f:b0:72b:615c:5af1 with SMTP id gx15-20020a1709068a4f00b0072b615c5af1mr12534708ejc.461.1659358422450; Mon, 01 Aug 2022 05:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659358422; cv=none; d=google.com; s=arc-20160816; b=ZnYlLT+eiCm5ABl43eEXDQqcAov9SgbNWu1j5r3nY+BQwoNavyeRURjaG4cPmDlO3p 3Au0aWbhohwlCmJ6BkjCHfSPHSGOTeRtVJopm+ETw4ekZAtemTrSm5J7Bc/9ou6B/VpH qDHBk+OVv+a1SSDTZWeiwtKT9pLP6QYgAHFD0FsulTe1JOd6JXOy5Ly4rz1UB7u1jRTs JU39ZY5S4AgcrTfSw3AFZQRX50v4FP2AdPDrLbxBkeatum0hKnJPa/bkiP1C/3wxkq/3 DLeTwMGMbWbJKi8V8LsjYTQqvNJWLZjV5zWE9qMDBARuRhQ2QUMqU+0pEa8U87POxaU4 574g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ij5iZINm/GZzX4jhrZnR0EyTKv6y9DwT6sJx2dnhqQo=; b=HCCSmyLltP4pTZfe91UCy+sWvEPC4E6//jGGXoZ4tBWMolo4A/xVTG4frO77EeteEI xppJznEnw/9eHva44VprdYtR7NypJz2Fju3L57OoTyIt9iMviTxui16ZWbx15BdVLvbh P5nUdsVGoYrKsBrZEMWX1VueIDQk3oqUuzY7xQthCFc1umtZx8agQDy8keK/GRpvqqPZ C8Kg3pD49wvJzZWYzAa8f87BOGKMl5XInMxMZiUhS0xjBKfpUjy4DnNK8cj/q1Ue/FTV i26G1F/zkMi4n7JFcWkmBPkY/AAFtBmsk6hyXaVPgTjlluLmCWQvsWO1Ku1Wo9vGjwkA fwag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1DJyuPJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a0564020e8300b0043d58fba67csi5115217eda.312.2022.08.01.05.53.17; Mon, 01 Aug 2022 05:53:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1DJyuPJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231599AbiHALxw (ORCPT + 99 others); Mon, 1 Aug 2022 07:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232114AbiHALxL (ORCPT ); Mon, 1 Aug 2022 07:53:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4396EB96; Mon, 1 Aug 2022 04:50:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ED5FCB8116E; Mon, 1 Aug 2022 11:50:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DEE2C433C1; Mon, 1 Aug 2022 11:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354610; bh=5uesq9rIRXGZcge29XMMG/2+QB+X/pWuqao7Azxf3tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1DJyuPJMmI6VAkUlHo9e2ryhqRVPNMEdhCKgExPuT6HDYIvKxt5GJbABkBgezI9sw s/Gkhevyi9ljqbPDviTVke0r7SbmOsFSa/CTpOvFRSBOoFIXYxhUH0f7fqYIOgqoo9 x6NwaMuFAgGTKynRzhMoxlHcl7jJQqIn2fQ8WkWI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ziyang Xuan , David Ahern , Jakub Kicinski Subject: [PATCH 5.10 22/65] ipv6/addrconf: fix a null-ptr-deref bug for ip6_ptr Date: Mon, 1 Aug 2022 13:46:39 +0200 Message-Id: <20220801114134.630598394@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114133.641770326@linuxfoundation.org> References: <20220801114133.641770326@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ziyang Xuan commit 85f0173df35e5462d89947135a6a5599c6c3ef6f upstream. Change net device's MTU to smaller than IPV6_MIN_MTU or unregister device while matching route. That may trigger null-ptr-deref bug for ip6_ptr probability as following. ========================================================= BUG: KASAN: null-ptr-deref in find_match.part.0+0x70/0x134 Read of size 4 at addr 0000000000000308 by task ping6/263 CPU: 2 PID: 263 Comm: ping6 Not tainted 5.19.0-rc7+ #14 Call trace: dump_backtrace+0x1a8/0x230 show_stack+0x20/0x70 dump_stack_lvl+0x68/0x84 print_report+0xc4/0x120 kasan_report+0x84/0x120 __asan_load4+0x94/0xd0 find_match.part.0+0x70/0x134 __find_rr_leaf+0x408/0x470 fib6_table_lookup+0x264/0x540 ip6_pol_route+0xf4/0x260 ip6_pol_route_output+0x58/0x70 fib6_rule_lookup+0x1a8/0x330 ip6_route_output_flags_noref+0xd8/0x1a0 ip6_route_output_flags+0x58/0x160 ip6_dst_lookup_tail+0x5b4/0x85c ip6_dst_lookup_flow+0x98/0x120 rawv6_sendmsg+0x49c/0xc70 inet_sendmsg+0x68/0x94 Reproducer as following: Firstly, prepare conditions: $ip netns add ns1 $ip netns add ns2 $ip link add veth1 type veth peer name veth2 $ip link set veth1 netns ns1 $ip link set veth2 netns ns2 $ip netns exec ns1 ip -6 addr add 2001:0db8:0:f101::1/64 dev veth1 $ip netns exec ns2 ip -6 addr add 2001:0db8:0:f101::2/64 dev veth2 $ip netns exec ns1 ifconfig veth1 up $ip netns exec ns2 ifconfig veth2 up $ip netns exec ns1 ip -6 route add 2000::/64 dev veth1 metric 1 $ip netns exec ns2 ip -6 route add 2001::/64 dev veth2 metric 1 Secondly, execute the following two commands in two ssh windows respectively: $ip netns exec ns1 sh $while true; do ip -6 addr add 2001:0db8:0:f101::1/64 dev veth1; ip -6 route add 2000::/64 dev veth1 metric 1; ping6 2000::2; done $ip netns exec ns1 sh $while true; do ip link set veth1 mtu 1000; ip link set veth1 mtu 1500; sleep 5; done It is because ip6_ptr has been assigned to NULL in addrconf_ifdown() firstly, then ip6_ignore_linkdown() accesses ip6_ptr directly without NULL check. cpu0 cpu1 fib6_table_lookup __find_rr_leaf addrconf_notify [ NETDEV_CHANGEMTU ] addrconf_ifdown RCU_INIT_POINTER(dev->ip6_ptr, NULL) find_match ip6_ignore_linkdown So we can add NULL check for ip6_ptr before using in ip6_ignore_linkdown() to fix the null-ptr-deref bug. Fixes: dcd1f572954f ("net/ipv6: Remove fib6_idev") Signed-off-by: Ziyang Xuan Reviewed-by: David Ahern Link: https://lore.kernel.org/r/20220728013307.656257-1-william.xuanziyang@huawei.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- include/net/addrconf.h | 3 +++ 1 file changed, 3 insertions(+) --- a/include/net/addrconf.h +++ b/include/net/addrconf.h @@ -405,6 +405,9 @@ static inline bool ip6_ignore_linkdown(c { const struct inet6_dev *idev = __in6_dev_get(dev); + if (unlikely(!idev)) + return true; + return !!idev->cnf.ignore_routes_with_linkdown; }