Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp841285pxb; Thu, 17 Feb 2022 16:18:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNW3uM4ZuKuu7kViGgDvT21Em239OzVLAkXmO0N22wGQJjIWyn5hvsn9STg2Qa+7o0XYOh X-Received: by 2002:a05:6a00:2311:b0:4e1:52bf:e466 with SMTP id h17-20020a056a00231100b004e152bfe466mr5246932pfh.77.1645143515542; Thu, 17 Feb 2022 16:18:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645143515; cv=none; d=google.com; s=arc-20160816; b=guj76shQI0Yt8JKlXiBJkrxwj0jZvH0o9KTF95BgtJti5Krmr38Pl4/n8E610TWvk6 L7BL6RKeVntjwHcTI8AQf6pNOS9p7BM1rDiaUj2bmHEj/XdirjYkB29/2lLNVKQICND7 tzugm7rn7iVhj9raUnJvW7AHbBVV9+wk9ZIXpTbRvuqC5ouiKUj6hIgMv1ovUDI0+eS1 J1EW89I0k2anRlUKUvW1QR+S4P/kDPZIJCONI9wakghBxvWDe/KtrmeGwsfBGAptOeBH iQWTOaUlSAh4ZuhFeZYa7vtGgc76fBUDmeQLyGDbljIL3hThJ7Ujee5fWGZPupgUsHUq td8Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QtTQzoKh6SHELhVbK7UgiDGo5+sChsVz7qZ/mZQ4wRk=; b=g+/UowhMMLeLNtb+UTFsgpzNUste3oG7bFwT0SOuO8wLHF/XCpZr9w7xp/tP3BGVY5 TmnW5K0M8I1vuZ5b1c0rdIp2clJP9bgo4l1a0VunI8WUoxtRsv/2zNQYG616YgjkVXI0 rsN2keOfxAbz0DAVrfClfPlZOYM+lt8Xmy14FMz/WtX4RXACzpBnhHutvEmerIpBygKO AknJEAxx2VLm4F0riu7LOQFLspP+ZmZXdpooYYa83R9BwRq7qa5LKHVmhSM7v97DdAoE P5nZmcxSEj8Es1i01P8E/C5VOzcmlJKBZY+FRwjOC0TK5cjV1xChDthnuelJzHv9dRhm YTRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LfG5Bww0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id on1si2364196pjb.151.2022.02.17.16.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:18:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LfG5Bww0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 65445361B11; Thu, 17 Feb 2022 15:42:37 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244757AbiBQSuo (ORCPT + 99 others); Thu, 17 Feb 2022 13:50:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244654AbiBQSu0 (ORCPT ); Thu, 17 Feb 2022 13:50:26 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E77532D9; Thu, 17 Feb 2022 10:50:06 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id qk11so9473224ejb.2; Thu, 17 Feb 2022 10:50:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QtTQzoKh6SHELhVbK7UgiDGo5+sChsVz7qZ/mZQ4wRk=; b=LfG5Bww0Oy3sfjvyo7UZik9CTOze3VJSleCGeTzqBYFQBb7GCb81WoeNFCcwMDHAf2 6KDyRC9FbU54q681hajrooEUs1aUj1/X/WjuVoV3omcO+G34AxBIxo5VUbbH/vgctNu5 1nPnBsA8HLXrB09j1Wal4ffV2IdeaqW/EDGtqMw6CEptfUVX/9wu9p6LShOkI46d0IfV f3qb+rqVCZPlnikjHQsgKr/voCZUNSLcpsDDevv90CtSx//A6/d3IEgX3w+q0SNjp1ng d7OUNelVCif/q3zsuV5zwuSk4/D/XArrjWCtU6hHhewjLLju4BupSa/6nftUykdH73+X JYSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QtTQzoKh6SHELhVbK7UgiDGo5+sChsVz7qZ/mZQ4wRk=; b=wn0sqvOmQxI0h5noPo+XCYO52Gj+7O66j323rHL6/4f68W/mx2ECsONeQmrqgkfHpr YYHTRCYJkYfXopX70g4jKzeW/3Ag6kOgfufGkKgKdtjfP8TOMn92JBpwBOVg5sZtavwk USFwyFisy8Efj/OoErFXyrN/uU/EC8xMuf3bcwHVceQq63vwygpRsvhL2AE7R8uYCva8 9VeFJ0W1f3cD607iOPjvHHVGwhzdFIL9xxPS8FqH8AAcGX0kPdtL4+LWBQOXD+tW3YWU wnClr9WQMBekTCu8lU2RJtIBG0j6x4qufWkPl+818hxJHwwz6iU9Gp+gUlltc41zZ8Vy ZRlw== X-Gm-Message-State: AOAM530xyLyQNaDStFYAEKpaZViBoEdHdmG9A9PVLH52kb5ZnhAvMDCL q6iqQfSzOzpaIyFAgdzpOWk= X-Received: by 2002:a17:906:284b:b0:6ae:9d05:e904 with SMTP id s11-20020a170906284b00b006ae9d05e904mr3341561ejc.345.1645123804953; Thu, 17 Feb 2022 10:50:04 -0800 (PST) Received: from localhost.localdomain (dhcp-077-250-038-153.chello.nl. [77.250.38.153]) by smtp.googlemail.com with ESMTPSA id q7sm3493268edv.93.2022.02.17.10.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 10:50:04 -0800 (PST) From: Jakob Koschel To: Linus Torvalds , linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, Greg Kroah-Hartman , Thomas Gleixner , Arnd Bergman , Andy Shevchenko , Andrew Morton , Kees Cook , Mike Rapoport , "Gustavo A. R. Silva" , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [RFC PATCH 07/13] udp_tunnel: remove the usage of the list iterator after the loop Date: Thu, 17 Feb 2022 19:48:23 +0100 Message-Id: <20220217184829.1991035-8-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220217184829.1991035-1-jakobkoschel@gmail.com> References: <20220217184829.1991035-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 The usage of node->dev after the loop body is a legitimate type confusion if the break was not hit. It will compare an undefined memory location with dev that could potentially be equal. The value of node->dev in this case could either be a random struct member of the head element or an out-of-bounds value. Therefore it is more safe to use the found variable. With the introduction of speculative safe list iterator this check could be replaced with if (!node). Signed-off-by: Jakob Koschel --- net/ipv4/udp_tunnel_nic.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/ipv4/udp_tunnel_nic.c b/net/ipv4/udp_tunnel_nic.c index b91003538d87..c47f9fb36d29 100644 --- a/net/ipv4/udp_tunnel_nic.c +++ b/net/ipv4/udp_tunnel_nic.c @@ -842,11 +842,14 @@ udp_tunnel_nic_unregister(struct net_device *dev, struct udp_tunnel_nic *utn) */ if (info->shared) { struct udp_tunnel_nic_shared_node *node, *first; + bool found = false; list_for_each_entry(node, &info->shared->devices, list) - if (node->dev == dev) + if (node->dev == dev) { + found = true; break; - if (node->dev != dev) + } + if (!found) return; list_del(&node->list); -- 2.25.1