Merge branch 'net-sysctl-races-round2'
Kuniyuki Iwashima says: ==================== sysctl: Fix data-races around ipv4_net_table (Round 2). This series fixes data-races around 15 knobs after ip_default_ttl in ipv4_net_table. These two knobs are skipped. - ip_local_port_range is safe with its own lock. - ip_local_reserved_ports uses proc_do_large_bitmap(), which will need an additional lock and can be fixed later. So, the next round will start with igmp_link_local_mcast_reports. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
782d86fe44
@ -10523,13 +10523,14 @@ static int mlxsw_sp_dscp_init(struct mlxsw_sp *mlxsw_sp)
|
||||
static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
|
||||
{
|
||||
struct net *net = mlxsw_sp_net(mlxsw_sp);
|
||||
bool usp = net->ipv4.sysctl_ip_fwd_update_priority;
|
||||
char rgcr_pl[MLXSW_REG_RGCR_LEN];
|
||||
u64 max_rifs;
|
||||
bool usp;
|
||||
|
||||
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_RIFS))
|
||||
return -EIO;
|
||||
max_rifs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
|
||||
usp = READ_ONCE(net->ipv4.sysctl_ip_fwd_update_priority);
|
||||
|
||||
mlxsw_reg_rgcr_pack(rgcr_pl, true, true);
|
||||
mlxsw_reg_rgcr_max_router_interfaces_set(rgcr_pl, max_rifs);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ static inline bool inet_sk_bound_dev_eq(struct net *net, int bound_dev_if,
|
||||
int dif, int sdif)
|
||||
{
|
||||
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
|
||||
return inet_bound_dev_eq(!!net->ipv4.sysctl_tcp_l3mdev_accept,
|
||||
return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept),
|
||||
bound_dev_if, dif, sdif);
|
||||
#else
|
||||
return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
|
||||
|
@ -107,7 +107,8 @@ static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk)
|
||||
|
||||
static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb)
|
||||
{
|
||||
if (!sk->sk_mark && sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept)
|
||||
if (!sk->sk_mark &&
|
||||
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept))
|
||||
return skb->mark;
|
||||
|
||||
return sk->sk_mark;
|
||||
@ -120,7 +121,7 @@ static inline int inet_request_bound_dev_if(const struct sock *sk,
|
||||
#ifdef CONFIG_NET_L3_MASTER_DEV
|
||||
struct net *net = sock_net(sk);
|
||||
|
||||
if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)
|
||||
if (!bound_dev_if && READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept))
|
||||
return l3mdev_master_ifindex_by_index(net, skb->skb_iif);
|
||||
#endif
|
||||
|
||||
@ -132,7 +133,7 @@ static inline int inet_sk_bound_l3mdev(const struct sock *sk)
|
||||
#ifdef CONFIG_NET_L3_MASTER_DEV
|
||||
struct net *net = sock_net(sk);
|
||||
|
||||
if (!net->ipv4.sysctl_tcp_l3mdev_accept)
|
||||
if (!READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept))
|
||||
return l3mdev_master_ifindex_by_index(net,
|
||||
sk->sk_bound_dev_if);
|
||||
#endif
|
||||
@ -374,7 +375,7 @@ static inline bool inet_get_convert_csum(struct sock *sk)
|
||||
static inline bool inet_can_nonlocal_bind(struct net *net,
|
||||
struct inet_sock *inet)
|
||||
{
|
||||
return net->ipv4.sysctl_ip_nonlocal_bind ||
|
||||
return READ_ONCE(net->ipv4.sysctl_ip_nonlocal_bind) ||
|
||||
inet->freebind || inet->transparent;
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ void ipfrag_init(void);
|
||||
void ip_static_sysctl_init(void);
|
||||
|
||||
#define IP4_REPLY_MARK(net, mark) \
|
||||
((net)->ipv4.sysctl_fwmark_reflect ? (mark) : 0)
|
||||
(READ_ONCE((net)->ipv4.sysctl_fwmark_reflect) ? (mark) : 0)
|
||||
|
||||
static inline bool ip_is_fragment(const struct iphdr *iph)
|
||||
{
|
||||
@ -446,7 +446,7 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
|
||||
struct net *net = dev_net(dst->dev);
|
||||
unsigned int mtu;
|
||||
|
||||
if (net->ipv4.sysctl_ip_fwd_use_pmtu ||
|
||||
if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) ||
|
||||
ip_mtu_locked(dst) ||
|
||||
!forwarding) {
|
||||
mtu = rt->rt_pmtu;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ lookup_protocol:
|
||||
inet->hdrincl = 1;
|
||||
}
|
||||
|
||||
if (net->ipv4.sysctl_ip_no_pmtu_disc)
|
||||
if (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc))
|
||||
inet->pmtudisc = IP_PMTUDISC_DONT;
|
||||
else
|
||||
inet->pmtudisc = IP_PMTUDISC_WANT;
|
||||
|
@ -881,7 +881,7 @@ static enum skb_drop_reason icmp_unreach(struct sk_buff *skb)
|
||||
* values please see
|
||||
* Documentation/networking/ip-sysctl.rst
|
||||
*/
|
||||
switch (net->ipv4.sysctl_ip_no_pmtu_disc) {
|
||||
switch (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc)) {
|
||||
default:
|
||||
net_dbg_ratelimited("%pI4: fragmentation needed and DF set\n",
|
||||
&iph->daddr);
|
||||
|
@ -263,7 +263,7 @@ next_port:
|
||||
goto other_half_scan;
|
||||
}
|
||||
|
||||
if (net->ipv4.sysctl_ip_autobind_reuse && !relax) {
|
||||
if (READ_ONCE(net->ipv4.sysctl_ip_autobind_reuse) && !relax) {
|
||||
/* We still have a chance to connect to different destinations */
|
||||
relax = true;
|
||||
goto ports_exhausted;
|
||||
|
@ -157,7 +157,7 @@ int ip_forward(struct sk_buff *skb)
|
||||
!skb_sec_path(skb))
|
||||
ip_rt_send_redirect(skb);
|
||||
|
||||
if (net->ipv4.sysctl_ip_fwd_update_priority)
|
||||
if (READ_ONCE(net->ipv4.sysctl_ip_fwd_update_priority))
|
||||
skb->priority = rt_tos2priority(iph->tos);
|
||||
|
||||
return NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -1398,7 +1398,7 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr)
|
||||
struct fib_info *fi = res->fi;
|
||||
u32 mtu = 0;
|
||||
|
||||
if (dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu ||
|
||||
if (READ_ONCE(dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu) ||
|
||||
fi->fib_metrics->metrics[RTAX_LOCK - 1] & (1 << RTAX_MTU))
|
||||
mtu = fi->fib_mtu;
|
||||
|
||||
|
@ -1719,7 +1719,8 @@ static inline int __tcp_mtu_to_mss(struct sock *sk, int pmtu)
|
||||
mss_now -= icsk->icsk_ext_hdr_len;
|
||||
|
||||
/* Then reserve room for full set of TCP options and 8 bytes of data */
|
||||
mss_now = max(mss_now, sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss);
|
||||
mss_now = max(mss_now,
|
||||
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss));
|
||||
return mss_now;
|
||||
}
|
||||
|
||||
@ -1762,10 +1763,10 @@ void tcp_mtup_init(struct sock *sk)
|
||||
struct inet_connection_sock *icsk = inet_csk(sk);
|
||||
struct net *net = sock_net(sk);
|
||||
|
||||
icsk->icsk_mtup.enabled = net->ipv4.sysctl_tcp_mtu_probing > 1;
|
||||
icsk->icsk_mtup.enabled = READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing) > 1;
|
||||
icsk->icsk_mtup.search_high = tp->rx_opt.mss_clamp + sizeof(struct tcphdr) +
|
||||
icsk->icsk_af_ops->net_header_len;
|
||||
icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, net->ipv4.sysctl_tcp_base_mss);
|
||||
icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, READ_ONCE(net->ipv4.sysctl_tcp_base_mss));
|
||||
icsk->icsk_mtup.probe_size = 0;
|
||||
if (icsk->icsk_mtup.enabled)
|
||||
icsk->icsk_mtup.probe_timestamp = tcp_jiffies32;
|
||||
@ -2282,7 +2283,7 @@ static inline void tcp_mtu_check_reprobe(struct sock *sk)
|
||||
u32 interval;
|
||||
s32 delta;
|
||||
|
||||
interval = net->ipv4.sysctl_tcp_probe_interval;
|
||||
interval = READ_ONCE(net->ipv4.sysctl_tcp_probe_interval);
|
||||
delta = tcp_jiffies32 - icsk->icsk_mtup.probe_timestamp;
|
||||
if (unlikely(delta >= interval * HZ)) {
|
||||
int mss = tcp_current_mss(sk);
|
||||
@ -2366,7 +2367,7 @@ static int tcp_mtu_probe(struct sock *sk)
|
||||
* probing process by not resetting search range to its orignal.
|
||||
*/
|
||||
if (probe_size > tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_high) ||
|
||||
interval < net->ipv4.sysctl_tcp_probe_threshold) {
|
||||
interval < READ_ONCE(net->ipv4.sysctl_tcp_probe_threshold)) {
|
||||
/* Check whether enough time has elaplased for
|
||||
* another round of probing.
|
||||
*/
|
||||
|
@ -163,7 +163,7 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk)
|
||||
int mss;
|
||||
|
||||
/* Black hole detection */
|
||||
if (!net->ipv4.sysctl_tcp_mtu_probing)
|
||||
if (!READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing))
|
||||
return;
|
||||
|
||||
if (!icsk->icsk_mtup.enabled) {
|
||||
@ -171,9 +171,9 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk)
|
||||
icsk->icsk_mtup.probe_timestamp = tcp_jiffies32;
|
||||
} else {
|
||||
mss = tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1;
|
||||
mss = min(net->ipv4.sysctl_tcp_base_mss, mss);
|
||||
mss = max(mss, net->ipv4.sysctl_tcp_mtu_probe_floor);
|
||||
mss = max(mss, net->ipv4.sysctl_tcp_min_snd_mss);
|
||||
mss = min(READ_ONCE(net->ipv4.sysctl_tcp_base_mss), mss);
|
||||
mss = max(mss, READ_ONCE(net->ipv4.sysctl_tcp_mtu_probe_floor));
|
||||
mss = max(mss, READ_ONCE(net->ipv4.sysctl_tcp_min_snd_mss));
|
||||
icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss);
|
||||
}
|
||||
tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
|
||||
|
@ -226,7 +226,7 @@ lookup_protocol:
|
||||
RCU_INIT_POINTER(inet->mc_list, NULL);
|
||||
inet->rcv_tos = 0;
|
||||
|
||||
if (net->ipv4.sysctl_ip_no_pmtu_disc)
|
||||
if (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc))
|
||||
inet->pmtudisc = IP_PMTUDISC_DONT;
|
||||
else
|
||||
inet->pmtudisc = IP_PMTUDISC_WANT;
|
||||
|
@ -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;
|
||||
|
@ -358,7 +358,7 @@ static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
|
||||
if (addr->v4.sin_addr.s_addr != htonl(INADDR_ANY) &&
|
||||
ret != RTN_LOCAL &&
|
||||
!sp->inet.freebind &&
|
||||
!net->ipv4.sysctl_ip_nonlocal_bind)
|
||||
!READ_ONCE(net->ipv4.sysctl_ip_nonlocal_bind))
|
||||
return 0;
|
||||
|
||||
if (ipv6_only_sock(sctp_opt2sk(sp)))
|
||||
|
@ -2620,7 +2620,7 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
|
||||
int err;
|
||||
|
||||
if (family == AF_INET &&
|
||||
xs_net(x)->ipv4.sysctl_ip_no_pmtu_disc)
|
||||
READ_ONCE(xs_net(x)->ipv4.sysctl_ip_no_pmtu_disc))
|
||||
x->props.flags |= XFRM_STATE_NOPMTUDISC;
|
||||
|
||||
err = -EPROTONOSUPPORT;
|
||||
|
Loading…
Reference in New Issue
Block a user