Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1550674pxa; Thu, 6 Aug 2020 10:04:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydzlN6R9x+TRXXaO1sHb1REysiKTr8rcN2xoRAMdWuNpS1GLepLS36HxyskJi6r2wHRboF X-Received: by 2002:aa7:cb0e:: with SMTP id s14mr4990880edt.349.1596733472889; Thu, 06 Aug 2020 10:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596733472; cv=none; d=google.com; s=arc-20160816; b=JnTGfrOeATTXNIu9nOkyfGO6CyQPmw8ZX1YKosicvcvgqQ7KsMvn7G7ME+XeM4Zrr4 FfpXV6rlF/izinzEkKIqHd+TCoNbr4H+xPSvT2oC/sCW5bklLtZqiuORoJtOLAut4LkD UQZKx5QpKQAZ+zebc8vmIpICOXN20etgapRVEoxBbpop8Tlq2Vv8mUtDCs1ZAgnKTnNQ 7CtQCSOnH5uBT2TJ+TFecoNe3Rovj0gOXhaK24f7gI18PZDdLgviQhwqAJsz4OnuiEoW 1IQF/JVqqM4iTFbdBUBAT55rt7AQHT4LqntAsO0e3Nr9JOLw5zkl19KpQxX9GMekNfkb DfUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wITD6sAbyjVa5WRqw37Sc/Lb0EfyweCj3P0+wea36Io=; b=Px0SOeAfNX77CctYn8ly8Z/o0k962nrbRqu3UCFcCw4NPFUBUrhQqd8m9zJ0Sj4g9/ IzzUSLdxUaG38TNT+73/9/3ZswtHvJOttek6qYltyGKND3VyGNTKbJUuqDjdwhd+id3b Gr/iOKlW0PVhbSIFwsKhEqKFXuFbQoe4ufKZktZp8tx5at8/STL6Q/6GKrYXc91soc5A tkZ8szpzZU6u7W4z2YytWaFW2KZDHCgIT1qHlL+1HGRUUVUFljOIKZTNAYFaqp27zKJl mGfr+Aesi++YC4S2WYPUcLmrl3fSvNl16MihpZP58ICzaAix59xOEY7AXgWtHJHbQcCU nNdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=msJ9eXJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v6si3520619edx.215.2020.08.06.10.04.09; Thu, 06 Aug 2020 10:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=msJ9eXJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729861AbgHFRD3 (ORCPT + 99 others); Thu, 6 Aug 2020 13:03:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729564AbgHFRB5 (ORCPT ); Thu, 6 Aug 2020 13:01:57 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC4BC034604 for ; Thu, 6 Aug 2020 05:32:12 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id jp10so23541882ejb.0 for ; Thu, 06 Aug 2020 05:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wITD6sAbyjVa5WRqw37Sc/Lb0EfyweCj3P0+wea36Io=; b=msJ9eXJ47kbGAjrgF16460tFJbqR1deSR1wZPU7U9hNgjFASv3q85xr2slEvFTf+6+ OFVC/KLvPCzDI5Qxf76YP1S7TsIxD2WlS/YUD4j0f181kF1qkAsSYk/kzrLJ9pFLNFHg gAHn6CyMn4rfYiwBHHF8VwVijPNm/sHxrWS/AmS0y5JjpvXv5sdSh4e3XF30kbZ68lHa jXBI3++7orK5KUNl2Lw7ZVMj7Srr2/GdksdFS0Dd1NAunpT+2VCFBlmu3dXmtmXDam45 RibxBrvNcGgGJ6AoFvguHJIYRy+01MDjpvXT4IFsl4uDDnTyJf7oPjXHHKZtPddY+hYF vyCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wITD6sAbyjVa5WRqw37Sc/Lb0EfyweCj3P0+wea36Io=; b=k1qzfUzZ8O3V0X9l58pMRCgT4JJdM5+MEDP+PTYcLDSWF9E7ZTblJIOqoEDZEbzZ4I rIW4KsQLFvKLSdms0wSOCQDVEBumS2gle1aacy2j6gJsGaQVWCROAteXL0EzAmMTBrMS gjNgAl9TVTDZE9OTs5EAH7FUyWe3l5RRklvUyjuVocFMru1ZoCo7urLe8XQUFi8Cxovh BbKh13ISG5pvgPf18zS+WutCLUqvDfa3UAp/iDkNSSDs+J1N7vEJXuMPckHWQGuYztY6 vu9gHhaXj29N9691ZlfUePZvEuGGyebEejPNIghC4FSPyC4SKLlLk8QX8++ZOXcrrcRf N9nA== X-Gm-Message-State: AOAM531R+wPHSrKSurnssiiF6GdkRFAtDSHatZZCBi0DPTrOeVuup/fj dhMy6m7pnq/4+37BAS8mfAuoiw== X-Received: by 2002:a17:906:f202:: with SMTP id gt2mr4056426ejb.70.1596717129751; Thu, 06 Aug 2020 05:32:09 -0700 (PDT) Received: from tim.froidcoeur.net (ptr-7tznw15pracyli75x11.18120a2.ip6.access.telenet.be. [2a02:1811:50e:f0f0:d05d:939:f42b:f575]) by smtp.gmail.com with ESMTPSA id c5sm3695778ejb.103.2020.08.06.05.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 05:32:09 -0700 (PDT) From: Tim Froidcoeur To: "David S. Miller" , Jakub Kicinski , Alexey Kuznetsov , Hideaki YOSHIFUJI , Patrick McHardy , KOVACS Krisztian Cc: Tim Froidcoeur , Matthieu Baerts , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v3 2/2] net: initialize fastreuse on inet_inherit_port Date: Thu, 6 Aug 2020 14:30:23 +0200 Message-Id: <20200806123024.585212-3-tim.froidcoeur@tessares.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200806123024.585212-1-tim.froidcoeur@tessares.net> References: <20200806123024.585212-1-tim.froidcoeur@tessares.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the case of TPROXY, bind_conflict optimizations for SO_REUSEADDR or SO_REUSEPORT are broken, possibly resulting in O(n) instead of O(1) bind behaviour or in the incorrect reuse of a bind. the kernel keeps track for each bind_bucket if all sockets in the bind_bucket support SO_REUSEADDR or SO_REUSEPORT in two fastreuse flags. These flags allow skipping the costly bind_conflict check when possible (meaning when all sockets have the proper SO_REUSE option). For every socket added to a bind_bucket, these flags need to be updated. As soon as a socket that does not support reuse is added, the flag is set to false and will never go back to true, unless the bind_bucket is deleted. Note that there is no mechanism to re-evaluate these flags when a socket is removed (this might make sense when removing a socket that would not allow reuse; this leaves room for a future patch). For this optimization to work, it is mandatory that these flags are properly initialized and updated. When a child socket is created from a listen socket in __inet_inherit_port, the TPROXY case could create a new bind bucket without properly initializing these flags, thus preventing the optimization to work. Alternatively, a socket not allowing reuse could be added to an existing bind bucket without updating the flags, causing bind_conflict to never be called as it should. Call inet_csk_update_fastreuse when __inet_inherit_port decides to create a new bind_bucket or use a different bind_bucket than the one of the listen socket. Fixes: 093d282321da ("tproxy: fix hash locking issue when using port redirection in __inet_inherit_port()") Acked-by: Matthieu Baerts Signed-off-by: Tim Froidcoeur --- net/ipv4/inet_hashtables.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 2bbaaf0c7176..006a34b18537 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -163,6 +163,7 @@ int __inet_inherit_port(const struct sock *sk, struct sock *child) return -ENOMEM; } } + inet_csk_update_fastreuse(tb, child); } inet_bind_hash(child, tb, port); spin_unlock(&head->lock); -- 2.25.1