From patchwork Fri Jul 2 20:09:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12356455 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5E28C07E95 for ; Fri, 2 Jul 2021 20:09:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A4FB61402 for ; Fri, 2 Jul 2021 20:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbhGBULm (ORCPT ); Fri, 2 Jul 2021 16:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230116AbhGBULl (ORCPT ); Fri, 2 Jul 2021 16:11:41 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 020CAC061762 for ; Fri, 2 Jul 2021 13:09:08 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id mn20-20020a17090b1894b02901707fc074e8so8341854pjb.0 for ; Fri, 02 Jul 2021 13:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7hsxLPE6n9hDKQXhj6wLUqqXLVyZdJIo7vOg1HKqVME=; b=k1IVm6et8+mDTWsm55kZV8Uv5MWSNKejWXcf1Smip1J3r5s98ucQHPjZuIqSHfrwXQ XmBFNO3Fx4jdsMpd86oIqcBuXDk6YXIBNv1Yxmp4M1RNQCTn+ozNyP4KWsXVxEKLRKLZ xlKrtxgRMck0SrBKPyKB4F6vDKJ4LhNFHtXDrdQFH8iK5/y5VEtiUCGOVkS3ZnvSoAIl BdMpLx0vyTUlMS+OrfboUtlS26S7LlzkEaKiJAg0xsr1JdtZrNlVS36Pk9zaZdv/BVrV TS8/KR9omqcVzoR6OhifPE40FMW/mOxBTaeAwGEzeneiQP8zkLPxYS8ZsPXgZ63zl3K3 idWA== 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:mime-version :content-transfer-encoding; bh=7hsxLPE6n9hDKQXhj6wLUqqXLVyZdJIo7vOg1HKqVME=; b=sZfsZs03AR+2MWpe3RgdUlyBPjjjJz3jaYqSOXx2q6vdRq8lLnv666mKS8WNclszJ9 C/HR7bWrR2l0cbhLprngNEQ59tvbQg3HVqZbUMEIxCp02/NdBB9m1JAsw9XWhUjsYodK DkPMETW8rk/R3QHxERtW5zQnEseowYmTPFJFNOKziYWIBP6jY/aG8f/MR5ev9lqRDptA qaWPZhupe4Xrobnn9URTGvYpYTYoY/UYNt6OygnfDXkVvB+S57l+LG6x+w2t0oN+kp9d 4lkWHv5pqKI4VEI2KGPz+ok01TTTZCvc9j2SrfelZMB4+IdQWd5xVGgC8ikOSF9GKKa7 XKRw== X-Gm-Message-State: AOAM530TJuv+WhHAncdZRjIzRt+RCn0T1M7cpNDWi4P1aQk2wK234rW4 aJ2zF91R+heVSmG0ae2eDh6lLhsCc2E= X-Google-Smtp-Source: ABdhPJyZYm3GkwFT2c0m+090ldIMc9heOiTPgMOO5kNAA6EHiOgy8MEu2CtTb+y09qSciXR26VO1OQ== X-Received: by 2002:a17:902:aa4a:b029:10e:f98c:2b83 with SMTP id c10-20020a170902aa4ab029010ef98c2b83mr1231970plr.62.1625256547523; Fri, 02 Jul 2021 13:09:07 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:7c57:ec32:6dc8:bd6c]) by smtp.gmail.com with ESMTPSA id j205sm4653065pfd.4.2021.07.02.13.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 13:09:06 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net] tcp: annotate data races around tp->mtu_info Date: Fri, 2 Jul 2021 13:09:03 -0700 Message-Id: <20210702200903.4088572-1-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet While tp->mtu_info is read while socket is owned, the write sides happen from err handlers (tcp_v[46]_mtu_reduced) which only own the socket spinlock. Fixes: 563d34d05786 ("tcp: dont drop MTU reduction indications") Signed-off-by: Eric Dumazet --- net/ipv4/tcp_ipv4.c | 4 ++-- net/ipv6/tcp_ipv6.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index e66ad6bfe8083bfde66d24d9644abcdb649508be..b9dc2d6197be8b8b03a4d052ad1c87987c7a62aa 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -342,7 +342,7 @@ void tcp_v4_mtu_reduced(struct sock *sk) if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) return; - mtu = tcp_sk(sk)->mtu_info; + mtu = READ_ONCE(tcp_sk(sk)->mtu_info); dst = inet_csk_update_pmtu(sk, mtu); if (!dst) return; @@ -546,7 +546,7 @@ int tcp_v4_err(struct sk_buff *skb, u32 info) if (sk->sk_state == TCP_LISTEN) goto out; - tp->mtu_info = info; + WRITE_ONCE(tp->mtu_info, info); if (!sock_owned_by_user(sk)) { tcp_v4_mtu_reduced(sk); } else { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 578ab6305c3f84819bb38054acf1e62c00a9061e..593c32fe57ed13a218492fd6056f2593e601ec79 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -352,7 +352,7 @@ static void tcp_v6_mtu_reduced(struct sock *sk) if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) return; - dst = inet6_csk_update_pmtu(sk, tcp_sk(sk)->mtu_info); + dst = inet6_csk_update_pmtu(sk, READ_ONCE(tcp_sk(sk)->mtu_info)); if (!dst) return; @@ -443,7 +443,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, if (!ip6_sk_accept_pmtu(sk)) goto out; - tp->mtu_info = ntohl(info); + WRITE_ONCE(tp->mtu_info, ntohl(info)); if (!sock_owned_by_user(sk)) tcp_v6_mtu_reduced(sk); else if (!test_and_set_bit(TCP_MTU_REDUCED_DEFERRED,