* [PATCH net v2] rxrpc: Fix data-race warning and potential load/store tearing
@ 2026-01-14 21:36 David Howells
2026-01-18 0:24 ` [net,v2] " Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: David Howells @ 2026-01-14 21:36 UTC (permalink / raw)
To: netdev
Cc: dhowells, syzbot+6182afad5045e6703b3d, Marc Dionne, Eric Dumazet,
David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-afs, stable, linux-kernel
Fix the following:
BUG: KCSAN: data-race in rxrpc_peer_keepalive_worker / rxrpc_send_data_packet
which is reporting an issue with the reads and writes to ->last_tx_at in:
conn->peer->last_tx_at = ktime_get_seconds();
and:
keepalive_at = peer->last_tx_at + RXRPC_KEEPALIVE_TIME;
The lockless accesses to these to values aren't actually a problem as the
read only needs an approximate time of last transmission for the purposes
of deciding whether or not the transmission of a keepalive packet is
warranted yet.
Also, as ->last_tx_at is a 64-bit value, tearing can occur on a 32-bit
arch.
Fix both of these by switching to an unsigned int for ->last_tx_at and only
storing the LSW of the time64_t. It can then be reconstructed at need
provided no more than 68 years has elapsed since the last transmission.
Fixes: ace45bec6d77 ("rxrpc: Fix firewall route keepalive")
Reported-by: syzbot+6182afad5045e6703b3d@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/695e7cfb.050a0220.1c677c.036b.GAE@google.com/
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: "David S. Miller" <davem@davemloft.net>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: netdev@vger.kernel.org
cc: stable@kernel.org
---
Changes
=======
ver #2)
- Fix a format specifier to match the change in type of last_tx_at.
net/rxrpc/ar-internal.h | 9 ++++++++-
net/rxrpc/conn_event.c | 2 +-
net/rxrpc/output.c | 14 +++++++-------
net/rxrpc/peer_event.c | 17 ++++++++++++++++-
net/rxrpc/proc.c | 4 ++--
net/rxrpc/rxgk.c | 2 +-
net/rxrpc/rxkad.c | 2 +-
7 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 5b7342d43486..36d6ca0d1089 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -387,7 +387,7 @@ struct rxrpc_peer {
struct rb_root service_conns; /* Service connections */
struct list_head keepalive_link; /* Link in net->peer_keepalive[] */
unsigned long app_data; /* Application data (e.g. afs_server) */
- time64_t last_tx_at; /* Last time packet sent here */
+ unsigned int last_tx_at; /* Last time packet sent here (time64_t LSW) */
seqlock_t service_conn_lock;
spinlock_t lock; /* access lock */
int debug_id; /* debug ID for printks */
@@ -1379,6 +1379,13 @@ void rxrpc_peer_keepalive_worker(struct work_struct *);
void rxrpc_input_probe_for_pmtud(struct rxrpc_connection *conn, rxrpc_serial_t acked_serial,
bool sendmsg_fail);
+/* Update the last transmission time on a peer for keepalive purposes. */
+static inline void rxrpc_peer_mark_tx(struct rxrpc_peer *peer)
+{
+ /* To avoid tearing on 32-bit systems, we only keep the LSW. */
+ WRITE_ONCE(peer->last_tx_at, ktime_get_seconds());
+}
+
/*
* peer_object.c
*/
diff --git a/net/rxrpc/conn_event.c b/net/rxrpc/conn_event.c
index 232b6986da83..98ad9b51ca2c 100644
--- a/net/rxrpc/conn_event.c
+++ b/net/rxrpc/conn_event.c
@@ -194,7 +194,7 @@ void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn,
}
ret = kernel_sendmsg(conn->local->socket, &msg, iov, ioc, len);
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
if (ret < 0)
trace_rxrpc_tx_fail(chan->call_debug_id, serial, ret,
rxrpc_tx_point_call_final_resend);
diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c
index 8b5903b6e481..d70db367e358 100644
--- a/net/rxrpc/output.c
+++ b/net/rxrpc/output.c
@@ -275,7 +275,7 @@ static void rxrpc_send_ack_packet(struct rxrpc_call *call, int nr_kv, size_t len
rxrpc_local_dont_fragment(conn->local, why == rxrpc_propose_ack_ping_for_mtu_probe);
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
- call->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(call->peer);
if (ret < 0) {
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
rxrpc_tx_point_call_ack);
@@ -411,7 +411,7 @@ int rxrpc_send_abort_packet(struct rxrpc_call *call)
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt));
ret = do_udp_sendmsg(conn->local->socket, &msg, sizeof(pkt));
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
if (ret < 0)
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
rxrpc_tx_point_call_abort);
@@ -698,7 +698,7 @@ void rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_send_data_req
ret = 0;
trace_rxrpc_tx_data(call, txb->seq, txb->serial, txb->flags,
rxrpc_txdata_inject_loss);
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
goto done;
}
}
@@ -711,7 +711,7 @@ void rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_send_data_req
*/
rxrpc_inc_stat(call->rxnet, stat_tx_data_send);
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
if (ret == -EMSGSIZE) {
rxrpc_inc_stat(call->rxnet, stat_tx_data_send_msgsize);
@@ -797,7 +797,7 @@ void rxrpc_send_conn_abort(struct rxrpc_connection *conn)
trace_rxrpc_tx_packet(conn->debug_id, &whdr, rxrpc_tx_point_conn_abort);
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
}
/*
@@ -917,7 +917,7 @@ void rxrpc_send_keepalive(struct rxrpc_peer *peer)
trace_rxrpc_tx_packet(peer->debug_id, &whdr,
rxrpc_tx_point_version_keepalive);
- peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(peer);
_leave("");
}
@@ -973,7 +973,7 @@ void rxrpc_send_response(struct rxrpc_connection *conn, struct sk_buff *response
if (ret < 0)
goto fail;
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
return;
fail:
diff --git a/net/rxrpc/peer_event.c b/net/rxrpc/peer_event.c
index 7f4729234957..9d02448ac062 100644
--- a/net/rxrpc/peer_event.c
+++ b/net/rxrpc/peer_event.c
@@ -237,6 +237,21 @@ static void rxrpc_distribute_error(struct rxrpc_peer *peer, struct sk_buff *skb,
spin_unlock_irq(&peer->lock);
}
+/*
+ * Reconstruct the last transmission time. The difference calculated should be
+ * valid provided no more than ~68 years elapsed since the last transmission.
+ */
+static time64_t rxrpc_peer_get_tx_mark(const struct rxrpc_peer *peer, time64_t base)
+{
+ s32 last_tx_at = READ_ONCE(peer->last_tx_at);
+ s32 base_lsw = base;
+ s32 diff = last_tx_at - base_lsw;
+
+ diff = clamp(diff, -RXRPC_KEEPALIVE_TIME, RXRPC_KEEPALIVE_TIME);
+
+ return diff + base;
+}
+
/*
* Perform keep-alive pings.
*/
@@ -265,7 +280,7 @@ static void rxrpc_peer_keepalive_dispatch(struct rxrpc_net *rxnet,
spin_unlock_bh(&rxnet->peer_hash_lock);
if (use) {
- keepalive_at = peer->last_tx_at + RXRPC_KEEPALIVE_TIME;
+ keepalive_at = rxrpc_peer_get_tx_mark(peer, base) + RXRPC_KEEPALIVE_TIME;
slot = keepalive_at - base;
_debug("%02x peer %u t=%d {%pISp}",
cursor, peer->debug_id, slot, &peer->srx.transport);
diff --git a/net/rxrpc/proc.c b/net/rxrpc/proc.c
index d803562ca0ac..ce4fd1af79ba 100644
--- a/net/rxrpc/proc.c
+++ b/net/rxrpc/proc.c
@@ -296,13 +296,13 @@ static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
now = ktime_get_seconds();
seq_printf(seq,
- "UDP %-47.47s %-47.47s %3u %4u %5u %6llus %8d %8d\n",
+ "UDP %-47.47s %-47.47s %3u %4u %5u %6ds %8d %8d\n",
lbuff,
rbuff,
refcount_read(&peer->ref),
peer->cong_ssthresh,
peer->max_data,
- now - peer->last_tx_at,
+ (s32)now - (s32)peer->last_tx_at,
READ_ONCE(peer->recent_srtt_us),
READ_ONCE(peer->recent_rto_us));
diff --git a/net/rxrpc/rxgk.c b/net/rxrpc/rxgk.c
index dce5a3d8a964..43cbf9efd89f 100644
--- a/net/rxrpc/rxgk.c
+++ b/net/rxrpc/rxgk.c
@@ -678,7 +678,7 @@ static int rxgk_issue_challenge(struct rxrpc_connection *conn)
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
if (ret > 0)
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
__free_page(page);
if (ret < 0) {
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 3657c0661cdc..a756855a0a62 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -694,7 +694,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
return -EAGAIN;
}
- conn->peer->last_tx_at = ktime_get_seconds();
+ rxrpc_peer_mark_tx(conn->peer);
trace_rxrpc_tx_packet(conn->debug_id, &whdr,
rxrpc_tx_point_rxkad_challenge);
_leave(" = 0");
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [net,v2] rxrpc: Fix data-race warning and potential load/store tearing
2026-01-14 21:36 [PATCH net v2] rxrpc: Fix data-race warning and potential load/store tearing David Howells
@ 2026-01-18 0:24 ` Jakub Kicinski
2026-01-18 12:03 ` David Howells
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2026-01-18 0:24 UTC (permalink / raw)
To: dhowells; +Cc: Jakub Kicinski, netdev
Hi,
This is an AI-generated review of your patch.
Bit of a nit pick but... I guess so..?
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
rxrpc: Fix data-race warning and potential load/store tearing
This commit fixes a KCSAN data-race warning on peer->last_tx_at by changing
it from time64_t to unsigned int (to prevent tearing on 32-bit) and adding
WRITE_ONCE/READ_ONCE annotations for the accesses.
Closes: https://lore.kernel.org/r/695e7cfb.050a0220.1c677c.036b.GAE@google.com/
> diff --git a/net/rxrpc/peer_event.c b/net/rxrpc/peer_event.c
> index 7f4729234957..9d02448ac062 100644
[ ... ]
> +static time64_t rxrpc_peer_get_tx_mark(const struct rxrpc_peer *peer, time64_t base)
> +{
> + s32 last_tx_at = READ_ONCE(peer->last_tx_at);
[ ... ]
> diff --git a/net/rxrpc/proc.c b/net/rxrpc/proc.c
> index d803562ca0ac..ce4fd1af79ba 100644
> --- a/net/rxrpc/proc.c
> +++ b/net/rxrpc/proc.c
> @@ -296,13 +296,13 @@ static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
>
> now = ktime_get_seconds();
> seq_printf(seq,
> - "UDP %-47.47s %-47.47s %3u %4u %5u %6llus %8d %8d\n",
> + "UDP %-47.47s %-47.47s %3u %4u %5u %6ds %8d %8d\n",
> lbuff,
> rbuff,
> refcount_read(&peer->ref),
> peer->cong_ssthresh,
> peer->max_data,
> - now - peer->last_tx_at,
> + (s32)now - (s32)peer->last_tx_at,
^^^^^^^^^^^^^^^^^
Should this read use READ_ONCE(peer->last_tx_at) for consistency with the
data-race fix? The new rxrpc_peer_get_tx_mark() uses READ_ONCE for the
same field, and the same seq_printf uses READ_ONCE for recent_srtt_us and
recent_rto_us on the following lines.
> + READ_ONCE(peer->recent_srtt_us),
> + READ_ONCE(peer->recent_rto_us));
--
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [net,v2] rxrpc: Fix data-race warning and potential load/store tearing
2026-01-18 0:24 ` [net,v2] " Jakub Kicinski
@ 2026-01-18 12:03 ` David Howells
2026-01-19 17:39 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: David Howells @ 2026-01-18 12:03 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: dhowells, netdev
Jakub Kicinski <kuba@kernel.org> wrote:
> > + (s32)now - (s32)peer->last_tx_at,
> ^^^^^^^^^^^^^^^^^
>
> Should this read use READ_ONCE(peer->last_tx_at) for consistency with the
> data-race fix? The new rxrpc_peer_get_tx_mark() uses READ_ONCE for the
> same field, and the same seq_printf uses READ_ONCE for recent_srtt_us and
> recent_rto_us on the following lines.
I suppose. Racing doesn't matter here as it's just displaying the value;
tearing might matter, but it's now a 32-bit field.
David
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net,v2] rxrpc: Fix data-race warning and potential load/store tearing
2026-01-18 12:03 ` David Howells
@ 2026-01-19 17:39 ` Jakub Kicinski
2026-01-19 23:46 ` David Howells
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2026-01-19 17:39 UTC (permalink / raw)
To: David Howells; +Cc: netdev
On Sun, 18 Jan 2026 12:03:01 +0000 David Howells wrote:
> Jakub Kicinski <kuba@kernel.org> wrote:
>
> > > + (s32)now - (s32)peer->last_tx_at,
> > ^^^^^^^^^^^^^^^^^
> >
> > Should this read use READ_ONCE(peer->last_tx_at) for consistency with the
> > data-race fix? The new rxrpc_peer_get_tx_mark() uses READ_ONCE for the
> > same field, and the same seq_printf uses READ_ONCE for recent_srtt_us and
> > recent_rto_us on the following lines.
>
> I suppose. Racing doesn't matter here as it's just displaying the value;
> tearing might matter, but it's now a 32-bit field.
Right, total nit pick. It's mostly for consistency with other fields in
the same print statement that are READ_ONCE()d.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-19 23:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 21:36 [PATCH net v2] rxrpc: Fix data-race warning and potential load/store tearing David Howells
2026-01-18 0:24 ` [net,v2] " Jakub Kicinski
2026-01-18 12:03 ` David Howells
2026-01-19 17:39 ` Jakub Kicinski
2026-01-19 23:46 ` David Howells
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox