Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3345451rwa; Tue, 23 Aug 2022 03:15:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5I8nD83MId6b54uSP1Wu7HUwfgOF/tI4doxhzunufraFxrXHO+SqZ6N81MvYsziqoc8m7G X-Received: by 2002:a17:907:2bce:b0:73d:6ab5:17f4 with SMTP id gv14-20020a1709072bce00b0073d6ab517f4mr9164771ejc.632.1661249743319; Tue, 23 Aug 2022 03:15:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661249743; cv=none; d=google.com; s=arc-20160816; b=ONDAAb/NhRLIS2B5CwbAlZxB+8l8voAD4tzzbcb8BoLoCUh8Oc4CuAT4zreYN+WN2z uklaFerxCXzKFIVROTHDCUQTrjqa6dZoLEEKTueM0Kr0hDFDRyxGsdoOeFe0lS8bEGLx C/Q1czomxIc49yuEc0pnT8Rm00+czPWh9Etp/rfgMm/PvUaRjukI4LDhU95LTR5p5bm3 WGLVfI2kSwK2M1DxQUHWz/vO8FZHtXLXfE5iG59//EUPEZbulZmBpLjh5Q+xJkxXauqT PO+5bsYdsH2MKV69ZAtM4dsJxDPPwg1FFZW89uHN+Q3RDdGYOr+LA4RS70f+kyXbMOWD QW8g== 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=egcrLaEQWEwWbmFko9CPWeP9IPFwz8DjznshVgIgDUw=; b=C/mY45kY8TOyYCY93ra1YAglsvqhLCCyshYg1NSvbkkbyOjgQpbdlEf62o+vimI4c8 ePMVAx+8P/tmuEWLQxxQT3kl/jaKqc1qwD/eEodSCzNCkMLhK9L58J1wbv5+Ug6UEtwv G7ZtGJOP6jm7BCXt61nqrbrXCN+nAlkNW8kZ6D3vjC8C+SPuwSttNAm8/q1iZZuRY0pN Q+HSLNzUMKv8lRBWWdWKkcLCUDV93TYRR9sfonUV1fa/481rPEJ/pfbYafVzsIZiduLW UmGizrA4+IRTyIoh/5dmVujBlQcOwj8Zq1Ski0Qn6K3L1mOb+sgMpQYfITtaOkU53tWk N6ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qWCKcINg; 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 s1-20020a17090699c100b0073c1d6b30fbsi13994162ejn.355.2022.08.23.03.15.17; Tue, 23 Aug 2022 03:15:43 -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=qWCKcINg; 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 S1353953AbiHWKMU (ORCPT + 99 others); Tue, 23 Aug 2022 06:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243465AbiHWKFU (ORCPT ); Tue, 23 Aug 2022 06:05:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F9E1A262D; Tue, 23 Aug 2022 01:51:57 -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 754286123D; Tue, 23 Aug 2022 08:51:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 749F7C433D6; Tue, 23 Aug 2022 08:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244715; bh=j77QJl1TcNYkGHqZiSjCkKoxYzy27qIOtLmaK1Cnxb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qWCKcINgZ+uizg6URZOvVOhbgAZKlpFWr3/EvbdJEMRYpxFpWQEAH0+D9kHL5wTBJ rdNLliWJHKSGLR3UYd4iuLREs7tbg24yhirINbSRmpj51rHgWD9Sw5EslWgwwnI9vl jgSXAFrugGWEQ+FFTpPAtDgcvTjSSbGwfeOONc0o= 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.15 138/244] net: fix potential refcount leak in ndisc_router_discovery() Date: Tue, 23 Aug 2022 10:24:57 +0200 Message-Id: <20220823080103.755618325@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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 @@ -1317,6 +1317,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) {