Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp108616rwb; Sat, 17 Sep 2022 01:43:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4gk8EC4wmIWjPKRRry8fOiHyhkTt3CyfUH2C+PgeGhMvsBfQFfwqINQYttY0RAQec/GN3d X-Received: by 2002:a17:907:744:b0:741:36b9:d2cc with SMTP id xc4-20020a170907074400b0074136b9d2ccmr5948148ejb.613.1663404224418; Sat, 17 Sep 2022 01:43:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663404224; cv=none; d=google.com; s=arc-20160816; b=vIdqrMHAi2Q9W3wjuWrpSHvMu6sKgoeeAGGF9lXO4ypdGMi7GIS/hjARDKrsZMAraR 8shjArmlwxUNDmoJY9xCoM0vQhQKFCjWTf5XlknNNUQpka3QZgfaI40hF08a2dOs1j4V frzlB7cNvZ5sRDM8snym3QS+SOH9cXci8607LPFFCKqtLB04be6pU3MXPviFIO+LeG8F lprxO52BCMUE5MQUQTVSJEi/Y2RaOnUjg7/mpbjyaCJNB2ONlzZuSP+vHdSVqNoE+Wyc g4WAzfhE1iKyGnEDSIUiXVFb//CriNBO+UZGA9l616LI0ZazFRyZpRu9Ii9byvbVUNJv kVEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vqIwZcKbluvTMAjTQnpYPyZCNj+oMkHihHLd47ipyyI=; b=yZUaAY7jLbsXNrksC1efzZkGDqYANoA5M0v/hnHLUNBFTzVyN9A+iPTu3HMBfs029E cmMwzGScP3+KSZ/wqpnxs21GuDVuIRXqqk6duvuUCnqRkxH+2xStSBOuMKTF8ww+J89j +KX7wWQJcqsc32LkTZsmjjY+CX2f3GmNDvQz1QqnfEnkTjOAhtLAguDIhXHgZXm+Ifk6 TYB3qNamzDaUN6ugaVJBC5rRAKkDBGLQ2LWviDhsneK6/TR1WNXwa5ErYBgh4wiSQuih 9hMH94lYEJPw4IwijAjQGeCWpGoNWhOh2Nu0h++mAdy4jKyfq3j0qcQMAC9xZrw6H6JB 1CQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@blackwall-org.20210112.gappssmtp.com header.s=20210112 header.b=Ef7g1m4+; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a05640227c700b004488373d5b8si4991440ede.24.2022.09.17.01.43.18; Sat, 17 Sep 2022 01:43:44 -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=@blackwall-org.20210112.gappssmtp.com header.s=20210112 header.b=Ef7g1m4+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229529AbiIQI34 (ORCPT + 99 others); Sat, 17 Sep 2022 04:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiIQI3x (ORCPT ); Sat, 17 Sep 2022 04:29:53 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2AA1DA6A for ; Sat, 17 Sep 2022 01:29:52 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id z21so34594546edi.1 for ; Sat, 17 Sep 2022 01:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=vqIwZcKbluvTMAjTQnpYPyZCNj+oMkHihHLd47ipyyI=; b=Ef7g1m4+vE1Dt7lR3DUQwBwTEgs0WbZr/amckJGN+EOQd+CrTqhZbebMrT+mSohUrD F9LVB8+udY3wh9btWp80YNqBtZNKoIkFqhBoIM3NiC0bihx9q3PrEs27bwFPTXVpLW4O ZfBNtA6iycztalaD13pWRObb3AQH9z7ug7JpOK1v3yX58zWvDsio/N6vqd4Z0tlg7m1C VvcApICnw8fTjarDEIBhI4OGDuoriLh5yoBESYfssj6qjtNL4nN2bYpk7G/OekMyYMEH I4OoubY0L+6CHIiOsc0Hth49BPelD+nXWiKJiQZiZxnmG26coMzQcEINy5enuCP3Vv8q uzGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=vqIwZcKbluvTMAjTQnpYPyZCNj+oMkHihHLd47ipyyI=; b=xiwnNfGBLNzkSbAMklprfPOE5yBPTfx3hxL9DvyJWD5xSucfLlkZUYtYpCx/d1LOnn JPZG2fX9/2xIwNH0RLfjKDAdA4sjMVJD0EXgKNvwDiEifVb5a9/1VPc/huiScFpI5fLX Bf50aFQcpNwn9lVbmEOYYesKa+q5Dkjp7yAoaaIiSysXqOGdIGJnjGZHiLIMGvn9Uav5 pq03xg3eY39NLty962O7Ayd0MVUHUd/8dQhXNtTwFSQT8SjPV3AWMldB2Ykb1sOxi8bA y8c+rRrZN58GAwoVWaknlf+/ywVZkbANLaC0e2mT4J0dR0kGoG/6OALmhO1dfRw+MoKy P1rA== X-Gm-Message-State: ACrzQf3oiRhK0x6Tk+GtzkpYObaykddQDMkR89S2xNLiuZ/rBuDgNI2Y 2YNDuTlK9PciQk6bfS0+oxTAvD83VMkdSyGb X-Received: by 2002:aa7:c0c5:0:b0:453:9a23:a0cd with SMTP id j5-20020aa7c0c5000000b004539a23a0cdmr1725459edp.286.1663403390628; Sat, 17 Sep 2022 01:29:50 -0700 (PDT) Received: from [192.168.0.111] (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id v23-20020aa7cd57000000b0044e796598bdsm15260506edw.11.2022.09.17.01.29.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Sep 2022 01:29:50 -0700 (PDT) Message-ID: <9974177e-7067-aacd-1c53-7e82616f3c3f@blackwall.org> Date: Sat, 17 Sep 2022 11:29:48 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH v1] net/ipv4/nexthop: check the return value of nexthop_find_by_id() To: Li Zhong , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org References: <20220917023020.3845137-1-floridsleeves@gmail.com> Content-Language: en-US From: Nikolay Aleksandrov In-Reply-To: <20220917023020.3845137-1-floridsleeves@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 On 17/09/2022 05:30, Li Zhong wrote: > Check the return value of nexthop_find_by_id(), which could be NULL on > when not found. So we check to avoid null pointer dereference. > > Signed-off-by: Li Zhong > --- > net/ipv4/nexthop.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c > index 853a75a8fbaf..9f91bb78eed5 100644 > --- a/net/ipv4/nexthop.c > +++ b/net/ipv4/nexthop.c > @@ -2445,6 +2445,10 @@ static struct nexthop *nexthop_create_group(struct net *net, > struct nh_info *nhi; > > nhe = nexthop_find_by_id(net, entry[i].id); > + if (!nhe) { > + err = -EINVAL; > + goto out_no_nh; > + } > if (!nexthop_get(nhe)) { > err = -ENOENT; > goto out_no_nh; These are validated in nh_check_attr_group() and should exist at this point. Since remove_nexthop() should run under rtnl I don't see a way for a nexthop to disappear after nh_check_attr_group() and before nexthop_create_group(). Did you notice a problem or have a stack dump?