sysctl: Fix data-races around ipv4_net_table (Round 3).
Subsystems (9)
cover sysctl: Fix data-races around ipv4_net_table (Round 3).
This series fixes data-races around 21 knobs after igmp_link_local_mcast_reports in ipv4_net_table.
These 4 knobs are skipped because they are safe.
- tcp_congestion_control: Safe with RCU and xchg().
- tcp_available_congestion_control: Read only.
- tcp_allowed_congestion_control: Safe with RCU and spinlock().
- tcp_fastopen_key: Safe with RCU and xchg()
So, round 4 will start with fib_multipath_use_neigh.
Kuniyuki Iwashima (15):
igmp: Fix data-races around sysctl_igmp_llm_reports.
igmp: Fix a data-race around sysctl_igmp_max_memberships.
igmp: Fix data-races around sysctl_igmp_max_msf.
igmp: Fix data-races around sysctl_igmp_qrv.
tcp: Fix data-races around keepalive sysctl knobs.
tcp: Fix data-races around sysctl_tcp_syn(ack)?_retries.
tcp: Fix data-races around sysctl_tcp_syncookies.
tcp: Fix data-races around sysctl_tcp_migrate_req.
tcp: Fix data-races around sysctl_tcp_reordering.
tcp: Fix data-races around some timeout sysctl knobs.
tcp: Fix a data-race around sysctl_tcp_notsent_lowat.
tcp: Fix a data-race around sysctl_tcp_tw_reuse.
tcp: Fix data-races around sysctl_max_syn_backlog.
tcp: Fix data-races around sysctl_tcp_fastopen.
tcp: Fix data-races around sysctl_tcp_fastopen_blackhole_timeout.
drivers/net/amt.c | 4 +-- include/net/tcp.h | 14 ++++++---- net/core/filter.c | 4 +-- net/core/sock_reuseport.c | 4 +-- net/ipv4/af_inet.c | 2 +- net/ipv4/igmp.c | 49 +++++++++++++++++++-------------- net/ipv4/inet_connection_sock.c | 3 +- net/ipv4/ip_sockglue.c | 6 ++-- net/ipv4/syncookies.c | 3 +- net/ipv4/tcp.c | 13 +++++---- net/ipv4/tcp_fastopen.c | 9 +++--- net/ipv4/tcp_input.c | 36 +++++++++++++++--------- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_metrics.c | 3 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 20 ++++++++------ net/ipv6/syncookies.c | 3 +- net/smc/smc_llc.c | 2 +- 18 files changed, 106 insertions(+), 73 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/15 igmp: Fix data-races around sysctl_igmp_llm_reports.
While reading sysctl_igmp_llm_reports, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
This test can be packed into a helper, so such changes will be in the follow-up series after net is merged into net-next.
if (ipv4_is_local_multicast(pmc->multiaddr) &&
!READ_ONCE(net->ipv4.sysctl_igmp_llm_reports))
---
CC: Philip Downey <[email protected]>
--- net/ipv4/igmp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
net/ipv4/igmp.c +13 -8
@@ -467,7 +467,8 @@ static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,if (pmc->multiaddr ==IGMP_ALL_HOSTS )return skb; -if (ipv4_is_local_multicast (pmc->multiaddr) && !net->ipv4.sysctl_igmp_llm_reports) +if (ipv4_is_local_multicast (pmc->multiaddr) && + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))return skb; mtu =READ_ONCE (dev->mtu);
@@ -593,7 +594,7 @@ static int igmpv3_send_report(struct in_device *in_dev, struct ip_mc_list *pmc)if (pmc->multiaddr ==IGMP_ALL_HOSTS )continue ;if (ipv4_is_local_multicast (pmc->multiaddr) && - !net->ipv4.sysctl_igmp_llm_reports) + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))continue ;spin_lock_bh (&pmc->lock);if (pmc->sfcount[MCAST_EXCLUDE ])
@@ -736,7 +737,8 @@ static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc,if (type ==IGMPV3_HOST_MEMBERSHIP_REPORT )return igmpv3_send_report (in_dev, pmc); -if (ipv4_is_local_multicast (group) && !net->ipv4.sysctl_igmp_llm_reports) +if (ipv4_is_local_multicast (group) && + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))return 0 ;if (type ==IGMP_HOST_LEAVE_MESSAGE )
@@ -920,7 +922,8 @@ static bool igmp_heard_report(struct in_device *in_dev, __be32 group)if (group ==IGMP_ALL_HOSTS )return false; -if (ipv4_is_local_multicast (group) && !net->ipv4.sysctl_igmp_llm_reports) +if (ipv4_is_local_multicast (group) && + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))return false;rcu_read_lock ();
@@ -1045,7 +1048,7 @@ static bool igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,if (im->multiaddr ==IGMP_ALL_HOSTS )continue ;if (ipv4_is_local_multicast (im->multiaddr) && - !net->ipv4.sysctl_igmp_llm_reports) + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))continue ;spin_lock_bh (&im->lock);if (im->tm_running)
@@ -1296,7 +1299,8 @@ static void __igmp_group_dropped(struct ip_mc_list *im, gfp_t gfp)#ifdef CONFIG_IP_MULTICAST if (im->multiaddr ==IGMP_ALL_HOSTS )return ; -if (ipv4_is_local_multicast (im->multiaddr) && !net->ipv4.sysctl_igmp_llm_reports) +if (ipv4_is_local_multicast (im->multiaddr) && + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))return ; reporter = im->reporter;
@@ -1338,7 +1342,8 @@ static void igmp_group_added(struct ip_mc_list *im)#ifdef CONFIG_IP_MULTICAST if (im->multiaddr ==IGMP_ALL_HOSTS )return ; -if (ipv4_is_local_multicast (im->multiaddr) && !net->ipv4.sysctl_igmp_llm_reports) +if (ipv4_is_local_multicast (im->multiaddr) && + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))return ;if (in_dev->dead)
@@ -1642,7 +1647,7 @@ static void ip_mc_rejoin_groups(struct in_device *in_dev)if (im->multiaddr ==IGMP_ALL_HOSTS )continue ;if (ipv4_is_local_multicast (im->multiaddr) && - !net->ipv4.sysctl_igmp_llm_reports) + !READ_ONCE (net->ipv4.sysctl_igmp_llm_reports))continue ;/* a failover is happening and switches
Signature · 1 line
2.30.2
PATCH 2/15 igmp: Fix a data-race around sysctl_igmp_max_memberships.
In reply to Kuniyuki IwashimaWhile reading sysctl_igmp_max_memberships, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/igmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/igmp.c +1 -1
@@ -2197,7 +2197,7 @@ static int __ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr, count++; } err = -ENOBUFS ; -if (count >= net->ipv4.sysctl_igmp_max_memberships) +if (count >=READ_ONCE (net->ipv4.sysctl_igmp_max_memberships)) goto done; iml =sock_kmalloc (sk,sizeof (*iml),GFP_KERNEL );if (!iml)
Signature · 1 line
2.30.2
PATCH 3/15 igmp: Fix data-races around sysctl_igmp_max_msf.
In reply to Kuniyuki IwashimaWhile reading sysctl_igmp_max_msf, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/ipv4/igmp.c | 2 +- net/ipv4/ip_sockglue.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
net/ipv4/igmp.c +1 -1
@@ -2384,7 +2384,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct }/* else, add a new source to the filter */ -if (psl && psl->sl_count >= net->ipv4.sysctl_igmp_max_msf) { +if (psl && psl->sl_count >=READ_ONCE (net->ipv4.sysctl_igmp_max_msf)) { err = -ENOBUFS ; goto done; }
net/ipv4/ip_sockglue.c +3 -3
@@ -782,7 +782,7 @@ static int ip_set_mcast_msfilter(struct sock *sk, sockptr_t optval, int optlen)/* numsrc >= (4G-140)/128 overflow in 32 bits */ err = -ENOBUFS ;if (gsf->gf_numsrc >=0x1ffffff || - gsf->gf_numsrc >sock_net (sk)->ipv4.sysctl_igmp_max_msf) + gsf->gf_numsrc >READ_ONCE (sock_net (sk)->ipv4.sysctl_igmp_max_msf)) goto out_free_gsf; err = -EINVAL ;
@@ -832,7 +832,7 @@ static int compat_ip_set_mcast_msfilter(struct sock *sk, sockptr_t optval,/* numsrc >= (4G-140)/128 overflow in 32 bits */ err = -ENOBUFS ; -if (n >sock_net (sk)->ipv4.sysctl_igmp_max_msf) +if (n >READ_ONCE (sock_net (sk)->ipv4.sysctl_igmp_max_msf)) goto out_free_gsf; err =set_mcast_msfilter (sk, gf32->gf_interface, n, gf32->gf_fmode, &gf32->gf_group, gf32->gf_slist_flex);
@@ -1244,7 +1244,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, int optname, }/* numsrc >= (1G-4) overflow in 32 bits */ if (msf->imsf_numsrc >=0x3ffffffcU || - msf->imsf_numsrc > net->ipv4.sysctl_igmp_max_msf) { + msf->imsf_numsrc >READ_ONCE (net->ipv4.sysctl_igmp_max_msf)) {kfree (msf); err = -ENOBUFS ;break ;
Signature · 1 line
2.30.2
PATCH 4/15 igmp: Fix data-races around sysctl_igmp_qrv.
In reply to Kuniyuki IwashimaWhile reading sysctl_igmp_qrv, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
This test can be packed into a helper, so such changes will be in the follow-up series after net is merged into net-next.
qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv);
---
CC: Hannes Frederic Sowa <[email protected]>
--- drivers/net/amt.c | 4 ++-- net/ipv4/igmp.c | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/net/amt.c +2 -2
@@ -563,7 +563,7 @@ static struct sk_buff *amt_build_igmp_gq(struct amt_dev *amt) ihv3->nsrcs =0 ; ihv3->resv =0 ; ihv3->suppress = false; - ihv3->qrv = amt->net->ipv4.sysctl_igmp_qrv; + ihv3->qrv =READ_ONCE (amt->net->ipv4.sysctl_igmp_qrv); ihv3->csum =0 ; csum = &ihv3->csum; csum_start = (void *)ihv3;
@@ -3095,7 +3095,7 @@ static int amt_newlink(struct net *net, struct net_device *dev, goto err; }if (amt->mode ==AMT_MODE_RELAY ) { - amt->qrv = amt->net->ipv4.sysctl_igmp_qrv; + amt->qrv =READ_ONCE (amt->net->ipv4.sysctl_igmp_qrv); amt->qri =10 ; dev->needed_headroom = amt->stream_dev->needed_headroom +AMT_RELAY_HLEN ;
net/ipv4/igmp.c +13 -11
@@ -827,7 +827,7 @@ static void igmp_ifc_event(struct in_device *in_dev)struct net *net =dev_net (in_dev->dev);if (IGMP_V1_SEEN (in_dev) ||IGMP_V2_SEEN (in_dev))return ; -WRITE_ONCE (in_dev->mr_ifc_count, in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv); +WRITE_ONCE (in_dev->mr_ifc_count, in_dev->mr_qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv));igmp_ifc_start_timer (in_dev,1 ); }
@@ -1009,7 +1009,7 @@ static bool igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,* received value was zero, use the default or statically * configured value. */ - in_dev->mr_qrv = ih3->qrv ?: net->ipv4.sysctl_igmp_qrv; + in_dev->mr_qrv = ih3->qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv); in_dev->mr_qi =IGMPV3_QQIC (ih3->qqic)*HZ ?:IGMP_QUERY_INTERVAL ;/* RFC3376, 8.3. Query Response Interval:
@@ -1189,7 +1189,7 @@ static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im, pmc->interface = im->interface;in_dev_hold (in_dev); pmc->multiaddr = im->multiaddr; - pmc->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + pmc->crcount = in_dev->mr_qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv); pmc->sfmode = im->sfmode;if (pmc->sfmode ==MCAST_INCLUDE ) {struct ip_sf_list *psf;
@@ -1240,9 +1240,11 @@ static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im)swap (im->tomb, pmc->tomb);swap (im->sources, pmc->sources);for (psf = im->sources; psf; psf = psf->sf_next) - psf->sf_crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + psf->sf_crcount = in_dev->mr_qrv ?: +READ_ONCE (net->ipv4.sysctl_igmp_qrv); }else { - im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + im->crcount = in_dev->mr_qrv ?: +READ_ONCE (net->ipv4.sysctl_igmp_qrv); }in_dev_put (pmc->interface);kfree_pmc (pmc);
@@ -1349,7 +1351,7 @@ static void igmp_group_added(struct ip_mc_list *im)if (in_dev->dead)return ; - im->unsolicit_count = net->ipv4.sysctl_igmp_qrv; + im->unsolicit_count =READ_ONCE (net->ipv4.sysctl_igmp_qrv);if (IGMP_V1_SEEN (in_dev) ||IGMP_V2_SEEN (in_dev)) {spin_lock_bh (&im->lock);igmp_start_timer (im,IGMP_INITIAL_REPORT_DELAY );
@@ -1363,7 +1365,7 @@ static void igmp_group_added(struct ip_mc_list *im)* IN() to IN(A). */ if (im->sfmode ==MCAST_EXCLUDE ) - im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + im->crcount = in_dev->mr_qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv);igmp_ifc_event (in_dev);#endif
@@ -1754,7 +1756,7 @@ static void ip_mc_reset(struct in_device *in_dev) in_dev->mr_qi =IGMP_QUERY_INTERVAL ; in_dev->mr_qri =IGMP_QUERY_RESPONSE_INTERVAL ; - in_dev->mr_qrv = net->ipv4.sysctl_igmp_qrv; + in_dev->mr_qrv = READ_ONCE(net->ipv4.sysctl_igmp_qrv); }#else static void ip_mc_reset (struct in_device *in_dev)
@@ -1888,7 +1890,7 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,#ifdef CONFIG_IP_MULTICAST if (psf->sf_oldin && !IGMP_V1_SEEN (in_dev) && !IGMP_V2_SEEN (in_dev)) { - psf->sf_crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + psf->sf_crcount = in_dev->mr_qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv); psf->sf_next = pmc->tomb; pmc->tomb = psf; rv =1 ;
@@ -1952,7 +1954,7 @@ static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode,/* filter mode change */ pmc->sfmode =MCAST_INCLUDE ;#ifdef CONFIG_IP_MULTICAST - pmc->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + pmc->crcount = in_dev->mr_qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv);WRITE_ONCE (in_dev->mr_ifc_count, pmc->crcount);for (psf = pmc->sources; psf; psf = psf->sf_next) psf->sf_crcount =0 ;
@@ -2131,7 +2133,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,#ifdef CONFIG_IP_MULTICAST /* else no filters; keep old mode for reports */ - pmc->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; + pmc->crcount = in_dev->mr_qrv ?:READ_ONCE (net->ipv4.sysctl_igmp_qrv);WRITE_ONCE (in_dev->mr_ifc_count, pmc->crcount);for (psf = pmc->sources; psf; psf = psf->sf_next) psf->sf_crcount =0 ;
Signature · 1 line
2.30.2
PATCH 5/15 tcp: Fix data-races around keepalive sysctl knobs.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_keepalive_(time|probes|intvl), they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers.
--- include/net/tcp.h | 9 ++++++--- net/smc/smc_llc.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-)
include/net/tcp.h +6 -3
@@ -1493,21 +1493,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)
net/smc/smc_llc.c +1 -1
@@ -2122,7 +2122,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 */
Signature · 1 line
2.30.2
PATCH 6/15 tcp: Fix data-races around sysctl_tcp_syn(ack)?_retries.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_syn(ack)?_retries, they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers.
--- net/ipv4/inet_connection_sock.c | 3 ++- net/ipv4/tcp.c | 3 ++- net/ipv4/tcp_timer.c | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-)
net/ipv4/inet_connection_sock.c +2 -1
@@ -833,7 +833,8 @@ static void reqsk_timer_handler(struct timer_list *t) icsk =inet_csk (sk_listener); net =sock_net (sk_listener); - max_syn_ack_retries = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_synack_retries; + max_syn_ack_retries = icsk->icsk_syn_retries ? : +READ_ONCE (net->ipv4.sysctl_tcp_synack_retries);/* Normally all the openreqs are young and become mature * (i.e. converted to established socket) for first timeout. * If synack was not acknowledged for 1 second, it means
net/ipv4/tcp.c +2 -1
@@ -3967,7 +3967,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level, val =keepalive_probes (tp);break ;case TCP_SYNCNT : - val = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries; + val = icsk->icsk_syn_retries ? : +READ_ONCE (net->ipv4.sysctl_tcp_syn_retries);break ;case TCP_LINGER2 : val = tp->linger2;
net/ipv4/tcp_timer.c +7 -3
@@ -239,7 +239,8 @@ static int tcp_write_timeout(struct sock *sk)if ((1 << sk->sk_state) & (TCPF_SYN_SENT |TCPF_SYN_RECV )) {if (icsk->icsk_retransmits)__dst_negative_advice (sk); - retry_until = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries; + retry_until = icsk->icsk_syn_retries ? : +READ_ONCE (net->ipv4.sysctl_tcp_syn_retries); expired = icsk->icsk_retransmits >= retry_until; }else {if (retransmits_timed_out (sk, net->ipv4.sysctl_tcp_retries1,0 )) {
@@ -406,12 +407,15 @@ abort: tcp_write_err(sk);static void tcp_fastopen_synack_timer (struct sock *sk,struct request_sock *req) {struct inet_connection_sock *icsk =inet_csk (sk); -int max_retries = icsk->icsk_syn_retries ? : -sock_net (sk)->ipv4.sysctl_tcp_synack_retries +1 ;/* add one more retry for fastopen */ struct tcp_sock *tp =tcp_sk (sk); +int max_retries; req->rsk_ops->syn_ack_timeout (req); +/* add one more retry for fastopen */ + max_retries = icsk->icsk_syn_retries ? : +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_synack_retries) +1 ; +if (req->num_timeout >= max_retries) {tcp_write_err (sk);return ;
Signature · 1 line
2.30.2
PATCH 7/15 tcp: Fix data-races around sysctl_tcp_syncookies.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_syncookies, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/core/filter.c | 4 ++-- net/ipv4/syncookies.c | 3 ++- net/ipv4/tcp_input.c | 20 ++++++++++++-------- net/ipv6/syncookies.c | 3 ++- 4 files changed, 18 insertions(+), 12 deletions(-)
net/core/filter.c +2 -2
@@ -7041,7 +7041,7 @@ BPF_CALL_5(bpf_tcp_check_syncookie, struct sock *, sk, void *, iph, u32, iph_lenif (sk->sk_protocol !=IPPROTO_TCP || sk->sk_state !=TCP_LISTEN )return -EINVAL ; -if (!sock_net (sk)->ipv4.sysctl_tcp_syncookies) +if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies))return -EINVAL ;if (!th->ack || th->rst || th->syn)
@@ -7116,7 +7116,7 @@ BPF_CALL_5(bpf_tcp_gen_syncookie, struct sock *, sk, void *, iph, u32, iph_len,if (sk->sk_protocol !=IPPROTO_TCP || sk->sk_state !=TCP_LISTEN )return -EINVAL ; -if (!sock_net (sk)->ipv4.sysctl_tcp_syncookies) +if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies))return -ENOENT ;if (!th->syn || th->ack || th->fin || th->rst)
net/ipv4/syncookies.c +2 -1
@@ -340,7 +340,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)struct flowi4 fl4;u32 tsoff =0 ; -if (!sock_net (sk)->ipv4.sysctl_tcp_syncookies || !th->ack || th->rst) +if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies) || + !th->ack || th->rst) goto out;if (tcp_synq_no_recent_overflow (sk))
net/ipv4/tcp_input.c +12 -8
@@ -6797,11 +6797,14 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) {struct request_sock_queue *queue = &inet_csk (sk)->icsk_accept_queue;const char *msg ="Dropping request" ; -bool want_cookie = false;struct net *net =sock_net (sk); +bool want_cookie = false; +u8 syncookies; + + syncookies =READ_ONCE (net->ipv4.sysctl_tcp_syncookies);#ifdef CONFIG_SYN_COOKIES -if (net->ipv4.sysctl_tcp_syncookies) { +if (syncookies) { msg ="Sending cookies" ; want_cookie = true;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPREQQFULLDOCOOKIES );
@@ -6809,8 +6812,7 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto)#endif __NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPREQQFULLDROP ); -if (!queue->synflood_warned && - net->ipv4.sysctl_tcp_syncookies !=2 && +if (!queue->synflood_warned && syncookies !=2 &&xchg (&queue->synflood_warned,1 ) ==0 )net_info_ratelimited ("%s: Possible SYN flooding on port %d. %s. Check SNMP counters.\n" , proto, sk->sk_num, msg);
@@ -6859,7 +6861,7 @@ u16 tcp_get_syncookie_mss(struct request_sock_ops *rsk_ops,struct tcp_sock *tp =tcp_sk (sk);u16 mss; -if (sock_net (sk)->ipv4.sysctl_tcp_syncookies !=2 && +if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies) !=2 && !inet_csk_reqsk_queue_is_full (sk))return 0 ;
@@ -6893,13 +6895,15 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,bool want_cookie = false;struct dst_entry *dst;struct flowi fl; +u8 syncookies; + + syncookies =READ_ONCE (net->ipv4.sysctl_tcp_syncookies);/* TW buckets are converted to open requests without * limitations, they conserve resources and peer is * evidently real one. */ -if ((net->ipv4.sysctl_tcp_syncookies ==2 || -inet_csk_reqsk_queue_is_full (sk)) && !isn) { +if ((syncookies ==2 ||inet_csk_reqsk_queue_is_full (sk)) && !isn) { want_cookie =tcp_syn_flood_action (sk, rsk_ops->slab_name);if (!want_cookie) goto drop;
@@ -6949,7 +6953,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,if (!want_cookie && !isn) {/* Kill the following clause, if you dislike this way. */ -if (!net->ipv4.sysctl_tcp_syncookies && +if (!syncookies && (net->ipv4.sysctl_max_syn_backlog -inet_csk_reqsk_queue_len (sk) < (net->ipv4.sysctl_max_syn_backlog >>2 )) && !tcp_peer_is_proven (req, dst)) {
net/ipv6/syncookies.c +2 -1
@@ -141,7 +141,8 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)__u8 rcv_wscale;u32 tsoff =0 ; -if (!sock_net (sk)->ipv4.sysctl_tcp_syncookies || !th->ack || th->rst) +if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies) || + !th->ack || th->rst) goto out;if (tcp_synq_no_recent_overflow (sk))
Signature · 1 line
2.30.2
PATCH 8/15 tcp: Fix data-races around sysctl_tcp_migrate_req.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_migrate_req, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/core/sock_reuseport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/sock_reuseport.c +2 -2
@@ -387,7 +387,7 @@ void reuseport_stop_listen_sock(struct sock *sk) prog =rcu_dereference_protected (reuse->prog,lockdep_is_held (&reuseport_lock)); -if (sock_net (sk)->ipv4.sysctl_tcp_migrate_req || +if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_migrate_req) || (prog && prog->expected_attach_type ==BPF_SK_REUSEPORT_SELECT_OR_MIGRATE )) {/* Migration capable, move sk from the listening section * to the closed section.
@@ -545,7 +545,7 @@ struct sock *reuseport_migrate_sock(struct sock *sk, hash = migrating_sk->sk_hash; prog =rcu_dereference (reuse->prog);if (!prog || prog->expected_attach_type !=BPF_SK_REUSEPORT_SELECT_OR_MIGRATE ) { -if (sock_net (sk)->ipv4.sysctl_tcp_migrate_req) +if (READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_migrate_req)) goto select_by_hash; goto failure; }
Signature · 1 line
2.30.2
PATCH 9/15 tcp: Fix data-races around sysctl_tcp_reordering.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_reordering, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_input.c | 10 +++++++--- net/ipv4/tcp_metrics.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-)
net/ipv4/tcp.c +1 -1
@@ -441,7 +441,7 @@ void tcp_init_sock(struct sock *sk) tp->snd_cwnd_clamp = ~0 ; tp->mss_cache =TCP_MSS_DEFAULT ; - tp->reordering =sock_net (sk)->ipv4.sysctl_tcp_reordering; + tp->reordering =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_reordering);tcp_assign_congestion_control (sk); tp->tsoffset =0 ;
net/ipv4/tcp_input.c +7 -3
@@ -2139,6 +2139,7 @@ void tcp_enter_loss(struct sock *sk)struct tcp_sock *tp =tcp_sk (sk);struct net *net =sock_net (sk);bool new_recovery = icsk->icsk_ca_state < TCP_CA_Recovery; +u8 reordering;tcp_timeout_mark_lost (sk);
@@ -2159,10 +2160,12 @@ void tcp_enter_loss(struct sock *sk)/* Timeout in disordered state after receiving substantial DUPACKs * suggests that the degree of reordering is over-estimated. */ + reordering =READ_ONCE (net->ipv4.sysctl_tcp_reordering);if (icsk->icsk_ca_state <= TCP_CA_Disorder && - tp->sacked_out >= net->ipv4.sysctl_tcp_reordering) + tp->sacked_out >= reordering) tp->reordering = min_t(unsigned int, tp->reordering, - net->ipv4.sysctl_tcp_reordering); + reordering); +tcp_set_ca_state (sk, TCP_CA_Loss); tp->high_seq = tp->snd_nxt;tcp_ecn_queue_cwr (tp);
@@ -3464,7 +3467,8 @@ static inline bool tcp_may_raise_cwnd(const struct sock *sk, const int flag)* new SACK or ECE mark may first advance cwnd here and later reduce * cwnd in tcp_fastretrans_alert() based on more states. */ -if (tcp_sk (sk)->reordering >sock_net (sk)->ipv4.sysctl_tcp_reordering) +if (tcp_sk (sk)->reordering > +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_reordering))return flag &FLAG_FORWARD_PROGRESS ;return flag &FLAG_DATA_ACKED ;
net/ipv4/tcp_metrics.c +2 -1
@@ -428,7 +428,8 @@ void tcp_update_metrics(struct sock *sk)if (!tcp_metric_locked (tm,TCP_METRIC_REORDERING )) { val =tcp_metric_get (tm,TCP_METRIC_REORDERING );if (val < tp->reordering && - tp->reordering != net->ipv4.sysctl_tcp_reordering) + tp->reordering != +READ_ONCE (net->ipv4.sysctl_tcp_reordering))tcp_metric_set (tm,TCP_METRIC_REORDERING , tp->reordering); }
Signature · 1 line
2.30.2
PATCH 10/15 tcp: Fix data-races around some timeout sysctl knobs.
In reply to Kuniyuki IwashimaWhile reading these sysctl knobs, they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers.
- tcp_retries1
- tcp_retries2
- tcp_orphan_retries
- tcp_fin_timeout
--- include/net/tcp.h | 3 ++- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 10 +++++----- 4 files changed, 9 insertions(+), 8 deletions(-)
include/net/tcp.h +2 -1
@@ -1523,7 +1523,8 @@ static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp)static inline int tcp_fin_time (const struct sock *sk) { -int fin_timeout =tcp_sk (sk)->linger2 ? :sock_net (sk)->ipv4.sysctl_tcp_fin_timeout; +int fin_timeout =tcp_sk (sk)->linger2 ? : +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fin_timeout);const int rto =inet_csk (sk)->icsk_rto;if (fin_timeout < (rto <<2 ) - (rto >>1 ))
net/ipv4/tcp.c +1 -1
@@ -3973,7 +3973,7 @@ static int do_tcp_getsockopt(struct sock *sk, int level,case TCP_LINGER2 : val = tp->linger2;if (val >=0 ) - val = (val ? : net->ipv4.sysctl_tcp_fin_timeout) /HZ ; + val = (val ? :READ_ONCE (net->ipv4.sysctl_tcp_fin_timeout)) /HZ ;break ;case TCP_DEFER_ACCEPT : val = retrans_to_secs(icsk->icsk_accept_queue.rskq_defer_accept,
net/ipv4/tcp_output.c +1 -1
@@ -4090,7 +4090,7 @@ void tcp_send_probe0(struct sock *sk) icsk->icsk_probes_out++;if (err <=0 ) { -if (icsk->icsk_backoff < net->ipv4.sysctl_tcp_retries2) +if (icsk->icsk_backoff <READ_ONCE (net->ipv4.sysctl_tcp_retries2)) icsk->icsk_backoff++; timeout =tcp_probe0_when (sk,TCP_RTO_MAX ); }else {
net/ipv4/tcp_timer.c +5 -5
@@ -143,7 +143,7 @@ static int tcp_out_of_resources(struct sock *sk, bool do_reset)*/ static int tcp_orphan_retries (struct sock *sk,bool alive) { -int retries =sock_net (sk)->ipv4.sysctl_tcp_orphan_retries;/* May be zero. */ +int retries =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_orphan_retries);/* May be zero. */ /* We know from an ICMP that something is wrong. */ if (sk->sk_err_soft && !alive)
@@ -243,14 +243,14 @@ static int tcp_write_timeout(struct sock *sk)READ_ONCE (net->ipv4.sysctl_tcp_syn_retries); expired = icsk->icsk_retransmits >= retry_until; }else { -if (retransmits_timed_out (sk, net->ipv4.sysctl_tcp_retries1,0 )) { +if (retransmits_timed_out (sk,READ_ONCE (net->ipv4.sysctl_tcp_retries1),0 )) {/* Black hole detection */ tcp_mtu_probing (icsk, sk);__dst_negative_advice (sk); } - retry_until = net->ipv4.sysctl_tcp_retries2; + retry_until =READ_ONCE (net->ipv4.sysctl_tcp_retries2);if (sock_flag (sk,SOCK_DEAD )) {const bool alive = icsk->icsk_rto <TCP_RTO_MAX ;
@@ -381,7 +381,7 @@ static void tcp_probe_timer(struct sock *sk) msecs_to_jiffies(icsk->icsk_user_timeout)) goto abort; - max_probes =sock_net (sk)->ipv4.sysctl_tcp_retries2; + max_probes =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_retries2);if (sock_flag (sk,SOCK_DEAD )) {const bool alive =inet_csk_rto_backoff (icsk,TCP_RTO_MAX ) <TCP_RTO_MAX ;
@@ -589,7 +589,7 @@ void tcp_retransmit_timer(struct sock *sk) }inet_csk_reset_xmit_timer (sk,ICSK_TIME_RETRANS ,tcp_clamp_rto_to_user_timeout (sk),TCP_RTO_MAX ); -if (retransmits_timed_out (sk, net->ipv4.sysctl_tcp_retries1 +1 ,0 )) +if (retransmits_timed_out (sk,READ_ONCE (net->ipv4.sysctl_tcp_retries1) +1 ,0 ))__sk_dst_reset (sk); out:;
Signature · 1 line
2.30.2
PATCH 11/15 tcp: Fix a data-race around sysctl_tcp_notsent_lowat.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_notsent_lowat, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- include/net/tcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/tcp.h +1 -1
@@ -2027,7 +2027,7 @@ void __tcp_v4_send_check(struct sk_buff *skb, __be32 saddr, __be32 daddr);static inline u32 tcp_notsent_lowat (const struct tcp_sock *tp) {struct net *net =sock_net ((struct sock *)tp); -return tp->notsent_lowat ?: net->ipv4.sysctl_tcp_notsent_lowat; +return tp->notsent_lowat ?:READ_ONCE (net->ipv4.sysctl_tcp_notsent_lowat); }bool tcp_stream_memory_free (const struct sock *sk,int wake);
Signature · 1 line
2.30.2
PATCH 12/15 tcp: Fix a data-race around sysctl_tcp_tw_reuse.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_tw_reuse, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader.
--- net/ipv4/tcp_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_ipv4.c +1 -1
@@ -108,10 +108,10 @@ static u32 tcp_v4_init_ts_off(const struct net *net, const struct sk_buff *skb)int tcp_twsk_unique (struct sock *sk,struct sock *sktw,void *twp) { +int reuse =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_tw_reuse);const struct inet_timewait_sock *tw =inet_twsk (sktw);const struct tcp_timewait_sock *tcptw =tcp_twsk (sktw);struct tcp_sock *tp =tcp_sk (sk); -int reuse =sock_net (sk)->ipv4.sysctl_tcp_tw_reuse;if (reuse ==2 ) {/* Still does not detect *everything* that goes through
Signature · 1 line
2.30.2
PATCH 13/15 tcp: Fix data-races around sysctl_max_syn_backlog.
In reply to Kuniyuki IwashimaWhile reading sysctl_max_syn_backlog, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
--- net/ipv4/tcp_input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +4 -2
@@ -6956,10 +6956,12 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,tcp_rsk (req)->ts_off = af_ops->init_ts_off (net, skb);if (!want_cookie && !isn) { +int max_syn_backlog =READ_ONCE (net->ipv4.sysctl_max_syn_backlog); +/* Kill the following clause, if you dislike this way. */ if (!syncookies && - (net->ipv4.sysctl_max_syn_backlog -inet_csk_reqsk_queue_len (sk) < - (net->ipv4.sysctl_max_syn_backlog >>2 )) && + (max_syn_backlog -inet_csk_reqsk_queue_len (sk) < + (max_syn_backlog >>2 )) && !tcp_peer_is_proven (req, dst)) {/* Without syncookies last quarter of * backlog is filled with destinations,
Signature · 1 line
2.30.2
PATCH 14/15 tcp: Fix data-races around sysctl_tcp_fastopen.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_fastopen, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
---
CC: Yuchung Cheng <[email protected]>
--- net/ipv4/af_inet.c | 2 +- net/ipv4/tcp.c | 6 ++++-- net/ipv4/tcp_fastopen.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-)
net/ipv4/af_inet.c +1 -1
@@ -217,7 +217,7 @@ int inet_listen(struct socket *sock, int backlog)* because the socket was in TCP_LISTEN state previously but * was shutdown() rather than close(). */ - tcp_fastopen =sock_net (sk)->ipv4.sysctl_tcp_fastopen; + tcp_fastopen =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen);if ((tcp_fastopen &TFO_SERVER_WO_SOCKOPT1 ) && (tcp_fastopen &TFO_SERVER_ENABLE ) && !inet_csk (sk)->icsk_accept_queue.fastopenq.max_qlen) {
net/ipv4/tcp.c +4 -2
@@ -1150,7 +1150,8 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,struct sockaddr *uaddr = msg->msg_name;int err, flags; -if (!(sock_net (sk)->ipv4.sysctl_tcp_fastopen &TFO_CLIENT_ENABLE ) || +if (!(READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen) & +TFO_CLIENT_ENABLE ) || (uaddr && msg->msg_namelen >=sizeof (uaddr->sa_family) && uaddr->sa_family ==AF_UNSPEC ))return -EOPNOTSUPP ;
@@ -3617,7 +3618,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,case TCP_FASTOPEN_CONNECT :if (val >1 || val <0 ) { err = -EINVAL ; - }else if (net->ipv4.sysctl_tcp_fastopen &TFO_CLIENT_ENABLE ) { + }else if (READ_ONCE (net->ipv4.sysctl_tcp_fastopen) & +TFO_CLIENT_ENABLE ) {if (sk->sk_state ==TCP_CLOSE ) tp->fastopen_connect = val;else
net/ipv4/tcp_fastopen.c +2 -2
@@ -332,7 +332,7 @@ static bool tcp_fastopen_no_cookie(const struct sock *sk, const struct dst_entry *dst, int flag) { - return (sock_net(sk)->ipv4.sysctl_tcp_fastopen & flag) || + return (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & flag) || tcp_sk(sk)->fastopen_no_cookie || (dst && dst_metric(dst, RTAX_FASTOPEN_NO_COOKIE)); }
@@ -347,7 +347,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, const struct dst_entry *dst) {bool syn_data =TCP_SKB_CB (skb)->end_seq !=TCP_SKB_CB (skb)->seq +1 ; -int tcp_fastopen =sock_net (sk)->ipv4.sysctl_tcp_fastopen; +int tcp_fastopen =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen);struct tcp_fastopen_cookie valid_foc = { .len =-1 };struct sock *child;int ret =0 ;
Signature · 1 line
2.30.2
Re: [PATCH v1 net 14/15] tcp: Fix data-races around sysctl_tcp_fastopen.
Quoted 8 lines · Kuniyuki Iwashima
While reading
sysctl_tcp_fastopen, it can be changed concurrently. Thus, we need to addREAD_ONCE()to its readers.Fixes 2100c8d2d9db ("net-tcp: Fast Open base")Signed-off-by Kuniyuki Iwashima <[email protected]>---
CC: Yuchung Cheng <[email protected]>
Thanks for the improvement
Quoted 68 lines
--- net/ipv4/af_inet.c | 2 +- net/ipv4/tcp.c | 6 ++++-- net/ipv4/tcp_fastopen.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-)net/ipv4/af_inet.c +1
-1@@ -217,7 +217,7 @@ int inet_listen(struct socket *sock, int backlog)* because the socket was in TCP_LISTEN state previously but * was shutdown() rather than close(). */ - tcp_fastopen =sock_net (sk)->ipv4.sysctl_tcp_fastopen; + tcp_fastopen =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen);if ((tcp_fastopen &TFO_SERVER_WO_SOCKOPT1 ) && (tcp_fastopen &TFO_SERVER_ENABLE ) && !inet_csk (sk)->icsk_accept_queue.fastopenq.max_qlen) {net/ipv4/tcp.c +4
-2@@ -1150,7 +1150,8 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,struct sockaddr *uaddr = msg->msg_name;int err, flags; -if (!(sock_net (sk)->ipv4.sysctl_tcp_fastopen &TFO_CLIENT_ENABLE ) || +if (!(READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen) & +TFO_CLIENT_ENABLE ) || (uaddr && msg->msg_namelen >=sizeof (uaddr->sa_family) && uaddr->sa_family ==AF_UNSPEC ))return -EOPNOTSUPP ;@@ -3617,7 +3618,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,case TCP_FASTOPEN_CONNECT :if (val >1 || val <0 ) { err = -EINVAL ; - }else if (net->ipv4.sysctl_tcp_fastopen &TFO_CLIENT_ENABLE ) { + }else if (READ_ONCE (net->ipv4.sysctl_tcp_fastopen) & +TFO_CLIENT_ENABLE ) {if (sk->sk_state ==TCP_CLOSE ) tp->fastopen_connect = val;else net/ipv4/tcp_fastopen.c +2
-3@@ -332,7 +332,7 @@ static bool tcp_fastopen_no_cookie(const struct sock *sk, const struct dst_entry *dst, int flag) { - return (sock_net(sk)->ipv4.sysctl_tcp_fastopen & flag) || + return (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & flag) || tcp_sk(sk)->fastopen_no_cookie || (dst && dst_metric(dst, RTAX_FASTOPEN_NO_COOKIE)); }@@ -347,7 +347,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, const struct dst_entry *dst) {bool syn_data =TCP_SKB_CB (skb)->end_seq !=TCP_SKB_CB (skb)->seq +1 ; -int tcp_fastopen =sock_net (sk)->ipv4.sysctl_tcp_fastopen; +int tcp_fastopen =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen);struct tcp_fastopen_cookie valid_foc = { .len =-1 };struct sock *child;int ret =0 ; --2.30.2
PATCH 15/15 tcp: Fix data-races around sysctl_tcp_fastopen_blackhole_timeout.
In reply to Kuniyuki IwashimaWhile reading sysctl_tcp_fastopen_blackhole_timeout, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.
---
CC: Wei Wang <[email protected]>
--- net/ipv4/tcp_fastopen.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp_fastopen.c +3 -2
@@ -489,7 +489,7 @@ void tcp_fastopen_active_disable(struct sock *sk) {struct net *net =sock_net (sk); -if (!sock_net (sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout) +if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout))return ;/* Paired with READ_ONCE() in tcp_fastopen_active_should_disable() */
@@ -510,7 +510,8 @@ void tcp_fastopen_active_disable(struct sock *sk)*/ bool tcp_fastopen_active_should_disable (struct sock *sk) { -unsigned int tfo_bh_timeout =sock_net (sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout; +unsigned int tfo_bh_timeout = +READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout);unsigned long timeout;int tfo_da_times;int multiplier;
Signature · 1 line
2.30.2
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Quoted 11 lines · On Fri, 15 Jul 2022 10:17:40 -0700 you wrote:
This series fixes data-races around 21 knobs after
igmp_link_local_mcast_reportsinipv4_net_table.These 4 knobs are skipped because they are safe.
-
tcp_congestion_control: Safe with RCU andxchg().
-tcp_available_congestion_control: Read only.
-tcp_allowed_congestion_control: Safe with RCU andspinlock().
-tcp_fastopen_key: Safe with RCU andxchg()[...]
Here is the summary with links:
- [v1,net,01/15] igmp: Fix data-races around sysctl_igmp_llm_reports.
https://git.kernel.org/netdev/net/c/f6da2267e711 - [v1,net,02/15] igmp: Fix a data-race around sysctl_igmp_max_memberships. https://git.kernel.org/netdev/net/c/6305d821e3b9 - [v1,net,03/15] igmp: Fix data-races around sysctl_igmp_max_msf. https://git.kernel.org/netdev/net/c/6ae0f2e55373 - [v1,net,04/15] igmp: Fix data-races around sysctl_igmp_qrv. https://git.kernel.org/netdev/net/c/8ebcc62c738f - [v1,net,05/15] tcp: Fix data-races around keepalive sysctl knobs. https://git.kernel.org/netdev/net/c/f2f316e287e6 - [v1,net,06/15] tcp: Fix data-races around sysctl_tcp_syn(ack)?_retries. https://git.kernel.org/netdev/net/c/20a3b1c0f603 - [v1,net,07/15] tcp: Fix data-races around sysctl_tcp_syncookies. https://git.kernel.org/netdev/net/c/f2e383b5bb6b - [v1,net,08/15] tcp: Fix data-races around sysctl_tcp_migrate_req. https://git.kernel.org/netdev/net/c/4177f545895b - [v1,net,09/15] tcp: Fix data-races around sysctl_tcp_reordering. https://git.kernel.org/netdev/net/c/46778cd16e6a - [v1,net,10/15] tcp: Fix data-races around some timeout sysctl knobs. https://git.kernel.org/netdev/net/c/39e24435a776 - [v1,net,11/15] tcp: Fix a data-race around sysctl_tcp_notsent_lowat. https://git.kernel.org/netdev/net/c/55be873695ed - [v1,net,12/15] tcp: Fix a data-race around sysctl_tcp_tw_reuse. https://git.kernel.org/netdev/net/c/cbfc6495586a - [v1,net,13/15] tcp: Fix data-races around sysctl_max_syn_backlog. https://git.kernel.org/netdev/net/c/79539f34743d - [v1,net,14/15] tcp: Fix data-races around sysctl_tcp_fastopen. https://git.kernel.org/netdev/net/c/5a54213318c4 - [v1,net,15/15] tcp: Fix data-races around sysctl_tcp_fastopen_blackhole_timeout. https://git.kernel.org/netdev/net/c/021266ec640c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html