Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451648imw; Tue, 19 Jul 2022 06:55:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tNi8EPJvz++iyDOc81JW19fKhJhcBYHBxNswOqfUENgoC7izhpfASjqie8XUgntqdI6cAS X-Received: by 2002:a17:907:7f9e:b0:72e:d375:431 with SMTP id qk30-20020a1709077f9e00b0072ed3750431mr26887110ejc.580.1658238921292; Tue, 19 Jul 2022 06:55:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238921; cv=none; d=google.com; s=arc-20160816; b=OQ7glx/1e+YgCYF3Mt4oB7tASoTeMrhBzJCiIzMZVrg/r0nw0xMKAt53T14Wy+2eYj DpSL36+4MBw0HMFWbcN5AYSLLocQBFSdKe8E+oDk94qW0QEMZVCrrotsWfOTlz2Jae9e sbfTNVPQGxA6shetzrTjAJ57RyyKiPcqBih0zchxk8I0AAsuwJodm7GSWlMIDCG2gAm3 i0p+j2dqtm642kcRSiwt8o5cUpCKmfJZdXB2eJ2wvrVIsL6czukiDjMzrSa94nwW+OgN dWekdrFxlHKq9NT0fHVoxYJBtqPdQduLMeWQGT3glngHHCCEWLi3hmHsT3dZGTj2l4Bn uH3g== 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=AEvd2R0UIY1sN8RD/d49NMwImIdat5xxMMwESvwCogI=; b=Za6rdCLCpZK5V0uVevKL2cOw2EaL44wgVOmU3DH143iQ5lda0MGMM8Yz2GGxuTKs89 irVpkmEdqEF2+T0g4ZqclbglsDGJktExHa/9o6cNdgxrZKFqI5ejax5E7tsxIGnyyDAp 6lwKQppzUUW58y4E7dPhpSVOZVXy33TMi5vL+JpZz3aWbopOhjCZ1x1h8QYwKKyJ0gR/ q4zl557Imsf+cG62MW6O+B9ZXN0Y6j1gL7d9GAIr8eRlHJ0nv85th3XQfM/UrOiPO3lF Kvbh3h7EWF0mvzh4PxjfEXdNvCnL9jESHfKEoouBtaowy45WhGLzOmaVAERmZ+4X42vx 6ulg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KmRxTnF1; 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 g29-20020a056402321d00b0043ba40e66c9si703940eda.113.2022.07.19.06.54.56; Tue, 19 Jul 2022 06:55:21 -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=KmRxTnF1; 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 S241340AbiGSMkz (ORCPT + 99 others); Tue, 19 Jul 2022 08:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241213AbiGSMjN (ORCPT ); Tue, 19 Jul 2022 08:39:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C15E82DA8D; Tue, 19 Jul 2022 05:15:29 -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 1027260F10; Tue, 19 Jul 2022 12:15:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3106C341C6; Tue, 19 Jul 2022 12:15:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232928; bh=ptUMUYbP1ERJCm+DD853lDlnc7j+XBhZnBkNuXt1wDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KmRxTnF1pRhEhR+P/h6iOArJNJliGnx00+cVGd0uAlkrMjYEtCULlGZnq6hKLWQzO 3d7zD6c4CeCAlSu2rOx7wT+0yn8yLgsbViVs8E9sGH+sHFGxdmaXcachD8HpnPI9EI pk/wqgPfyXM7mn4kbzfvmqjhcoct51YiqzBhj6rg= 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.15 091/167] ipv4: Fix data-races around sysctl_ip_dynaddr. Date: Tue, 19 Jul 2022 13:53:43 +0200 Message-Id: <20220719114705.321690924@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@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.8 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 e49e4aff7ec19b2d0d0957ee30e93dade57dab9e ] While reading sysctl_ip_dynaddr, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- Documentation/networking/ip-sysctl.rst | 2 +- net/ipv4/af_inet.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 8d772484755a..b8b67041f955 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -1157,7 +1157,7 @@ ip_autobind_reuse - BOOLEAN option should only be set by experts. Default: 0 -ip_dynaddr - BOOLEAN +ip_dynaddr - INTEGER If set non-zero, enables support for dynamic addresses. If set to a non-zero value larger than 1, a kernel log message will be printed when dynamic address rewriting diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 77534b44b8c7..44f21278003d 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1251,7 +1251,7 @@ static int inet_sk_reselect_saddr(struct sock *sk) if (new_saddr == old_saddr) return 0; - if (sock_net(sk)->ipv4.sysctl_ip_dynaddr > 1) { + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_ip_dynaddr) > 1) { pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n", __func__, &old_saddr, &new_saddr); } @@ -1306,7 +1306,7 @@ int inet_sk_rebuild_header(struct sock *sk) * Other protocols have to map its equivalent state to TCP_SYN_SENT. * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme */ - if (!sock_net(sk)->ipv4.sysctl_ip_dynaddr || + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_ip_dynaddr) || sk->sk_state != TCP_SYN_SENT || (sk->sk_userlocks & SOCK_BINDADDR_LOCK) || (err = inet_sk_reselect_saddr(sk)) != 0) -- 2.35.1