Skip to contentSkip to conversation

netrom: Fix all the data-races around sysctls

PATCH Applied Jason Xing 3 participants 16 messages Mar 4, 2024 – Mar 7, 2024

Subsystems (2)
lore
Share & tools
lore

Jason Xing

author
#0 lore raw

cover netrom: Fix all the data-races around sysctls

From: Jason Xing <[email protected]>

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.

Jason Xing (12):
netrom: Fix a data-race around sysctl_netrom_default_path_quality
netrom: Fix a data-race around
sysctl_netrom_obsolescence_count_initialiser
netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser
netrom: Fix a data-race around sysctl_netrom_transport_timeout
netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries
netrom: Fix a data-race around
sysctl_netrom_transport_acknowledge_delay
netrom: Fix a data-race around sysctl_netrom_transport_busy_delay
netrom: Fix a data-race around
sysctl_netrom_transport_requested_window_size
netrom: Fix a data-race around
sysctl_netrom_transport_no_activity_timeout
netrom: Fix a data-race around sysctl_netrom_routing_control
netrom: Fix a data-race around sysctl_netrom_link_fails_count
netrom: Fix data-races around sysctl_net_busy_read

 net/netrom/af_netrom.c | 14 +++++++-------
 net/netrom/nr_dev.c    |  2 +-
 net/netrom/nr_in.c     |  6 +++---
 net/netrom/nr_out.c    |  2 +-
 net/netrom/nr_route.c  |  8 ++++----
 net/netrom/nr_subr.c   |  5 +++--
 6 files changed, 19 insertions(+), 18 deletions(-)
Signature · 1 line
2.37.3
author
#1 lore raw

PATCH 1/12 netrom: Fix a data-race around sysctl_netrom_default_path_quality

From: Jason Xing <[email protected]>

We need to protect the reader reading sysctl_netrom_default_path_quality because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/nr_route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/nr_route.c +1 -1
index baea3cbd76ca..6f709fdffc11 100644
@@ -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++;
Signature · 1 line
2.37.3
author
#2 lore raw

PATCH 2/12 netrom: Fix a data-race around sysctl_netrom_obsolescence_count_initialiser

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/nr_route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/nr_route.c +1 -1
index 6f709fdffc11..b8ddd8048f35 100644
@@ -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;
 	}
Signature · 1 line
2.37.3
author
#3 lore raw

PATCH 3/12 netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/nr_dev.c  | 2 +-
 net/netrom/nr_out.c  | 2 +-
 net/netrom/nr_subr.c | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)
net/netrom/nr_dev.c +1 -1
index 3aaac4a22b38..2c34389c3ce6 100644
@@ -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;
net/netrom/nr_out.c +1 -1
index 44929657f5b7..5e531394a724 100644
@@ -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);
net/netrom/nr_subr.c +3 -2
index e2d2af924cff..c3bbd5880850 100644
@@ -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:
@@ -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;
Signature · 1 line
2.37.3
author
#4 lore raw

PATCH 4/12 netrom: Fix a data-race around sysctl_netrom_transport_timeout

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/af_netrom.c +1 -1
index 0eed00184adf..4d0e0834d527 100644
@@ -453,7 +453,7 @@ 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);
 	nr->n2     =
Signature · 1 line
2.37.3
author
#5 lore raw

PATCH 5/12 netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/af_netrom.c +1 -1
index 4d0e0834d527..312fc745db7f 100644
@@ -457,7 +457,7 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,
 	nr->t2     =
 		msecs_to_jiffies(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);
 	nr->idle   =
Signature · 1 line
2.37.3
author
#6 lore raw

PATCH 6/12 netrom: Fix a data-race around sysctl_netrom_transport_acknowledge_delay

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/af_netrom.c +1 -1
index 312fc745db7f..8ada0da3c0e0 100644
@@ -455,7 +455,7 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,
 	nr->t1     =
 		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(READ_ONCE(sysctl_netrom_transport_maximum_tries));
 	nr->t4     =
Signature · 1 line
2.37.3
author
#7 lore raw

PATCH 7/12 netrom: Fix a data-race around sysctl_netrom_transport_busy_delay

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/af_netrom.c +1 -1
index 8ada0da3c0e0..10eee02ef99e 100644
@@ -459,7 +459,7 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,
 	nr->n2     =
 		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;
Signature · 1 line
2.37.3
author
#8 lore raw

PATCH 8/12 netrom: Fix a data-race around sysctl_netrom_transport_requested_window_size

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/af_netrom.c +1 -1
index 10eee02ef99e..e65418fb9d88 100644
@@ -462,7 +462,7 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,
 		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;
+	nr->window = READ_ONCE(sysctl_netrom_transport_requested_window_size);
 
 	nr->bpqext = 1;
 	nr->state  = NR_STATE_0;
Signature · 1 line
2.37.3
author
#9 lore raw

PATCH 9/12 netrom: Fix a data-race around sysctl_netrom_transport_no_activity_timeout

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/af_netrom.c +1 -1
index e65418fb9d88..1671be042ffe 100644
@@ -461,7 +461,7 @@ static int nr_create(struct net *net, struct socket *sock, int protocol,
 	nr->t4     =
 		msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_busy_delay));
 	nr->idle   =
