Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp481194imn; Wed, 27 Jul 2022 11:24:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tlI1Hoco8GPHxfOcAa9hxnRMRT3SSzHNmuQQAH1nSHLa1l53PBiKBQPZj5TcYAUKr7uf6O X-Received: by 2002:a05:6402:4144:b0:431:6ef0:bef7 with SMTP id x4-20020a056402414400b004316ef0bef7mr23922132eda.151.1658946255641; Wed, 27 Jul 2022 11:24:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946255; cv=none; d=google.com; s=arc-20160816; b=aNnXPBZLOsxkie0X+tZrPq2qiEmHDM0irPnD1Q1XYWBIWp8Isf613XOr6Mf3ctR552 /EnU3O1gY3HyRMNn6ffe/khJy8yWUmY+NfLG2yiT+ttoaK+WQoi067R90ujnqvQtAnmp fcSRwp5+abvKugJ5fsT9N8IWYzQRsHQg9mk1qMxw6ojclLpyfSljgWEsip3plAQ/k1TR R8+N9On1rHYP9ZK90jW7zngyCXyWYyt3fZthRtOo+phbms0rfP5B6X6DfzKwacNJhs8n 6WUzpBhJRW/H2hrufbkhzlA7EWx075cocTaphIy9m6qLMs1cNNGstPpU7tbGC+jKxbvQ ZX2w== 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=KGXML0pMatpyz0YcPwh0cifkhM3Tx90MGQT18CQWm6s=; b=xfLWAtwnSJNY6xQqvtVEc9EjDOv9b4ppAegSb9rikU1uzDoXey2ViJ0aZLLKqQFXh3 BHTrbfNQmi90Gd2GAwRq89BeAk3Pe1BJQqeA4l/2JbGQaWJwOK3MSwVl9f7eHOMOqss1 nvHzVS3jYIOl1kjiqP2Pt26twkumwqqHv7zIgaXQEaF4NWNW6yK3nI2dOIqjR2Lm8fX9 dPtaDV71GTI6GOok0KLzFRlu9epLmwsvBEYGuFBtK6zM2OwtRHbITIPyQA5SSlqpikbG yqk3L4eND6Onk/f0nOxue01rNnj3Ogne6L2nYx307l747Nqj1nCb7o0ApoZwIBLiM/Jc wAxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hEMKTy94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020a50998a000000b0043b52adbf6esi5725798edb.557.2022.07.27.11.23.50; Wed, 27 Jul 2022 11:24:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hEMKTy94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240760AbiG0Qwe (ORCPT + 99 others); Wed, 27 Jul 2022 12:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240804AbiG0QwF (ORCPT ); Wed, 27 Jul 2022 12:52:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5066454656; Wed, 27 Jul 2022 09:33:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E147B61A73; Wed, 27 Jul 2022 16:33:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E885DC433D6; Wed, 27 Jul 2022 16:33:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939632; bh=Vtrb3hA6GkN7VLsNOm4H7j5c2K8Sro92wFOX7ixBafA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEMKTy94Goaj3Png2da0C0zVT9pgHt5cq3edKKpFhItysiex+vmjWA8gqJxiE4nyX KKL6hJ+5ABp3H6hFeMPIXjvUiLefs8ova4t5plBwB7U4s+wj1iDhHFyx1v+XOXia4k jZLr+zI7ywWFxO/9d7XN1PKbJCfuBimWu7X6yEJc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 048/105] tcp: Fix data-races around keepalive sysctl knobs. Date: Wed, 27 Jul 2022 18:10:34 +0200 Message-Id: <20220727161013.995516807@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161012.056867467@linuxfoundation.org> References: <20220727161012.056867467@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima [ Upstream commit f2f316e287e6c2e3a1c5bab8d9b77ee03daa0463 ] While reading sysctl_tcp_keepalive_(time|probes|intvl), they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/tcp.h | 9 ++++++--- net/smc/smc_llc.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 2a28e0925573..9ef9fd0677b5 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1447,21 +1447,24 @@ static inline int keepalive_intvl_when(const struct tcp_sock *tp) { struct net *net = sock_net((struct sock *)tp); - return tp->keepalive_intvl ? : net->ipv4.sysctl_tcp_keepalive_intvl; + return tp->keepalive_intvl ? : + READ_ONCE(net->ipv4.sysctl_tcp_keepalive_intvl); } static inline int keepalive_time_when(const struct tcp_sock *tp) { struct net *net = sock_net((struct sock *)tp); - return tp->keepalive_time ? : net->ipv4.sysctl_tcp_keepalive_time; + return tp->keepalive_time ? : + READ_ONCE(net->ipv4.sysctl_tcp_keepalive_time); } static inline int keepalive_probes(const struct tcp_sock *tp) { struct net *net = sock_net((struct sock *)tp); - return tp->keepalive_probes ? : net->ipv4.sysctl_tcp_keepalive_probes; + return tp->keepalive_probes ? : + READ_ONCE(net->ipv4.sysctl_tcp_keepalive_probes); } static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp) diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c index ee1f0fdba085..0ef15f8fba90 100644 --- a/net/smc/smc_llc.c +++ b/net/smc/smc_llc.c @@ -1787,7 +1787,7 @@ void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc) init_waitqueue_head(&lgr->llc_flow_waiter); init_waitqueue_head(&lgr->llc_msg_waiter); mutex_init(&lgr->llc_conf_mutex); - lgr->llc_testlink_time = net->ipv4.sysctl_tcp_keepalive_time; + lgr->llc_testlink_time = READ_ONCE(net->ipv4.sysctl_tcp_keepalive_time); } /* called after lgr was removed from lgr_list */ -- 2.35.1