Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp891441pxb; Thu, 15 Apr 2021 08:54:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk01z8geG/y+dEOxEZr5jXt6mOHW6DRfhNi4UdfQbTQlVJiDuaQI5itDQOc7HETpGG7pBu X-Received: by 2002:a62:db43:0:b029:244:3c4c:6b90 with SMTP id f64-20020a62db430000b02902443c4c6b90mr3814675pfg.59.1618502075560; Thu, 15 Apr 2021 08:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618502075; cv=none; d=google.com; s=arc-20160816; b=dc3ofkOc0nqiagO+ZGMX8OTGievTjZ8P0Z41I8+tuvlplXsUSXKGbUWGSaAr59H3eV +Mgu7HL6OoSDsVAc5anwyuHB7/gKUJqVBq4/STUbKzWNYyFFn52y4RYg6w07OaekJed8 k3O6xexYnvwdDypdXEBx8ccrcFaq3c5r/9J3yc+fXfP8EsY2EaJKtWhAG4Wdg4Mi2kdi 8yySqKwpdIafgj954fZHW1j/nV3no6akguIlS+DAdt9qn5THul9Ud58AZBq3uUm7GvN+ mVKm4IcFCM2LRpmCjIBy5Z7Gek8AQtujMP8SsU0ey8lP+g60jz1bm+/bRt0g19jQgY44 i40w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=F9TuoPKL8IRzmmWmBzazLUtdnRWucaC/+xmjl6G5cBA=; b=G9fXCkVay/zi0uMCJCn+p+UcFhxzQBzSO72xz+tnNsnZVHG6Pu/7reMu7IiUgq1FpH khTY8H18TzpNRq+UsLEkiwlnpPCmNetQCabuHO6Hw/0fx5/0nnFJQltoORpmZSc5KZPC HMeEtzPTk0k7ODY1L0RWwF6mvGdUm6IZfR1uKlVnSrHfopTUymSbec/bg4X0GPyXRegX iV9SpRiDX+gwJ67YbmH7q7lm21SfTtsjce5uTy8ef0d7G4/MGqONxzw+fc0nMJuGWJk1 oocB4ZULXdJx6VVKDGWFf+NOdqCaqzhyYm5+H/28qkVJn56d+fDQvtzPM+i4tp4jPB1Y JKOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cKW8yX6v; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w18si3621997plq.286.2021.04.15.08.54.23; Thu, 15 Apr 2021 08:54:35 -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=@google.com header.s=20161025 header.b=cKW8yX6v; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233835AbhDOPx7 (ORCPT + 99 others); Thu, 15 Apr 2021 11:53:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233772AbhDOPx5 (ORCPT ); Thu, 15 Apr 2021 11:53:57 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ED9CC061756 for ; Thu, 15 Apr 2021 08:53:33 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id x8so21529970ybx.2 for ; Thu, 15 Apr 2021 08:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=F9TuoPKL8IRzmmWmBzazLUtdnRWucaC/+xmjl6G5cBA=; b=cKW8yX6vsGEJwivjF201Y+85frWjALXhCEZ5pki1xv7haWooMSh4XOTKxd6iMY7vyQ QnJPJlF+BGsfj9VBqQSNkjGB1VK4oSsc6YEdSJj9Xe1EpbeGHMtJZSg0hL0RXpHT0SMN KJZROGIDTtvaUGhVvA/sMVUdoT+4at0sOqc/PVNwnX4dOYzdyR69fCWn/+4DwWbh6IsW gjEVLT8rIyKI6L/2oLgrtP9QexfDmrX+EzHZ7ox9UxH7/M1Otts4Mkcc2qhXOpsRUXTu ivY1YKYivJfnz4eCpudiJn/wZFSDAFpSNzlSGVW51+D0KKHesoUp4MHl0a1tTyZwfCCq htbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=F9TuoPKL8IRzmmWmBzazLUtdnRWucaC/+xmjl6G5cBA=; b=hW4+tBWGUyYt8udg/vZAxjcq41tgb/n0MgB0fbiG0G/L4KiidfJNxD8y/jPDcRV2zF bZPurIojroCrVH+k7ZCwbMLYZEvXkK/T8PgINCsvbwfuX0dlEdLaCqSt3uGQ9R9u9nEx dKi3mDdwmoHogy3+ua00HvFlq7MizByWWoSXYBxbHbSpUlr0aPl53Xj+6WtkyvR8CgYo nORdvEuTxVjtEw7S8dirQJ435PBmEl/lBRhC4u7KRr8giieyEevR1i/PjtrG2QpFovaw 5ojThxKyc+VAbtCAHF7y3WihUIzTlXxRZL1gWYzdnQNKkexpO6YRZWK9v3Gshm35UVTO BJAA== X-Gm-Message-State: AOAM5320KakyjUF117OGvyfXTA61TFPfEnmZB1bZB2N6mFzqWhbuESVk 3uZtESi804ieOul0mP65eLt+iiJ9Q0ELvAA4Q25tbVYIb3A= X-Received: by 2002:a25:b906:: with SMTP id x6mr5196823ybj.504.1618502012217; Thu, 15 Apr 2021 08:53:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Eric Dumazet Date: Thu, 15 Apr 2021 17:53:20 +0200 Message-ID: Subject: Re: [PROBLEM] a data race between tcp_set_default_congestion_control() and tcp_set_congestion_control() To: "Gong, Sishuai" Cc: "davem@davemloft.net" , "yoshfuji@linux-ipv6.org" , "dsahern@kernel.org" , "kuba@kernel.org" , Linux Kernel Network Developers , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 5:47 PM Gong, Sishuai wrote: > > Hi, > > We found a data race between tcp_set_default_congestion_control() and tcp= _set_congestion_control() in linux-5.12-rc3. > In general, when tcp_set_congestion_control() is reading ca->flags with a= lock grabbed, tcp_set_default_congestion_control() > may be updating ca->flags at the same time, as shown below. > > When the writer and reader are running parallel, tcp_set_congestion_contr= ol()=E2=80=99s control flow > might be non-deterministic, either returning a -EPERM or calling tcp_rein= it_congestion_control(). > > We also notice in tcp_set_allowed_congestion_control(), the write to ca->= flags is protected by tcp_cong_list_lock, > so we want to point it out in case the data race is unexpected. > > Thread 1 Thread 2 > //tcp_set_default_congestion_control() //tcp_set_congestion_control() > // lock_s= ock() grabbed > if (!((ca= ->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin)) > e= rr =3D -EPERM; > else if (= !bpf_try_module_get(ca, ca->owner)) > e= rr =3D -EBUSY; > else > t= cp_reinit_congestion_control(sk, ca); > ca->flags |=3D TCP_CONG_NON_RESTRICTED; > > > > Thanks, > Sishuai > Yes, obviously reading ca->flags while another thread might set the bit is = racy. This is of no consequence, if you want to silence KCSAN please a patch.