Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4372221imw; Tue, 19 Jul 2022 05:32:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vxb1HJisaBYZ/EYYKpXil7wztquG2pxuQTXmiQP1/Vj7pw5onoP/mUbj2Rz3yXVlgeq1Vh X-Received: by 2002:a05:6402:1102:b0:43a:9cf7:68a3 with SMTP id u2-20020a056402110200b0043a9cf768a3mr44612479edv.68.1658233971303; Tue, 19 Jul 2022 05:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233971; cv=none; d=google.com; s=arc-20160816; b=rUZN2LSUo4I3ocvBhnZTAWuY6oN99nr/fNsOUdudDsHlpUy5PBSH/L1zEeMjDisOGp rO8Yf4ZbaR4ouVg9oVQAv33gDM8kWSJg3cGzyAfoBefUBJBWg/Be0PMbuMAe8OsN4T2B ET6P03kAyjX+CU5RJKwpqtS6te3xvy2Oc/YuGfJXTvSPwQVRwD9mXAIXDEvZeORcf5lE jPZ2SUPnvHhBJPc7WkhV7STENplN0+1MH8ozBI1Il830xOp12xqfWuyvKgVwz3q880Td Ii9lCkc1gp0+tnY4zxZr0wAjRAgJb+0+uPO3gvIanjAH4zX5A7iLAr3CQhmS//v7D8Nd p8ew== 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=6vm7Qzqfq4mpxlZpuUSgq7NesRTEJKINNkwRZ8RrUp4=; b=CeqtbdKAJN9SJMT6UK2B8R16lxa4p+V/zU3m64ZGpj4UIvpDkg4Dts04NU9C0Qq2ms p2sJBp75mrySTtOrk9vcFupbEGfQAmCFx8KrKhyOOEPdPx7MuDFfqQ9p4HsDkf1NYOdU GdkSRUvLGPYburNOIkXuTpxiXPEHFevBl/tvQUNT66zza65p+ABafLIqvAtbPBN6foU9 TZ/O5NAi0BYjFO66QC0nXfTdVIqZgaxtkGFTx76tLBbVWRowF/1AI3MKsLp0oKHa0a8N gg1Q1R5IxH97WIbT3mee6s9o9YlTBruyB081SgyTgzicJqltMx/qbfF8y/PxG+DeAMA3 2OUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MEQugnUt; 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 b17-20020a056402279100b00437deb23714si22805859ede.511.2022.07.19.05.32.26; Tue, 19 Jul 2022 05:32:51 -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=MEQugnUt; 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 S238304AbiGSMGV (ORCPT + 99 others); Tue, 19 Jul 2022 08:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237981AbiGSMEA (ORCPT ); Tue, 19 Jul 2022 08:04:00 -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 7B72C4BD2C; Tue, 19 Jul 2022 04:59:45 -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 0264E6163C; Tue, 19 Jul 2022 11:59:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D55B8C341C6; Tue, 19 Jul 2022 11:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231984; bh=5m/azPAvToI2gCQubBnf5EiYpONtrM6AIun8UYrg7eA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MEQugnUtTaf5vxaMhm+RZBWt0lpdWBUiIvbp2uaPsrNzG7IFDOT7yR/QhnQfg5Arm nTlxebqQ4wNcxq0rvWYQ716RE3JKIbdecn5hYQjz6UsZuvaAtc0sTsCsSDHhsSqSMq JWyZDORN+FN5xAtHTHTeBRRBvpmXpenbrqWNEyV8= 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 4.19 21/48] ipv4: Fix data-races around sysctl_ip_dynaddr. Date: Tue, 19 Jul 2022 13:53:58 +0200 Message-Id: <20220719114521.742897353@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114518.915546280@linuxfoundation.org> References: <20220719114518.915546280@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.txt | 2 +- net/ipv4/af_inet.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt index ae56957f51e4..e315e6052b9f 100644 --- a/Documentation/networking/ip-sysctl.txt +++ b/Documentation/networking/ip-sysctl.txt @@ -887,7 +887,7 @@ ip_nonlocal_bind - BOOLEAN which can be quite useful - but may break some applications. 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 d8c22246629a..dadd42a07c07 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1209,7 +1209,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); } @@ -1264,7 +1264,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