The branch main has been updated by kevans:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=25529f11cff891139bbddb257f54fcd67c1b3ef7

commit 25529f11cff891139bbddb257f54fcd67c1b3ef7
Author:     Kyle Evans <kev...@freebsd.org>
AuthorDate: 2021-03-15 06:23:56 +0000
Commit:     Kyle Evans <kev...@freebsd.org>
CommitDate: 2021-03-15 06:23:56 +0000

    if_wg: close the sockets if wg_socket_bind() failed
    
    This fixes the remaining cred leak that prevented jails from fully dying
    in some error cases.
---
 sys/dev/if_wg/if_wg.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/sys/dev/if_wg/if_wg.c b/sys/dev/if_wg/if_wg.c
index 4d5c66133a8f..8c11cc58a3bb 100644
--- a/sys/dev/if_wg/if_wg.c
+++ b/sys/dev/if_wg/if_wg.c
@@ -952,6 +952,7 @@ wg_socket_init(struct wg_softc *sc, in_port_t port)
 
        sx_assert(&sc->sc_lock, SX_XLOCKED);
 
+       so4 = so6 = NULL;
        td = curthread;
        if ((cred = sc->sc_ucred) == NULL)
                return (EBUSY);
@@ -965,7 +966,7 @@ wg_socket_init(struct wg_softc *sc, in_port_t port)
         * to the network.
         */
        rc = socreate(AF_INET, &so4, SOCK_DGRAM, IPPROTO_UDP, cred, td);
-       if (rc)
+       if (rc != 0)
                goto out;
 
        rc = udp_set_kernel_tunneling(so4, wg_input, NULL, sc);
@@ -976,11 +977,8 @@ wg_socket_init(struct wg_softc *sc, in_port_t port)
        MPASS(rc == 0);
 
        rc = socreate(AF_INET6, &so6, SOCK_DGRAM, IPPROTO_UDP, cred, td);
-       if (rc) {
-               SOCK_LOCK(so4);
-               sofree(so4);
+       if (rc != 0)
                goto out;
-       }
        rc = udp_set_kernel_tunneling(so6, wg_input, NULL, sc);
        MPASS(rc == 0);
 
@@ -992,6 +990,12 @@ wg_socket_init(struct wg_softc *sc, in_port_t port)
                wg_socket_set(sc, so4, so6);
        }
 out:
+       if (rc != 0) {
+               if (so4 != NULL)
+                       soclose(so4);
+               if (so6 != NULL)
+                       soclose(so6);
+       }
        return (rc);
 }
 
_______________________________________________
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"

Reply via email to