Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3293810rwa; Tue, 23 Aug 2022 02:09:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR4FYdih61OsEWZRfxIPn3vfl0OmEPB4YJUSBQexLdXk24a3ngExr/kFeKIpK2lxLo7LR5r0 X-Received: by 2002:a05:6402:348f:b0:446:c0ce:86ab with SMTP id v15-20020a056402348f00b00446c0ce86abmr2845467edc.386.1661245760439; Tue, 23 Aug 2022 02:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245760; cv=none; d=google.com; s=arc-20160816; b=OQaI78/HAHvbvgldqIigfLR57vRVGehNOOc2D7EIaCreIF9ZZxP0hhWP9mlA1eggC0 ySt3U1qpUgeDzpzh1EgSBnfiC124XTAcoTKSzIWmefwsnSpK0gd7MIxx0hfGwtCJcNIn fZrEV4ioxjzGjY+WJ7fqbRDkqAM4EyGmD/WBmaiY9GrWf0HD2q9GnmV8CkI7LQWCTO7J Zq/lXMk0E4gAs7IVdVlWqukqrrkiqHMYiPAtMapF+WIGSO9BTZko09E3i1UmOUVKQ5Qp wUdU8jum5n4BnEBo/JeVuOyQet+DTMxNr2taiALu+eMVk7UPkjOiYw+2pws9/hS5mCC1 lsDA== 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=16hBClSEb2fjKAyMilkzDk+h55sZvwjC27euP65EtTA=; b=HafVWP1CYJEKiPdHHTFDVwpy4d6gxlk0ViWZBngsgXWtP+hHCQ4DGrMIRhRBGbePq9 xy72LAP9pkCmoq6CdbFM7VhhRmc5hF1BypK90JHY3TObfJ3RZPhajtrld71xem00UtGy WG4gAXIqewLA6dUHfmNbNWhXzhEJhMh15DrgmdzTdeaEYGh8Bc2RpGix2AtnUt3o4iwE hC5B5ss1+Cd8omk/s67mPNpjHvN2TnkkC5zdu5+H3rQoD71HLY/lS2qU6UKfyuGHJTst 72J3IzMdn2ESDWgkDYrqAaOZjiHpd8Wj36X9mVnZ+9R+fRyjS7TQT+PoGmG5rhKvbY8P 1p6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x8iHAHYM; 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 b11-20020a056402084b00b00445f4337b07si1982121edz.362.2022.08.23.02.08.51; Tue, 23 Aug 2022 02:09:20 -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=x8iHAHYM; 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 S241971AbiHWJAy (ORCPT + 99 others); Tue, 23 Aug 2022 05:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346082AbiHWJAS (ORCPT ); Tue, 23 Aug 2022 05:00:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 887E081B07; Tue, 23 Aug 2022 01:27:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C4BB96148B; Tue, 23 Aug 2022 08:27:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4C65C433D6; Tue, 23 Aug 2022 08:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243230; bh=Fc/ptDfLjFPxNpv7wJK9pnk9GeqBK66W9EGqSZq/lbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x8iHAHYMRx4okq1GrzA/hO3IvWyj+JH2I+mp6eyfzjc0AB0tiVO5d8od0VEcoD23x IPh8QgElPX6tBAv+WnnUz8CSuCSrWn3kFZ8dA4/zr/NLbHel0LjaLhW+YQfpdUeHc8 5cPmLZGiE9vawbeuxpShIMXJJ0qOLq8NhjDr/2dQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Xiong , Xin Tan , "David S. Miller" Subject: [PATCH 5.19 211/365] net: fix potential refcount leak in ndisc_router_discovery() Date: Tue, 23 Aug 2022 10:01:52 +0200 Message-Id: <20220823080127.025493750@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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: Xin Xiong commit 7396ba87f1edf549284869451665c7c4e74ecd4f upstream. The issue happens on specific paths in the function. After both the object `rt` and `neigh` are grabbed successfully, when `lifetime` is nonzero but the metric needs change, the function just deletes the route and set `rt` to NULL. Then, it may try grabbing `rt` and `neigh` again if above conditions hold. The function simply overwrite `neigh` if succeeds or returns if fails, without decreasing the reference count of previous `neigh`. This may result in memory leaks. Fix it by decrementing the reference count of `neigh` in place. Fixes: 6b2e04bc240f ("net: allow user to set metric on default route learned via Router Advertisement") Signed-off-by: Xin Xiong Signed-off-by: Xin Tan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ndisc.c | 3 +++ 1 file changed, 3 insertions(+) --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1358,6 +1358,9 @@ static void ndisc_router_discovery(struc if (!rt && lifetime) { ND_PRINTK(3, info, "RA: adding default router\n"); + if (neigh) + neigh_release(neigh); + rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev, pref, defrtr_usr_metric); if (!rt) {