Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4366484imw; Tue, 19 Jul 2022 05:26:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1umLkDDCQuo59v55oR+V5wY4a7sAdCe4MfBUGkN+SKeCbQzwk2DYcRViSrwx2Vd7FaeyTWR X-Received: by 2002:a05:6402:5114:b0:43a:d072:83b9 with SMTP id m20-20020a056402511400b0043ad07283b9mr44512676edd.260.1658233563174; Tue, 19 Jul 2022 05:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233563; cv=none; d=google.com; s=arc-20160816; b=ggP2avp20LM+S+b/h6ptE15osw3biMqWAoSAQ7S7MKMlTfM8YMyIiaUs9MqCahnv6n DhMx2M2mngWMOkR0qLL4OwkM2ubu5mP44hP7uHTQV+2J/v51xDmlzYo1nMN+HYoyVqCa 2gv25JjIauntyj95+iAdcrSthIMP0rGdljyJw80Ha22ZmtzUtct9NB1v42aPToXPDBFQ Nqe/fnpZG9ZsOI0M93N5lFbxlOxOjWwYYUpLoHZwqrLfq2nGZsr/fRX6yl43Mwb9JsKt nYdpGGtcMY1Y1HZogsmOXI0PumcjpUJinhN0oy0rBPiz4pqN/WjlakOFSc5JRw863kC5 ehkA== 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=7vmS9XKFb0LkxPxsFc2PKOJ91WNjYsQtdEdgw1ikMzI=; b=qSHpIjl7iTXgWK+mqCWsTil1J7Pq8hh3JF9uF2rP6obiNPUHWg8r79vEiiC3Bbz+rB /U7U1RSC+2q+8IUcT83QlwM8MsfSIb0Sy8ss1CzmXepuXWv06oJGlXhZe7F4Cpizvruf sdSQTE6kFfYEvZ3fqLExI8BKHQA4WsuFN4opb9cjyKQsXsZWkkLioMP9FM/fWw78mZPQ hpKxN2jhA4BiGP34F4I3MJfqgS3Ds4kWiuA4haZpCK1RUeCN1ekaQrvyWOZ5U1++6qee CVUyPw7fx0AaRE+IGpPt/GVH2aqoyW4YYeP7o3eBJPKy28TSOEdDo9+7ZRSJR1+H7Csz pFeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xzsD2w7g; 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 s25-20020a1709064d9900b00722e779f365si15893740eju.376.2022.07.19.05.25.37; Tue, 19 Jul 2022 05:26:03 -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=xzsD2w7g; 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 S236906AbiGSL6P (ORCPT + 99 others); Tue, 19 Jul 2022 07:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237508AbiGSL5p (ORCPT ); Tue, 19 Jul 2022 07:57:45 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8922342AF4; Tue, 19 Jul 2022 04:56:56 -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 sin.source.kernel.org (Postfix) with ESMTPS id D4B79CE1BE1; Tue, 19 Jul 2022 11:56:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9419FC341CA; Tue, 19 Jul 2022 11:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231812; bh=gO9OnIBWp/SKCtS6azBInl1vCyoNlkWu3sj9EiXLNb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xzsD2w7gzeoWecrUczKKu7NO3hBlGoQD4rQMwZdoQcBazplj66Z5efN0YAJFpeX2H V1WALYQAM34m7cmoWKK+I29auesxuNfeePOwBVXKoP4nRtEftJo9yOZs8Nuwx4C1Pe 8SMbNK3ElelOYrQ3HXHVT5R3IEMRLwDYF7+7uj4A= 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.9 11/28] ipv4: Fix data-races around sysctl_ip_dynaddr. Date: Tue, 19 Jul 2022 13:53:49 +0200 Message-Id: <20220719114457.419620991@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114455.701304968@linuxfoundation.org> References: <20220719114455.701304968@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 67dfda40b8e6..dfac66c71cb5 100644 --- a/Documentation/networking/ip-sysctl.txt +++ b/Documentation/networking/ip-sysctl.txt @@ -849,7 +849,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 8f2fb14fd4f7..970a498c1166 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1122,7 +1122,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); } @@ -1177,7 +1177,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