-		msecs_to_jiffies(sysctl_netrom_transport_no_activity_timeout);
+		msecs_to_jiffies(READ_ONCE(sysctl_netrom_transport_no_activity_timeout));
 	nr->window = READ_ONCE(sysctl_netrom_transport_requested_window_size);
 
 	nr->bpqext = 1;
Signature · 1 line
2.37.3
author
#10 lore raw

PATCH 10/12 netrom: Fix a data-race around sysctl_netrom_routing_control

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/nr_route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/nr_route.c +1 -1
index b8ddd8048f35..89e12e6eea2e 100644
@@ -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 */
Signature · 1 line
2.37.3
author
#11 lore raw

PATCH 11/12 netrom: Fix a data-race around sysctl_netrom_link_fails_count

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/nr_route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netrom/nr_route.c +1 -1
index 89e12e6eea2e..70480869ad1c 100644
@@ -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;
 	}
Signature · 1 line
2.37.3
author
#12 lore raw

PATCH 12/12 netrom: Fix data-races around sysctl_net_busy_read

In reply to Jason Xing

From: Jason Xing <[email protected]>

We need to protect the reader reading the sysctl value because the value can be changed concurrently.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/netrom/af_netrom.c | 2 +-
 net/netrom/nr_in.c     | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
net/netrom/af_netrom.c +1 -1
index 1671be042ffe..104a80b75477 100644
@@ -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);
 
net/netrom/nr_in.c +3 -3
index 2f084b6f69d7..97944db6b5ac 100644
@@ -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;
 
@@ -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;
 
@@ -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;
 
Signature · 1 line
2.37.3
maintainer
#13 lore raw
In reply to Jason Xing

Hi,

Quoted 2 lines · Jason Xing

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.

I hope this is not a one-shot effort. I think there is quite a bit room for improvement in the x25/netrom land, e.g. starting from selftests, if you have time and will:)

The patches LGTM, I'm applying them.

Cheers,

Paolo

author
#14 lore raw
Quoted 10 lines · Paolo Abeni

Hi,

Quoted 2 lines · Jason Xing

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.

I hope this is not a one-shot effort. I think there is quite a bit room for improvement in the x25/netrom land, e.g. starting from selftests, if you have time and will:)

Yes, I'm trying to make time to learn it after work, like fixing issues that syzbot reports, since Ralf seems inactive in recent years. I hope I can take it...

Quoted 2 lines

The patches LGTM, I'm applying them.

Thanks!

Quoted 5 lines

Cheers,

Paolo

#15 lore raw
In reply to Jason Xing
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 23 lines · On Mon, 4 Mar 2024 16:20:34 +0800 you wrote:

From: Jason Xing <[email protected]>

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.

Jason Xing (12):
netrom: Fix a data-race around sysctl_netrom_default_path_quality
netrom: Fix a data-race around
sysctl_netrom_obsolescence_count_initialiser
netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser
netrom: Fix a data-race around sysctl_netrom_transport_timeout
netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries
netrom: Fix a data-race around
sysctl_netrom_transport_acknowledge_delay
netrom: Fix a data-race around sysctl_netrom_transport_busy_delay
netrom: Fix a data-race around
sysctl_netrom_transport_requested_window_size
netrom: Fix a data-race around
sysctl_netrom_transport_no_activity_timeout
netrom: Fix a data-race around sysctl_netrom_routing_control
netrom: Fix a data-race around sysctl_netrom_link_fails_count
netrom: Fix data-races around sysctl_net_busy_read

Quoted 1 line

[...]

Here is the summary with links:
- [net,01/12] netrom: Fix a data-race around sysctl_netrom_default_path_quality

    https://git.kernel.org/netdev/net/c/958d6145a6d9
  - [net,02/12] netrom: Fix a data-race around sysctl_netrom_obsolescence_count_initialiser
    https://git.kernel.org/netdev/net/c/cfd9f4a740f7
  - [net,03/12] netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser
    https://git.kernel.org/netdev/net/c/119cae5ea3f9
  - [net,04/12] netrom: Fix a data-race around sysctl_netrom_transport_timeout
    https://git.kernel.org/netdev/net/c/60a7a152abd4
  - [net,05/12] netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries
    https://git.kernel.org/netdev/net/c/e799299aafed
  - [net,06/12] netrom: Fix a data-race around sysctl_netrom_transport_acknowledge_delay
    https://git.kernel.org/netdev/net/c/806f462ba902
  - [net,07/12] netrom: Fix a data-race around sysctl_netrom_transport_busy_delay
    https://git.kernel.org/netdev/net/c/43547d869943
  - [net,08/12] netrom: Fix a data-race around sysctl_netrom_transport_requested_window_size
    https://git.kernel.org/netdev/net/c/a2e706841488
  - [net,09/12] netrom: Fix a data-race around sysctl_netrom_transport_no_activity_timeout
    https://git.kernel.org/netdev/net/c/f99b494b4043
  - [net,10/12] netrom: Fix a data-race around sysctl_netrom_routing_control
    https://git.kernel.org/netdev/net/c/b5dffcb8f71b
  - [net,11/12] netrom: Fix a data-race around sysctl_netrom_link_fails_count
    https://git.kernel.org/netdev/net/c/bc76645ebdd0
  - [net,12/12] netrom: Fix data-races around sysctl_net_busy_read
    https://git.kernel.org/netdev/net/c/d380ce70058a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html