Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp928820rwb; Sat, 17 Sep 2022 19:16:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zHCkDyKByctih0tYBvlDTV1VT/wpCNNJRCwZkHlGEXqWyZboOx9U5ZVVmKPxcyxStgbcg X-Received: by 2002:a17:90a:6ac5:b0:200:3216:d5fd with SMTP id b5-20020a17090a6ac500b002003216d5fdmr13329595pjm.191.1663467399557; Sat, 17 Sep 2022 19:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663467399; cv=none; d=google.com; s=arc-20160816; b=kFfA+T1T5eHPV6tJlbvvSr8U6zQ19ZmqC3bocZgTU6O3z/vzHYXKgM4e2h/f4Q1qH0 RneOnmxokgtGrlrMIiS1MXEpDhYmtHmrMkvJrbnDEE+sZxCVOX0NWkCbDJmA0fju5ZbT tokd5nmWqfmJovCe6YKvmBllE1iQcPFnZc3oHVc6FoDNgpK+i7kAyNKdczMN4yCpsLha 7v2CY67UCH9RSVc3XRIkS1XQ5FAJKsVRqkztbj6rEkDNEFbONxVvwCaKX4wlqdry3zEX +LMZ2uqMwA7LF5AqEfoMbQX+xlwX8v0tLWUu013Kgrfc1cjkNSK6sA6jQm1nP6CUIzT8 nhnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vpLxdyKTQCyc+XXz6eDep0CGfvlOkSywIi+7ypB726k=; b=WfDgzkh3KAtbsIotYwu4cCuouFYaj1f1uevBjR6jkukl7ju8mPYrl/4sOs5FwFBvm3 vFvIRBYme3rJw8duCmTXbh7Na2S+8f4lR+cmgiY5/CnTDuae+mSk4ij2WzU63/PIAn1X WGctbSIGpy42LFYgmYu8xpSlVrr7BJAv7BCNYboCk8mp2rZCQS5BNdW2g5LkeZtBj8PS 1qL3DDxfYCGCDVMUtJIYlALuXgqC1dithrkyGvrix/UoyavdouZGZvskW9FpuPOCkQfl F8Ng6x0mW5Ug6uZDLtOhkDShL5V7HKgUUqI9DZz13UE5asgjnjEejlbPDx0SaCzx7X6S S0LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jwMfrwTV; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id az3-20020a056a02004300b004391c48220fsi20725266pgb.257.2022.09.17.19.16.08; Sat, 17 Sep 2022 19:16:39 -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=@gmail.com header.s=20210112 header.b=jwMfrwTV; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229494AbiIRByw (ORCPT + 99 others); Sat, 17 Sep 2022 21:54:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiIRByu (ORCPT ); Sat, 17 Sep 2022 21:54:50 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80DD1F5A2; Sat, 17 Sep 2022 18:54:48 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id r18so57231248eja.11; Sat, 17 Sep 2022 18:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=vpLxdyKTQCyc+XXz6eDep0CGfvlOkSywIi+7ypB726k=; b=jwMfrwTVPg9ertXaTz3+PQGYRGM/HzR32kEfzPWUDK9C7WbrzIEDmQ0TuQgt4qAjI0 ts+q23u5jtBAfJYUCUTsp2XUckzQCIu87ywtVIqgJsMxqFZpMpvm+KF7t787g2YFrT/n 1+gufmBPrJkOsouKBJHyu3ZUZz8UyPb5cuhJ21PiFm3dciMDD+iomtxFVmtHQM/cqYfG zoUnnj7Y8mhAFGdFAGbxY7hq9+dPGX1u47uYsxZPvkhBjuaqPuOFo8VQDAfWhBePwgMt AZlzZAE2IdRXWrgvPW2gOb33uhNqb1WBUwsiiHLHzV6nXsK/MIiOvSq2k1nl+frWeVdU dsRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=vpLxdyKTQCyc+XXz6eDep0CGfvlOkSywIi+7ypB726k=; b=rse9w2DJBqt0ARjEEmGKkKKLzcF7N4V53Zz59+SrYTZ0t5aZarB54TYcwxCgJ+Y1St 4Bf4mriy9Ua04T3VsICl0faapWt0mLpaZ4xwuqnS52HmIx1ZFXu7b/yxkcLjTC/v7CVO cNNsHKvbGpX1ym6gR6Vmg2KBNgDrGDCAr12jw2jaaMMmHcbddMlMvrc3gXBLL7t9BbUK 1yepJhZouN6Xstg/7XPPlYup8E/uALflKcsgC/GWn2Hp2UchdZraYM6pZ0mtRJw11gYM Ky1CD20LRpXCIFI8eVMXSQbGPhc/yH4r9WGbNmOUAt2rU+9e76TqbL2H75eosFRLvjnL FL6Q== X-Gm-Message-State: ACrzQf1pjoCS/uaqgAv9qCq/XOfM/cFqHx7hacpwEjfGIigAtJNoOAH1 SB9UDlyRDVhRsqBnvG0hHau/kafaiwYNgtC4H+A= X-Received: by 2002:a17:907:a088:b0:780:da07:9df3 with SMTP id hu8-20020a170907a08800b00780da079df3mr3753660ejc.252.1663466086845; Sat, 17 Sep 2022 18:54:46 -0700 (PDT) MIME-Version: 1.0 References: <20220917023020.3845137-1-floridsleeves@gmail.com> <9974177e-7067-aacd-1c53-7e82616f3c3f@blackwall.org> In-Reply-To: From: Li Zhong Date: Sat, 17 Sep 2022 18:54:35 -0700 Message-ID: Subject: Re: [PATCH v1] net/ipv4/nexthop: check the return value of nexthop_find_by_id() To: David Ahern Cc: Nikolay Aleksandrov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, yoshfuji@linux-ipv6.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 On Sat, Sep 17, 2022 at 7:46 AM David Ahern wrote: > > On 9/17/22 2:29 AM, Nikolay Aleksandrov wrote: > > 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(). > > > > exactly. That lookup can't fail because the ids have been validated and > all of this is under rtnl preventing nexthop removes. > Thanks for all your replies. That makes sense to me.