Skip to content

Commit

Permalink
Merge branch 'netrom-fix-all-the-data-races-around-sysctls'
Browse files Browse the repository at this point in the history
Jason Xing says:

====================
netrom: Fix all the data-races around sysctls

As the title said, in this patchset I fix the data-race issues because
the writer and the reader can manipulate the same value concurrently.
====================

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Paolo Abeni committed Mar 7, 2024
2 parents 811b3f9 + d380ce7 commit 6d673e8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
14 changes: 7 additions & 7 deletions net/netrom/af_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,16 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,
nr_init_timers(sk);

nr->t1 =
msecs_to_jiffies(sysctl_netrom_transport_timeout);
msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_timeout));
nr->t2 =
msecs_to_jiffies(sysctl_netrom_transport_acknowledge_delay);
msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_acknowledge_delay));
nr->n2 =
msecs_to_jiffies(sysctl_netrom_transport_maximum_tries);
msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_maximum_tries));
nr->t4 =
msecs_to_jiffies(sysctl_netrom_transport_busy_delay);
msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_busy_delay));
nr->idle =
msecs_to_jiffies(sysctl_netrom_transport_no_activity_timeout);
nr->window = sysctl_netrom_transport_requested_window_size;
msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_no_activity_timeout));
nr->window = READ_ONCE(sysctl_netrom_transport_requested_window_size);

nr->bpqext = 1;
nr->state = NR_STATE_0;
Expand Down Expand Up @@ -954,7 +954,7 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
* G8PZT's Xrouter which is sending packets with command type 7
* as an extension of the protocol.
*/
if (sysctl_netrom_reset_circuit &&
if (READ_ONCE(sysctl_netrom_reset_circuit) &&
(frametype != NR_RESET || flags != 0))
nr_transmit_reset(skb, 1);

Expand Down
2 changes: 1 addition & 1 deletion net/netrom/nr_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int nr_header(struct sk_buff *skb, struct net_device *dev,
buff[6] |= AX25_SSSID_SPARE;
buff += AX25_ADDR_LEN;

*buff++ = sysctl_netrom_network_ttl_initialiser;
*buff++ = READ_ONCE(sysctl_netrom_network_ttl_initialiser);

*buff++ = NR_PROTO_IP;
*buff++ = NR_PROTO_IP;
Expand Down
6 changes: 3 additions & 3 deletions net/netrom/nr_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int nr_state1_machine(struct sock *sk, struct sk_buff *skb,
break;

case NR_RESET:
if (sysctl_netrom_reset_circuit)
if (READ_ONCE(sysctl_netrom_reset_circuit))
nr_disconnect(sk, ECONNRESET);
break;

Expand Down Expand Up @@ -128,7 +128,7 @@ static int nr_state2_machine(struct sock *sk, struct sk_buff *skb,
break;

case NR_RESET:
if (sysctl_netrom_reset_circuit)
if (READ_ONCE(sysctl_netrom_reset_circuit))
nr_disconnect(sk, ECONNRESET);
break;

Expand Down Expand Up @@ -262,7 +262,7 @@ static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype
break;

case NR_RESET:
if (sysctl_netrom_reset_circuit)
if (READ_ONCE(sysctl_netrom_reset_circuit))
nr_disconnect(sk, ECONNRESET);
break;

Expand Down
2 changes: 1 addition & 1 deletion net/netrom/nr_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void nr_transmit_buffer(struct sock *sk, struct sk_buff *skb)
dptr[6] |= AX25_SSSID_SPARE;
dptr += AX25_ADDR_LEN;

*dptr++ = sysctl_netrom_network_ttl_initialiser;
*dptr++ = READ_ONCE(sysctl_netrom_network_ttl_initialiser);

if (!nr_route_frame(skb, NULL)) {
kfree_skb(skb);
Expand Down
8 changes: 4 additions & 4 deletions net/netrom/nr_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
nr_neigh->digipeat = NULL;
nr_neigh->ax25 = NULL;
nr_neigh->dev = dev;
nr_neigh->quality = sysctl_netrom_default_path_quality;
nr_neigh->quality = READ_ONCE(sysctl_netrom_default_path_quality);
nr_neigh->locked = 0;
nr_neigh->count = 0;
nr_neigh->number = nr_neigh_no++;
Expand Down Expand Up @@ -728,7 +728,7 @@ void nr_link_failed(ax25_cb *ax25, int reason)
nr_neigh->ax25 = NULL;
ax25_cb_put(ax25);

if (++nr_neigh->failed < sysctl_netrom_link_fails_count) {
if (++nr_neigh->failed < READ_ONCE(sysctl_netrom_link_fails_count)) {
nr_neigh_put(nr_neigh);
return;
}
Expand Down Expand Up @@ -766,7 +766,7 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
if (ax25 != NULL) {
ret = nr_add_node(nr_src, "", &ax25->dest_addr, ax25->digipeat,
ax25->ax25_dev->dev, 0,
sysctl_netrom_obsolescence_count_initialiser);
READ_ONCE(sysctl_netrom_obsolescence_count_initialiser));
if (ret)
return ret;
}
Expand All @@ -780,7 +780,7 @@ int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
return ret;
}

if (!sysctl_netrom_routing_control && ax25 != NULL)
if (!READ_ONCE(sysctl_netrom_routing_control) && ax25 != NULL)
return 0;

/* Its Time-To-Live has expired */
Expand Down
5 changes: 3 additions & 2 deletions net/netrom/nr_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ void nr_write_internal(struct sock *sk, int frametype)
*dptr++ = nr->my_id;
*dptr++ = frametype;
*dptr++ = nr->window;
if (nr->bpqext) *dptr++ = sysctl_netrom_network_ttl_initialiser;
if (nr->bpqext)
*dptr++ = READ_ONCE(sysctl_netrom_network_ttl_initialiser);
break;

case NR_DISCREQ:
Expand Down Expand Up @@ -236,7 +237,7 @@ void __nr_transmit_reply(struct sk_buff *skb, int mine, unsigned char cmdflags)
dptr[6] |= AX25_SSSID_SPARE;
dptr += AX25_ADDR_LEN;

*dptr++ = sysctl_netrom_network_ttl_initialiser;
*dptr++ = READ_ONCE(sysctl_netrom_network_ttl_initialiser);

if (mine) {
*dptr++ = 0;
Expand Down

0 comments on commit 6d673e8

Please sign in to comment.