History

ipv4: Fix data-races around sysctl_fib_multipath_hash_fields.

While reading sysctl_fib_multipath_hash_fields, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.

Kuniyuki Iwashima committed 4 years ago

Commit 8895a9c1 parent 7998c122 files · +4 −4Browse files

Unified · Split

2 files
  1. drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 −1
  2. net/ipv4/route.c +3 −3
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c+1−1
@@ -10342,7 +10342,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp, · 10341 unmodified lines
10342 mlxsw_sp_mp_hash_inner_l3(config);10342 mlxsw_sp_mp_hash_inner_l3(config);
10343 break;10343 break;
10344 case 3:10344 case 3:
10345 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;10345 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
10346 /* Outer */10346 /* Outer */
10347 MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP);10347 MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP);
10348 MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP);10348 MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP);
net/ipv4/route.c+3−3
@@ -1929,7 +1929,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net, · 1928 unmodified lines
1929 const struct sk_buff *skb,1929 const struct sk_buff *skb,
1930 bool *p_has_inner)1930 bool *p_has_inner)
1931{1931{
1932 u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;1932 u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
1933 struct flow_keys keys, hash_keys;1933 struct flow_keys keys, hash_keys;
1934 1934
1935 if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))1935 if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))
@@ -1958,7 +1958,7 @@ static u32 fib_multipath_custom_hash_inner(const struct net *net, · 22 unmodified lines
1958 const struct sk_buff *skb,1958 const struct sk_buff *skb,
1959 bool has_inner)1959 bool has_inner)
1960{1960{
1961 u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;1961 u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
1962 struct flow_keys keys, hash_keys;1962 struct flow_keys keys, hash_keys;
1963 1963
1964 /* We assume the packet carries an encapsulation, but if none was1964 /* We assume the packet carries an encapsulation, but if none was
@@ -2018,7 +2018,7 @@ static u32 fib_multipath_custom_hash_skb(const struct net *net, · 53 unmodified lines
2018static u32 fib_multipath_custom_hash_fl4(const struct net *net,2018static u32 fib_multipath_custom_hash_fl4(const struct net *net,
2019 const struct flowi4 *fl4)2019 const struct flowi4 *fl4)
2020{2020{
2021 u32 hash_fields = net->ipv4.sysctl_fib_multipath_hash_fields;2021 u32 hash_fields = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields);
2022 struct flow_keys hash_keys;2022 struct flow_keys hash_keys;
2023 2023
2024 if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))2024 if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK))