* [PATCH net] xfrm: fix a data-race in xfrm_lookup_with_ifid()
@ 2023-10-11 10:24 Eric Dumazet
2023-10-13 15:22 ` Simon Horman
2023-10-16 5:45 ` Steffen Klassert
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-10-11 10:24 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Steffen Klassert
syzbot complains about a race in xfrm_lookup_with_ifid() [1]
When preparing commit 0a9e5794b21e ("xfrm: annotate data-race
around use_time") I thought xfrm_lookup_with_ifid() was modifying
a still private structure.
[1]
BUG: KCSAN: data-race in xfrm_lookup_with_ifid / xfrm_lookup_with_ifid
write to 0xffff88813ea41108 of 8 bytes by task 8150 on cpu 1:
xfrm_lookup_with_ifid+0xce7/0x12d0 net/xfrm/xfrm_policy.c:3218
xfrm_lookup net/xfrm/xfrm_policy.c:3270 [inline]
xfrm_lookup_route+0x3b/0x100 net/xfrm/xfrm_policy.c:3281
ip6_dst_lookup_flow+0x98/0xc0 net/ipv6/ip6_output.c:1246
send6+0x241/0x3c0 drivers/net/wireguard/socket.c:139
wg_socket_send_skb_to_peer+0xbd/0x130 drivers/net/wireguard/socket.c:178
wg_socket_send_buffer_to_peer+0xd6/0x100 drivers/net/wireguard/socket.c:200
wg_packet_send_handshake_initiation drivers/net/wireguard/send.c:40 [inline]
wg_packet_handshake_send_worker+0x10c/0x150 drivers/net/wireguard/send.c:51
process_one_work kernel/workqueue.c:2630 [inline]
process_scheduled_works+0x5b8/0xa30 kernel/workqueue.c:2703
worker_thread+0x525/0x730 kernel/workqueue.c:2784
kthread+0x1d7/0x210 kernel/kthread.c:388
ret_from_fork+0x48/0x60 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
write to 0xffff88813ea41108 of 8 bytes by task 15867 on cpu 0:
xfrm_lookup_with_ifid+0xce7/0x12d0 net/xfrm/xfrm_policy.c:3218
xfrm_lookup net/xfrm/xfrm_policy.c:3270 [inline]
xfrm_lookup_route+0x3b/0x100 net/xfrm/xfrm_policy.c:3281
ip6_dst_lookup_flow+0x98/0xc0 net/ipv6/ip6_output.c:1246
send6+0x241/0x3c0 drivers/net/wireguard/socket.c:139
wg_socket_send_skb_to_peer+0xbd/0x130 drivers/net/wireguard/socket.c:178
wg_socket_send_buffer_to_peer+0xd6/0x100 drivers/net/wireguard/socket.c:200
wg_packet_send_handshake_initiation drivers/net/wireguard/send.c:40 [inline]
wg_packet_handshake_send_worker+0x10c/0x150 drivers/net/wireguard/send.c:51
process_one_work kernel/workqueue.c:2630 [inline]
process_scheduled_works+0x5b8/0xa30 kernel/workqueue.c:2703
worker_thread+0x525/0x730 kernel/workqueue.c:2784
kthread+0x1d7/0x210 kernel/kthread.c:388
ret_from_fork+0x48/0x60 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
value changed: 0x00000000651cd9d1 -> 0x00000000651cd9d2
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 PID: 15867 Comm: kworker/u4:58 Not tainted 6.6.0-rc4-syzkaller-00016-g5e62ed3b1c8a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023
Workqueue: wg-kex-wg2 wg_packet_handshake_send_worker
Fixes: 0a9e5794b21e ("xfrm: annotate data-race around use_time")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
---
net/xfrm/xfrm_policy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index a73e4b66c98f9db98d94a146bc963fa29979c592..1058530d2a7235abe0f051e26695efbfc84feb33 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3213,7 +3213,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
}
for (i = 0; i < num_pols; i++)
- pols[i]->curlft.use_time = ktime_get_real_seconds();
+ WRITE_ONCE(pols[i]->curlft.use_time, ktime_get_real_seconds());
if (num_xfrms < 0) {
/* Prohibit the flow */
--
2.42.0.609.gbb76f46606-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net] xfrm: fix a data-race in xfrm_lookup_with_ifid()
2023-10-11 10:24 [PATCH net] xfrm: fix a data-race in xfrm_lookup_with_ifid() Eric Dumazet
@ 2023-10-13 15:22 ` Simon Horman
2023-10-16 5:45 ` Steffen Klassert
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2023-10-13 15:22 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, syzbot, Steffen Klassert
On Wed, Oct 11, 2023 at 10:24:29AM +0000, Eric Dumazet wrote:
> syzbot complains about a race in xfrm_lookup_with_ifid() [1]
>
> When preparing commit 0a9e5794b21e ("xfrm: annotate data-race
> around use_time") I thought xfrm_lookup_with_ifid() was modifying
> a still private structure.
>
> [1]
> BUG: KCSAN: data-race in xfrm_lookup_with_ifid / xfrm_lookup_with_ifid
>
> write to 0xffff88813ea41108 of 8 bytes by task 8150 on cpu 1:
> xfrm_lookup_with_ifid+0xce7/0x12d0 net/xfrm/xfrm_policy.c:3218
> xfrm_lookup net/xfrm/xfrm_policy.c:3270 [inline]
> xfrm_lookup_route+0x3b/0x100 net/xfrm/xfrm_policy.c:3281
> ip6_dst_lookup_flow+0x98/0xc0 net/ipv6/ip6_output.c:1246
> send6+0x241/0x3c0 drivers/net/wireguard/socket.c:139
> wg_socket_send_skb_to_peer+0xbd/0x130 drivers/net/wireguard/socket.c:178
> wg_socket_send_buffer_to_peer+0xd6/0x100 drivers/net/wireguard/socket.c:200
> wg_packet_send_handshake_initiation drivers/net/wireguard/send.c:40 [inline]
> wg_packet_handshake_send_worker+0x10c/0x150 drivers/net/wireguard/send.c:51
> process_one_work kernel/workqueue.c:2630 [inline]
> process_scheduled_works+0x5b8/0xa30 kernel/workqueue.c:2703
> worker_thread+0x525/0x730 kernel/workqueue.c:2784
> kthread+0x1d7/0x210 kernel/kthread.c:388
> ret_from_fork+0x48/0x60 arch/x86/kernel/process.c:147
> ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
>
> write to 0xffff88813ea41108 of 8 bytes by task 15867 on cpu 0:
> xfrm_lookup_with_ifid+0xce7/0x12d0 net/xfrm/xfrm_policy.c:3218
> xfrm_lookup net/xfrm/xfrm_policy.c:3270 [inline]
> xfrm_lookup_route+0x3b/0x100 net/xfrm/xfrm_policy.c:3281
> ip6_dst_lookup_flow+0x98/0xc0 net/ipv6/ip6_output.c:1246
> send6+0x241/0x3c0 drivers/net/wireguard/socket.c:139
> wg_socket_send_skb_to_peer+0xbd/0x130 drivers/net/wireguard/socket.c:178
> wg_socket_send_buffer_to_peer+0xd6/0x100 drivers/net/wireguard/socket.c:200
> wg_packet_send_handshake_initiation drivers/net/wireguard/send.c:40 [inline]
> wg_packet_handshake_send_worker+0x10c/0x150 drivers/net/wireguard/send.c:51
> process_one_work kernel/workqueue.c:2630 [inline]
> process_scheduled_works+0x5b8/0xa30 kernel/workqueue.c:2703
> worker_thread+0x525/0x730 kernel/workqueue.c:2784
> kthread+0x1d7/0x210 kernel/kthread.c:388
> ret_from_fork+0x48/0x60 arch/x86/kernel/process.c:147
> ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
>
> value changed: 0x00000000651cd9d1 -> 0x00000000651cd9d2
>
> Reported by Kernel Concurrency Sanitizer on:
> CPU: 0 PID: 15867 Comm: kworker/u4:58 Not tainted 6.6.0-rc4-syzkaller-00016-g5e62ed3b1c8a #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023
> Workqueue: wg-kex-wg2 wg_packet_handshake_send_worker
>
> Fixes: 0a9e5794b21e ("xfrm: annotate data-race around use_time")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Steffen Klassert <steffen.klassert@secunet.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] xfrm: fix a data-race in xfrm_lookup_with_ifid()
2023-10-11 10:24 [PATCH net] xfrm: fix a data-race in xfrm_lookup_with_ifid() Eric Dumazet
2023-10-13 15:22 ` Simon Horman
@ 2023-10-16 5:45 ` Steffen Klassert
1 sibling, 0 replies; 3+ messages in thread
From: Steffen Klassert @ 2023-10-16 5:45 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, syzbot
On Wed, Oct 11, 2023 at 10:24:29AM +0000, Eric Dumazet wrote:
> syzbot complains about a race in xfrm_lookup_with_ifid() [1]
>
> When preparing commit 0a9e5794b21e ("xfrm: annotate data-race
> around use_time") I thought xfrm_lookup_with_ifid() was modifying
> a still private structure.
>
> [1]
> BUG: KCSAN: data-race in xfrm_lookup_with_ifid / xfrm_lookup_with_ifid
>
> write to 0xffff88813ea41108 of 8 bytes by task 8150 on cpu 1:
> xfrm_lookup_with_ifid+0xce7/0x12d0 net/xfrm/xfrm_policy.c:3218
> xfrm_lookup net/xfrm/xfrm_policy.c:3270 [inline]
> xfrm_lookup_route+0x3b/0x100 net/xfrm/xfrm_policy.c:3281
> ip6_dst_lookup_flow+0x98/0xc0 net/ipv6/ip6_output.c:1246
> send6+0x241/0x3c0 drivers/net/wireguard/socket.c:139
> wg_socket_send_skb_to_peer+0xbd/0x130 drivers/net/wireguard/socket.c:178
> wg_socket_send_buffer_to_peer+0xd6/0x100 drivers/net/wireguard/socket.c:200
> wg_packet_send_handshake_initiation drivers/net/wireguard/send.c:40 [inline]
> wg_packet_handshake_send_worker+0x10c/0x150 drivers/net/wireguard/send.c:51
> process_one_work kernel/workqueue.c:2630 [inline]
> process_scheduled_works+0x5b8/0xa30 kernel/workqueue.c:2703
> worker_thread+0x525/0x730 kernel/workqueue.c:2784
> kthread+0x1d7/0x210 kernel/kthread.c:388
> ret_from_fork+0x48/0x60 arch/x86/kernel/process.c:147
> ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
>
> write to 0xffff88813ea41108 of 8 bytes by task 15867 on cpu 0:
> xfrm_lookup_with_ifid+0xce7/0x12d0 net/xfrm/xfrm_policy.c:3218
> xfrm_lookup net/xfrm/xfrm_policy.c:3270 [inline]
> xfrm_lookup_route+0x3b/0x100 net/xfrm/xfrm_policy.c:3281
> ip6_dst_lookup_flow+0x98/0xc0 net/ipv6/ip6_output.c:1246
> send6+0x241/0x3c0 drivers/net/wireguard/socket.c:139
> wg_socket_send_skb_to_peer+0xbd/0x130 drivers/net/wireguard/socket.c:178
> wg_socket_send_buffer_to_peer+0xd6/0x100 drivers/net/wireguard/socket.c:200
> wg_packet_send_handshake_initiation drivers/net/wireguard/send.c:40 [inline]
> wg_packet_handshake_send_worker+0x10c/0x150 drivers/net/wireguard/send.c:51
> process_one_work kernel/workqueue.c:2630 [inline]
> process_scheduled_works+0x5b8/0xa30 kernel/workqueue.c:2703
> worker_thread+0x525/0x730 kernel/workqueue.c:2784
> kthread+0x1d7/0x210 kernel/kthread.c:388
> ret_from_fork+0x48/0x60 arch/x86/kernel/process.c:147
> ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
>
> value changed: 0x00000000651cd9d1 -> 0x00000000651cd9d2
>
> Reported by Kernel Concurrency Sanitizer on:
> CPU: 0 PID: 15867 Comm: kworker/u4:58 Not tainted 6.6.0-rc4-syzkaller-00016-g5e62ed3b1c8a #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023
> Workqueue: wg-kex-wg2 wg_packet_handshake_send_worker
>
> Fixes: 0a9e5794b21e ("xfrm: annotate data-race around use_time")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Steffen Klassert <steffen.klassert@secunet.com>
Applied to the ipsec tree, thanks a lot Eric!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-16 5:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-11 10:24 [PATCH net] xfrm: fix a data-race in xfrm_lookup_with_ifid() Eric Dumazet
2023-10-13 15:22 ` Simon Horman
2023-10-16 5:45 ` Steffen Klassert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).