Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3697490pxv; Mon, 26 Jul 2021 09:38:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZlPXMCwxp4X5S52sA5dZTFYldPCuIfVJFx9pCnvuHnp2+WzZurXxNY5nx86Ts8jRKKpbU X-Received: by 2002:a17:906:e089:: with SMTP id gh9mr11604968ejb.80.1627317501499; Mon, 26 Jul 2021 09:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317501; cv=none; d=google.com; s=arc-20160816; b=AldeyNknJhAYQmUd9eHNN0lN8w7jwQd+AM33vZTJj8Qf+8fB2OXuwBT7G8MPqEA7td njoEMNdbJO/dSlflIn//CKQwnX/xExu3A0fhz03lZ5ifSF0YPAJfrLDwY0z3jpZayBxf /csLl9/KF3ibd1F7ShrPOndMzv0wUFxdEPw8mLrGp7jzAyCOP/Tinwohqkkw4d9aKuzG hG4snvmH8mPmqrVKDuleGjt14v/Dt/+yL2c04vzKX/hdCmh9ahZs993xUrd22Urm4aYw ONOZcHgdRv+8ceivSoh0iw/heSF0OcU9Y6iDdG4BpDe8VH5UnHsZSvUmdOihocgwpKxx 52jw== 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=5KghwH82A+BCKNMLbGmYLSRNpJp4ovKxqsXs7p0dxt4=; b=Vq2Vmk8y+OhE23RYUSLQm9FUZ3yjQZhULCGvmcX6rP+agGq/jnIbBhGcDAcEEfq4kV g1OgCNt5nNkhS8bd3sWaHJFbVAPFvVRsxhiOx58UYb8g2S/uvnx+OvxG0ymBOYUtL+2h S3eNZx/F/jmM+TyYVjQ1YET/XLslbWO0hAMSuTdu7MR3nRttNjp0kyfVtUyBStNFvbnQ wEAHraStdVeAuqjMYmyhWgA52k3t6yBQbgfsLXSz9vFOIXWTsELxGwDrS4u3bIRw0AAq MVoEzEI8m7M7uIJU6fwur+EsuZ5Dwf8oJeCqwY5CM/3eVcox5D3jZ16O8DdbYTB9naia VeEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ja0iGPY2; 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 z18si377649edc.216.2021.07.26.09.37.58; Mon, 26 Jul 2021 09:38:21 -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=ja0iGPY2; 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 S239644AbhGZPyE (ORCPT + 99 others); Mon, 26 Jul 2021 11:54:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:47948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233853AbhGZPcp (ORCPT ); Mon, 26 Jul 2021 11:32:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E7BD36056B; Mon, 26 Jul 2021 16:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315993; bh=6UZPrlVew1vjSX2qIq1Eea5jnQsUb/Gvdqafg42Ky5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ja0iGPY2CqoE4FOoAQoFCJnG7urJ3Yo6QucxId6S9PYHcAr8AS5VwaaT3HA0Rv9qd k6xAOZVCrOOWc3xnOxB6nbKmDSML5lPdR6de+0phOyaa0YSLx97/xEyzsOSjOam/BR KCOclDSy8jIr0654rD5qhDpsbn1JxgyXFhQ7GweE= 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.13 111/223] net/tcp_fastopen: fix data races around tfo_active_disable_stamp Date: Mon, 26 Jul 2021 17:38:23 +0200 Message-Id: <20210726153849.906205897@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@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 af2814c9342a..08548ff23d83 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -507,8 +507,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); } @@ -526,10 +533,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