Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp270221rwn; Fri, 16 Sep 2022 20:12:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4vKWKRdKhpzBijis/s3dnJiOwIvbAQNpqRKdyYgZPlusDu9/XOCYrAxxxH5Vw5AtpL32cM X-Received: by 2002:a05:6402:5189:b0:451:791e:f328 with SMTP id q9-20020a056402518900b00451791ef328mr6285462edd.282.1663384362785; Fri, 16 Sep 2022 20:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663384362; cv=none; d=google.com; s=arc-20160816; b=jpfixq+pZjUvBwtrLqkKAmVuQUUzgeekvpl1F9X5BZj/zBnR2IZI6NGPHlj1zVNp/z TXTIpNIuZb3AeSRQ5SD64fvPP0d4LIbSeNBUrZV2Lfabr2lhhcXon0+PDo/0WXotoV8y gw7FieZan01B/ZHwB4re5cNABTAZMnp1AHddVCw/0qjFwkodJmc3UGq8goSmzu93QkSI qJYpsvic8n1hEVAxQjJbs54Irq+5ZJcqMQvhKx9EIrBiw9i7m5wmlKdYKY+BbkeRcUfa 8NPEU9lpHfh9rz2VzeBDwFcMB/bQDfHE7E4m0+TjjFuuzSMNlv49bg9EI0BD84yHUKSi FqwA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zFwcid0Q8E2gf9MQQjQKHEHwun7GkfVCpiWkqyhDqh4=; b=graxvDbxUWfsRr/m7OhuHWhFjnB2dYns+JH9LmzB6dfrDGTK9S2SHDp3Fa0NUKWB+X o2pSt+qU3voQ5mbl3H81PVcAklufWVclOCCY5+wEw9gxhb7TaPPLf+JPeQ+WBNxHjGGV dUbRpr+wZnIzNxOieUDFLICFoYmWMNTRuWf/j360QRkx57SPSq63omoWnFNneTydh2dL kmOY7Pj38vcpe0JwF7mGfiAYR4ZUQOkFawTBcUQhboCggV2qmnkO89vtbTnIRP14S2F5 B6HRcIogxpkX9yeuzN9V97Sjb7S4N/ZZFZ6eTaTG6kEexHx59myrV199K20HBpkFCNAC BORg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=G8854RFI; 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 qk18-20020a1709077f9200b00777795f0725si18120287ejc.139.2022.09.16.20.12.17; Fri, 16 Sep 2022 20:12: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=@gmail.com header.s=20210112 header.b=G8854RFI; 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 S229564AbiIQCak (ORCPT + 99 others); Fri, 16 Sep 2022 22:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbiIQCai (ORCPT ); Fri, 16 Sep 2022 22:30:38 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A13184ECC; Fri, 16 Sep 2022 19:30:37 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id a5-20020a17090aa50500b002008eeb040eso2534536pjq.1; Fri, 16 Sep 2022 19:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=zFwcid0Q8E2gf9MQQjQKHEHwun7GkfVCpiWkqyhDqh4=; b=G8854RFIbUsqLAvs+PS5n+DTD8Di9YVJ3g/J2nlPxPCzyoP07VEGUwIe9IN7PLjN7/ Gsnj0WUD612Gp7xtM0dZlyUO5TTGM4hEDL5cHE8DooSU/VY2OxFHPfdVMwv8OvEHRfXp C+RwPQXoX/7FT1bnqjnYNegaHXZeMqGCGfSlYTbmBP9xdwuZQG+sAS73R2NqVu/nnidG yJ6TA2a5zCpt5WKmgnmG8xjnVfaOXmCXDdF2U2mSsahy8t6Jfs+ZjFnLrfmhU1R6U+OF hHBVwZ53U3ZvCKbbwMa/TTucgsLuUgmiPB7iAnXuiAndsAeWLk77j3nZqNMEyF7KhDw+ 8XTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=zFwcid0Q8E2gf9MQQjQKHEHwun7GkfVCpiWkqyhDqh4=; b=LMK//abI6Dpw8+9Djni9d0DPQ3fa3HEEIlJzynDUlt61MbPeQQWCH8K0PVaDThavck K9A9gkOTwwtOWqQq6VeAfXBKEeepZaTpuTDvgLGZmMtiGv1VKBCqBi66b0KHTppvWt1S CF3iSQQTke9q+ARGATr47FWPi3W2w2/aiL1DLryEaeI8mdRNk5qKUm/g3CWvZjzkOqQt MHPYrDD5SMa1MwPHWwJvn4C/WlPJbbpBojFJqZNA/XAq4MrHXaX5d+ZtVWKGfNKYe5/8 ARnPh+BuqXeGblu1LQVNqGg+mOKk3hke96zyHsKKPzoI8rS9P9HJC7W/mTcRpB1r1bDC qDyw== X-Gm-Message-State: ACrzQf3BVlEykOZTIBZnM/ygWL6XzfbHZ5ApKu/ObLTQizxVRfGjLDZR LiiAMUasa494hfhWvFcSr+qXSTBKyWOnFQ== X-Received: by 2002:a17:902:dad2:b0:178:401c:f672 with SMTP id q18-20020a170902dad200b00178401cf672mr2570615plx.168.1663381836083; Fri, 16 Sep 2022 19:30:36 -0700 (PDT) Received: from localhost.localdomain (lily-optiplex-3070.dynamic.ucsd.edu. [2607:f720:1300:3033::1:4dd]) by smtp.googlemail.com with ESMTPSA id m8-20020a62a208000000b005386b58c8a3sm15129454pff.100.2022.09.16.19.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 19:30:35 -0700 (PDT) From: Li Zhong To: 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, Li Zhong Subject: [PATCH v1] net/ipv4/nexthop: check the return value of nexthop_find_by_id() Date: Fri, 16 Sep 2022 19:30:20 -0700 Message-Id: <20220917023020.3845137-1-floridsleeves@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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; -- 2.25.1