Re: fix a wireguard mbuf leak

2023-09-22 Thread Alexander Bluhm
On Fri, Sep 22, 2023 at 12:21:42PM +0900, YASUOKA Masahiko wrote:
> A leak may happens when wgpeer is deleted.
> 
> ok?

OK bluhm@

> The state queue should be freeed when wg_peer is destroyed.
> diff from IIJ.
> 
> Index: sys/net/if_wg.c
> ===
> RCS file: /disk/cvs/openbsd/src/sys/net/if_wg.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 if_wg.c
> --- sys/net/if_wg.c   3 Aug 2023 09:49:08 -   1.29
> +++ sys/net/if_wg.c   22 Sep 2023 03:11:47 -
> @@ -518,6 +518,9 @@ wg_peer_destroy(struct wg_peer *peer)
>   taskq_barrier(wg_crypt_taskq);
>   taskq_barrier(net_tq(sc->sc_if.if_index));
>  
> + if (!mq_empty(>p_stage_queue))
> + mq_purge(>p_stage_queue);
> +
>   DPRINTF(sc, "Peer %llu destroyed\n", peer->p_id);
>   explicit_bzero(peer, sizeof(*peer));
>   pool_put(_peer_pool, peer);



Re: fix a wireguard mbuf leak

2023-09-22 Thread Vitaliy Makkoveev
On Fri, Sep 22, 2023 at 12:21:42PM +0900, YASUOKA Masahiko wrote:
> A leak may happens when wgpeer is deleted.
> 
> ok?
> 

ok mvs@

> The state queue should be freeed when wg_peer is destroyed.
> diff from IIJ.
> 
> Index: sys/net/if_wg.c
> ===
> RCS file: /disk/cvs/openbsd/src/sys/net/if_wg.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 if_wg.c
> --- sys/net/if_wg.c   3 Aug 2023 09:49:08 -   1.29
> +++ sys/net/if_wg.c   22 Sep 2023 03:11:47 -
> @@ -518,6 +518,9 @@ wg_peer_destroy(struct wg_peer *peer)
>   taskq_barrier(wg_crypt_taskq);
>   taskq_barrier(net_tq(sc->sc_if.if_index));
>  
> + if (!mq_empty(>p_stage_queue))
> + mq_purge(>p_stage_queue);
> +
>   DPRINTF(sc, "Peer %llu destroyed\n", peer->p_id);
>   explicit_bzero(peer, sizeof(*peer));
>   pool_put(_peer_pool, peer);
> 



fix a wireguard mbuf leak

2023-09-21 Thread YASUOKA Masahiko
A leak may happens when wgpeer is deleted.

ok?

The state queue should be freeed when wg_peer is destroyed.
diff from IIJ.

Index: sys/net/if_wg.c
===
RCS file: /disk/cvs/openbsd/src/sys/net/if_wg.c,v
retrieving revision 1.29
diff -u -p -r1.29 if_wg.c
--- sys/net/if_wg.c 3 Aug 2023 09:49:08 -   1.29
+++ sys/net/if_wg.c 22 Sep 2023 03:11:47 -
@@ -518,6 +518,9 @@ wg_peer_destroy(struct wg_peer *peer)
taskq_barrier(wg_crypt_taskq);
taskq_barrier(net_tq(sc->sc_if.if_index));
 
+   if (!mq_empty(>p_stage_queue))
+   mq_purge(>p_stage_queue);
+
DPRINTF(sc, "Peer %llu destroyed\n", peer->p_id);
explicit_bzero(peer, sizeof(*peer));
pool_put(_peer_pool, peer);