From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v1 net 01/15] ip: Fix data-races around sysctl_ip_default_ttl.
Date: Wed, 13 Jul 2022 13:51:51 -0700 [thread overview]
Message-ID: <20220713205205.15735-2-kuniyu@amazon.com> (raw)
In-Reply-To: <20220713205205.15735-1-kuniyu@amazon.com>
While reading sysctl_ip_default_ttl, 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 <kuniyu@amazon.com>
---
drivers/net/ethernet/netronome/nfp/flower/action.c | 2 +-
include/net/route.h | 2 +-
net/ipv4/ip_sockglue.c | 2 +-
net/ipv4/netfilter/nf_reject_ipv4.c | 4 ++--
net/ipv4/proc.c | 2 +-
net/netfilter/nf_synproxy_core.c | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c b/drivers/net/ethernet/netronome/nfp/flower/action.c
index 0147de405365..ffb6f6d05a07 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/action.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/action.c
@@ -474,7 +474,7 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun,
set_tun->ttl = ip4_dst_hoplimit(&rt->dst);
ip_rt_put(rt);
} else {
- set_tun->ttl = net->ipv4.sysctl_ip_default_ttl;
+ set_tun->ttl = READ_ONCE(net->ipv4.sysctl_ip_default_ttl);
}
}
diff --git a/include/net/route.h b/include/net/route.h
index 991a3985712d..bbcf2aba149f 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -373,7 +373,7 @@ static inline int ip4_dst_hoplimit(const struct dst_entry *dst)
struct net *net = dev_net(dst->dev);
if (hoplimit == 0)
- hoplimit = net->ipv4.sysctl_ip_default_ttl;
+ hoplimit = READ_ONCE(net->ipv4.sysctl_ip_default_ttl);
return hoplimit;
}
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 445a9ecaefa1..d497d525dea3 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -1606,7 +1606,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
{
struct net *net = sock_net(sk);
val = (inet->uc_ttl == -1 ?
- net->ipv4.sysctl_ip_default_ttl :
+ READ_ONCE(net->ipv4.sysctl_ip_default_ttl) :
inet->uc_ttl);
break;
}
diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
index 918c61fda0f3..d640adcaf1b1 100644
--- a/net/ipv4/netfilter/nf_reject_ipv4.c
+++ b/net/ipv4/netfilter/nf_reject_ipv4.c
@@ -62,7 +62,7 @@ struct sk_buff *nf_reject_skb_v4_tcp_reset(struct net *net,
skb_reserve(nskb, LL_MAX_HEADER);
niph = nf_reject_iphdr_put(nskb, oldskb, IPPROTO_TCP,
- net->ipv4.sysctl_ip_default_ttl);
+ READ_ONCE(net->ipv4.sysctl_ip_default_ttl));
nf_reject_ip_tcphdr_put(nskb, oldskb, oth);
niph->tot_len = htons(nskb->len);
ip_send_check(niph);
@@ -117,7 +117,7 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net,
skb_reserve(nskb, LL_MAX_HEADER);
niph = nf_reject_iphdr_put(nskb, oldskb, IPPROTO_ICMP,
- net->ipv4.sysctl_ip_default_ttl);
+ READ_ONCE(net->ipv4.sysctl_ip_default_ttl));
skb_reset_transport_header(nskb);
icmph = skb_put_zero(nskb, sizeof(struct icmphdr));
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index 28836071f0a6..0088a4c64d77 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -387,7 +387,7 @@ static int snmp_seq_show_ipstats(struct seq_file *seq, void *v)
seq_printf(seq, "\nIp: %d %d",
IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2,
- net->ipv4.sysctl_ip_default_ttl);
+ READ_ONCE(net->ipv4.sysctl_ip_default_ttl));
BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) != 0);
snmp_get_cpu_field64_batch(buff64, snmp4_ipstats_list,
diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index e479dd0561c5..16915f8eef2b 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -405,7 +405,7 @@ synproxy_build_ip(struct net *net, struct sk_buff *skb, __be32 saddr,
iph->tos = 0;
iph->id = 0;
iph->frag_off = htons(IP_DF);
- iph->ttl = net->ipv4.sysctl_ip_default_ttl;
+ iph->ttl = READ_ONCE(net->ipv4.sysctl_ip_default_ttl);
iph->protocol = IPPROTO_TCP;
iph->check = 0;
iph->saddr = saddr;
--
2.30.2
next prev parent reply other threads:[~2022-07-13 20:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-13 20:51 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 2) Kuniyuki Iwashima
2022-07-13 20:51 ` Kuniyuki Iwashima [this message]
2022-07-13 20:51 ` [PATCH v1 net 02/15] ip: Fix data-races around sysctl_ip_no_pmtu_disc Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 03/15] ip: Fix data-races around sysctl_ip_fwd_use_pmtu Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 04/15] ip: Fix data-races around sysctl_ip_fwd_update_priority Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 05/15] ip: Fix data-races around sysctl_ip_nonlocal_bind Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 06/15] ip: Fix a data-race around sysctl_ip_autobind_reuse Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 07/15] ip: Fix a data-race around sysctl_fwmark_reflect Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 08/15] tcp/dccp: Fix a data-race around sysctl_tcp_fwmark_accept Kuniyuki Iwashima
2022-07-13 20:51 ` [PATCH v1 net 09/15] tcp: Fix data-races around sysctl_tcp_l3mdev_accept Kuniyuki Iwashima
2022-07-13 20:52 ` [PATCH v1 net 10/15] tcp: Fix data-races around sysctl_tcp_mtu_probing Kuniyuki Iwashima
2022-07-13 20:52 ` [PATCH v1 net 11/15] tcp: Fix data-races around sysctl_tcp_base_mss Kuniyuki Iwashima
2022-07-13 20:52 ` [PATCH v1 net 12/15] tcp: Fix data-races around sysctl_tcp_min_snd_mss Kuniyuki Iwashima
2022-07-13 20:52 ` [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_mtu_probe_floor Kuniyuki Iwashima
2022-07-13 20:52 ` [PATCH v1 net 14/15] tcp: Fix a data-race around sysctl_tcp_probe_threshold Kuniyuki Iwashima
2022-07-13 20:52 ` [PATCH v1 net 15/15] tcp: Fix a data-race around sysctl_tcp_probe_interval Kuniyuki Iwashima
2022-07-15 11:00 ` [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 2) patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220713205205.15735-2-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).