From nobody Tue Jul 02 04:58:17 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WCrJn6Bx2z5PDWX; Tue, 02 Jul 2024 04:58:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WCrJn5clFz3x9m; Tue, 2 Jul 2024 04:58:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719896297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dYXeAok3IcEsZlf2I2sBKcLnEXnmC8udrLt7s5EX8Ak=; b=XKFCqKefNlVGprtKNgMNpLchu5s+AfBOqT5kt8zc7DpQe5BzHkVAmZNKT1ly51FhrOK7Sy gglIe6tj2eIr1VtY4XI38SqzBQB93OdutWZFXUgG96ePxMcQZKX7YugsQ4PBWobQhTchtV rMxFVmQapxVY6qMNTFvO80CreF88JylYBeC6P9tSXNkTNgI8DgPe+/7tcIY2b/vClfqpfF DPmeiwr/HdfUhlzVJ1os1V4YKXrhkw7OwvTtdx+YRFR/iywr60UD9V99CcnsHvl8Ca7TmW s2MgcZZPcAOErI6R1KIgyKcJhkDO8fuc2GLe1K3/ZJNO7BxAoQO5tUnQdWFV1w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1719896297; a=rsa-sha256; cv=none; b=TnR0iunNcPhES4zSn2qSv3zFxgDMdXUtFhyJPasaKP7zyOElrNVDemd4DYC+datBQtW8LX QZ3IOeDIR1kHR5bcHL0lxOWyzcOXlucIcDpFYiKbCkt5BeIusha40BR4gX+azqLQumeQMp 6zqrAlGysFnwHJEZPfKWgkoSEy9mb/4nvrjdkFIQJEg0hq/bWU07CG9zqC5XkBRxKa+sB9 zaec7oV9QFUGTUgKCAc/PjGwkUUgs0uFgNCA5EbXeAix/0wFxgGfj5bi0N4EsJ13ectIcf M0Eej7/Gx+fE565xzGevbloeLTjX2D2RLJ7AA8STVG4VRIrIaDGORD4MNkYeXw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1719896297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dYXeAok3IcEsZlf2I2sBKcLnEXnmC8udrLt7s5EX8Ak=; b=naoC1HNHybDYF6WuImNP8b8q4kwN3kw9BN1/vk6qo3H9NncGHbtRIQFGFLB1YlJBY38/tw JK1MH7mZn69feYHixXnivu/muK7yMHxSJL11Dm9v2PQ2SD1uGeTNCk/4kINFUkKa8+WmCe r2/c8jLfcSMCWvPzvZGJhgZ4CDVAlJ7AAFuE2WmaEjG0eK4zn3y7IPTtHYNlIVP5/b3R3h d25bYwgQisJs9nw8rLUaGYzP3T3kbuUB38E+eed7oKmsgr3fgEq2Nx534mEF/7QcWZY9z6 45nwOZc6kj2GBdZb7CzKKhYBjBdGgWn4BhjWUTKOVB/YBQS61gGyFVb9FuCx6w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WCrJn5F0fzZlj; Tue, 2 Jul 2024 04:58:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4624wHeU062942; Tue, 2 Jul 2024 04:58:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4624wHij062939; Tue, 2 Jul 2024 04:58:17 GMT (envelope-from git) Date: Tue, 2 Jul 2024 04:58:17 GMT Message-Id: <202407020458.4624wHij062939@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: 087f5e08ab5f - main - if_vxlan(4): Plug a memory leak List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 087f5e08ab5f0384163f76f73b9a91c98a3ba450 Auto-Submitted: auto-generated The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=087f5e08ab5f0384163f76f73b9a91c98a3ba450 commit 087f5e08ab5f0384163f76f73b9a91c98a3ba450 Author: Zhenlei Huang AuthorDate: 2024-07-02 04:57:02 +0000 Commit: Zhenlei Huang CommitDate: 2024-07-02 04:57:02 +0000 if_vxlan(4): Plug a memory leak On clone creating, either failure from vxlan_set_user_config() or ifc_copyin() will result in leaking previous allocated counters. Since counter_u64_alloc(M_WAITOK) never fails, make vxlan_stats_alloc() void and move the allocation for counters below checking ifd->params to avoid memory leak. Reviewed by: kp, glebius Fixes: b092fd6c973d if_vxlan(4): add support for hardware assisted checksumming, TSO, and RSS MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45822 --- sys/net/if_vxlan.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c index 05430768cc73..bb2de793550f 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -367,7 +367,7 @@ static bool vxlan_rcv_udp_packet(struct mbuf *, int, struct inpcb *, static int vxlan_input(struct vxlan_socket *, uint32_t, struct mbuf **, const struct sockaddr *); -static int vxlan_stats_alloc(struct vxlan_softc *); +static void vxlan_stats_alloc(struct vxlan_softc *); static void vxlan_stats_free(struct vxlan_softc *); static void vxlan_set_default_config(struct vxlan_softc *); static int vxlan_set_user_config(struct vxlan_softc *, @@ -2923,27 +2923,14 @@ out: return (error); } -static int +static void vxlan_stats_alloc(struct vxlan_softc *sc) { struct vxlan_statistics *stats = &sc->vxl_stats; stats->txcsum = counter_u64_alloc(M_WAITOK); - if (stats->txcsum == NULL) - goto failed; - stats->tso = counter_u64_alloc(M_WAITOK); - if (stats->tso == NULL) - goto failed; - stats->rxcsum = counter_u64_alloc(M_WAITOK); - if (stats->rxcsum == NULL) - goto failed; - - return (0); -failed: - vxlan_stats_free(sc); - return (ENOMEM); } static void @@ -2951,18 +2938,9 @@ vxlan_stats_free(struct vxlan_softc *sc) { struct vxlan_statistics *stats = &sc->vxl_stats; - if (stats->txcsum != NULL) { - counter_u64_free(stats->txcsum); - stats->txcsum = NULL; - } - if (stats->tso != NULL) { - counter_u64_free(stats->tso); - stats->tso = NULL; - } - if (stats->rxcsum != NULL) { - counter_u64_free(stats->rxcsum); - stats->rxcsum = NULL; - } + counter_u64_free(stats->txcsum); + counter_u64_free(stats->tso); + counter_u64_free(stats->rxcsum); } static void @@ -3233,9 +3211,6 @@ vxlan_clone_create(struct if_clone *ifc, char *name, size_t len, sc->vxl_unit = ifd->unit; sc->vxl_fibnum = curthread->td_proc->p_fibnum; vxlan_set_default_config(sc); - error = vxlan_stats_alloc(sc); - if (error != 0) - goto fail; if (ifd->params != NULL) { error = ifc_copyin(ifd, &vxlp, sizeof(vxlp)); @@ -3247,6 +3222,7 @@ vxlan_clone_create(struct if_clone *ifc, char *name, size_t len, goto fail; } + vxlan_stats_alloc(sc); ifp = if_alloc(IFT_ETHER); sc->vxl_ifp = ifp; rm_init(&sc->vxl_lock, "vxlanrm");