Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3675984pxv; Mon, 26 Jul 2021 09:11:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsPV/r5CUoUG8+LafS6ebbJ8iBOjsijvGdxoumO6okqqKH1QoqmBDCOw5BBSpr9yccAjuf X-Received: by 2002:a92:c549:: with SMTP id a9mr13549556ilj.248.1627315889927; Mon, 26 Jul 2021 09:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627315889; cv=none; d=google.com; s=arc-20160816; b=Yn6g7tyyXNjFB6amjG80r7hWTy9hy/xL94ghvdo+N0YiP+gtw6PP/Vv/OCiI2udqef 4Q4m8y3ulN8PL8bbC7L6iz9l/b/8de07HlpPF1+/e7Jrqnfzt5pwTBokFzFm7oh2gSz7 2JOoa6MSsSEmTPmFgaFhAiIo7s791UHiuqpPjYLhazJRH+Km2uVuavJGTA5dNbhxWrSQ afzHmtuZ81gGMuWC/iGtfrNYpGqF42070RAJlX7tzE01FvhJKBF7CoZSHC6Mzaau4NhW XQ/+jSYWNmaN7xq1EnBWWpU0HJr2wtPAz63X0ZapDxlLaUvcUQSPoMG/682EqfLOY8nE OuPQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AkBubyUqvPBIMmk44du+vcNe0dnKwNIUGivKqJPF0ck=; b=cRTrFfdDw2LIcaYFAXFXFvurwB/HyUzEQQrLMHsFnde3tcEBAU7lT4ikItXBdm7ZPX M+rWrOiWfkB7eaBwQ2DjL6LaK1kA2x2KA5qQTcuhHAB4zToQ/vzUS7WmO9tM+H5VWlQt ve9Fr7C+Be93lEjVfQyfvnhMvZw6/Jkk+HoxUNJZPOUtf23Hi45GR83jMARhjkjBsM0O Nfxc7FlP6SVj659qVM8UnUm3+5/O8jIQaaqKQgqGd19kh22UAN2ybev1Y5zA69IfcK+H dWOr1prlb28rpYFlMHaMqB568sYfSec7AptWI8eh92usQ09AeKnGZ5lzdAxATvUPPOoe 5s5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V0dpO85X; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si251727ilk.74.2021.07.26.09.11.14; Mon, 26 Jul 2021 09:11:29 -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=@linuxfoundation.org header.s=korg header.b=V0dpO85X; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233282AbhGZP3H (ORCPT + 99 others); Mon, 26 Jul 2021 11:29:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:56244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236127AbhGZPQg (ORCPT ); Mon, 26 Jul 2021 11:16:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8B9D160F02; Mon, 26 Jul 2021 15:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315025; bh=v2Bj5V1f/5/BtfVaui+4hou+3ngcsCnOxUNORf8hhHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V0dpO85Xg8w3aTIRjdGQ83er4fOKU+P50z6GEsHV9L0TqSLT49DjnKSG9Kup7JB6W a5iS6sAdan3RwICoeslfFABraXP94PamA1kiUzh+IcyaXKqD4WbavuqAAohX88dsFr ZtG5v5Bg/6yWEnxgOgqIBZ+6lDrURtdG7fvVIrDA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Wei Wang , Yuchung Cheng , Neal Cardwell , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 056/108] net/tcp_fastopen: fix data races around tfo_active_disable_stamp Date: Mon, 26 Jul 2021 17:38:57 +0200 Message-Id: <20210726153833.477127378@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 6f20c8adb1813467ea52c1296d52c4e95978cb2f ] tfo_active_disable_stamp is read and written locklessly. We need to annotate these accesses appropriately. Then, we need to perform the atomic_inc(tfo_active_disable_times) after the timestamp has been updated, and thus add barriers to make sure tcp_fastopen_active_should_disable() wont read a stale timestamp. Fixes: cf1ef3f0719b ("net/tcp_fastopen: Disable active side TFO in certain scenarios") Signed-off-by: Eric Dumazet Cc: Wei Wang Cc: Yuchung Cheng Cc: Neal Cardwell Acked-by: Wei Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp_fastopen.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index a9971e41f31b..8af4fefe371f 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -504,8 +504,15 @@ void tcp_fastopen_active_disable(struct sock *sk) { struct net *net = sock_net(sk); + /* Paired with READ_ONCE() in tcp_fastopen_active_should_disable() */ + WRITE_ONCE(net->ipv4.tfo_active_disable_stamp, jiffies); + + /* Paired with smp_rmb() in tcp_fastopen_active_should_disable(). + * We want net->ipv4.tfo_active_disable_stamp to be updated first. + */ + smp_mb__before_atomic(); atomic_inc(&net->ipv4.tfo_active_disable_times); - net->ipv4.tfo_active_disable_stamp = jiffies; + NET_INC_STATS(net, LINUX_MIB_TCPFASTOPENBLACKHOLE); } @@ -523,10 +530,16 @@ bool tcp_fastopen_active_should_disable(struct sock *sk) if (!tfo_da_times) return false; + /* Paired with smp_mb__before_atomic() in tcp_fastopen_active_disable() */ + smp_rmb(); + /* Limit timout to max: 2^6 * initial timeout */ multiplier = 1 << min(tfo_da_times - 1, 6); - timeout = multiplier * tfo_bh_timeout * HZ; - if (time_before(jiffies, sock_net(sk)->ipv4.tfo_active_disable_stamp + timeout)) + + /* Paired with the WRITE_ONCE() in tcp_fastopen_active_disable(). */ + timeout = READ_ONCE(sock_net(sk)->ipv4.tfo_active_disable_stamp) + + multiplier * tfo_bh_timeout * HZ; + if (time_before(jiffies, timeout)) return true; /* Mark check bit so we can check for successful active TFO -- 2.30.2