Module Name: src Committed By: riastradh Date: Mon Jul 29 18:43:11 UTC 2024
Modified Files: src/sys/net: if_wg.c Log Message: wg(4): Read wgs_state atomically in wg_get_stable_session. As noted in the comment above, it may concurrently transition from ESTABLISHED to DESTROYING. Post-fix tidying for: PR kern/55729: net/if_wg/t_misc:wg_rekey test case fails PR kern/56252: wg(4) state machine has race conditions PR kern/58463: if_wg does not work when idle. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/sys/net/if_wg.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_wg.c diff -u src/sys/net/if_wg.c:1.122 src/sys/net/if_wg.c:1.123 --- src/sys/net/if_wg.c:1.122 Mon Jul 29 16:02:05 2024 +++ src/sys/net/if_wg.c Mon Jul 29 18:43:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wg.c,v 1.122 2024/07/29 16:02:05 riastradh Exp $ */ +/* $NetBSD: if_wg.c,v 1.123 2024/07/29 18:43:11 riastradh Exp $ */ /* * Copyright (C) Ryota Ozaki <ozaki.ry...@gmail.com> @@ -41,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.122 2024/07/29 16:02:05 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.123 2024/07/29 18:43:11 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_altq_enabled.h" @@ -1297,7 +1297,8 @@ wg_get_stable_session(struct wg_peer *wg s = pserialize_read_enter(); wgs = atomic_load_consume(&wgp->wgp_session_stable); - if (__predict_false(wgs->wgs_state != WGS_STATE_ESTABLISHED)) + if (__predict_false(atomic_load_relaxed(&wgs->wgs_state) != + WGS_STATE_ESTABLISHED)) wgs = NULL; else psref_acquire(psref, &wgs->wgs_psref, wg_psref_class);