From nobody Wed Jul 10 11:45:21 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 4WJwyn42FVz5QJcd; Wed, 10 Jul 2024 11:45:21 +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 4WJwyn2CDBz49bn; Wed, 10 Jul 2024 11:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720611921; 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=0UGOYYIlDxgpbJUs83+8CPZpJoLviRWhiR37/v9ljT0=; b=FER4c0mv4n+bZfXUgKswk44ddViws4m1S4AsKP10kuRkL/Im0vc+8P4dDcVN1DsvwvuT4f 7w3P/nq79Cq3ukP2oqa9AVXbYz8A1sXxOu/YSPr+YQt8mUieOOGSRQ8nNrikMHuGweDYnY +MLbxFIFl0QlNlUa8dAN/3m4UKhWp9KkdPP3MHMyFi8lW2WBInGXP5zWK7NmPXATjjuTIi yaTLsYY2N4INrLxQ3JX9eSdNX3BtSeQHpcaN661rH51+7udstuN+ixntwpJhzBtR08m2Jh P92UoWrnT5d6UBvLbY0gZAnakOo4+bpySknAtNd5px8BpOFobARlyWZpWz9H9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720611921; a=rsa-sha256; cv=none; b=Tx+iA7zT+P+48aal2w3w1RjwdCebJhhTnEH/+uknveZaq+HK109J4EMOK3ba38CvZOIddh Gbv4cLex2KKtYobLZdos1wYwkW2NQIEPXIe6cjEEweUG8Ga83irraXczn+YiZBv5tXVEFk wkAPxUAHSKWL9+tajH7Ol8SdFrLVvm4go84AHev++zilKphOmp5C2t+lgTRvKLbsFZOs/5 AEYhmQWpCM8pNySUPdgjapaKNHI/ZFwcts+gUMd56kcS1S9/L/BP1/yt/vBXF5GTU56aU5 oYEEoR/5APP8GeHZypbJoq66IAE5tCZ7nxXMalgHRJ996kcJPdCP41Z80softg== 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=1720611921; 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=0UGOYYIlDxgpbJUs83+8CPZpJoLviRWhiR37/v9ljT0=; b=n0IjxiHUFAbBkhn66SJU9idfHYvbXvQ9ZMDcXN5G5SePVl/L6J6hhoQpVUnlVUniI6W6AD 8vsvOqSlkJtMIRBNEBISuxMxJwpJq6Js5782HrOcTMOr+UtqBgko8GGBrwIMmKNxTZh9WN UCWFkl0WfPEcjJ7IKVcuKGFtl5zG+rvOCwPX+1E1FYoxxFJPxbgGOTuVn5xxiIwixeGkFu rE0XJyaisqx65suMcdoVL7FtJDmSpvrFYhtB1LCeyqGOjL9m8ti7iFs4z6G2XEm20S/YiA 9o7/H25AGRgF2oDq56kALZLtIYVYzoUpQl7+AcgvecK/F1yCMjsE3+1nuicqNg== 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 4WJwyn1pRTzGMw; Wed, 10 Jul 2024 11:45:21 +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 46ABjL6R023223; Wed, 10 Jul 2024 11:45:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46ABjLpX023220; Wed, 10 Jul 2024 11:45:21 GMT (envelope-from git) Date: Wed, 10 Jul 2024 11:45:21 GMT Message-Id: <202407101145.46ABjLpX023220@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 12bd1341d2aa - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 12bd1341d2aa8eea34d858727c295ed5703de4f1 Auto-Submitted: auto-generated The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=12bd1341d2aa8eea34d858727c295ed5703de4f1 commit 12bd1341d2aa8eea34d858727c295ed5703de4f1 Author: Zhenlei Huang AuthorDate: 2024-07-02 04:57:02 +0000 Commit: Zhenlei Huang CommitDate: 2024-07-10 11:43:37 +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 (cherry picked from commit 087f5e08ab5f0384163f76f73b9a91c98a3ba450) (cherry picked from commit e729e750806d3873d5de24cce3b47cc054145985) --- 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 34816ede13a3..2cc9f60cba87 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -367,7 +367,7 @@ static void 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 *, @@ -2918,27 +2918,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 @@ -2946,18 +2933,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 @@ -3227,9 +3205,6 @@ vxlan_clone_create(struct if_clone *ifc, int unit, caddr_t params) sc->vxl_unit = 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 (params != 0) { error = copyin(params, &vxlp, sizeof(vxlp)); @@ -3241,6 +3216,7 @@ vxlan_clone_create(struct if_clone *ifc, int unit, caddr_t params) goto fail; } + vxlan_stats_alloc(sc); ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { error = ENOSPC;