From nobody Thu Apr 07 14:52:39 2022 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 7A77F1A84F55; Thu, 7 Apr 2022 14:52:39 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KZ49g2J2Cz4v04; Thu, 7 Apr 2022 14:52:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649343159; 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=1lwEAE1JbUn+z/C3ETUrmZUjKq7r9ggre4hS1XBQVGs=; b=u0O0VX0N+ZGXV+gxt1AmVak+aGorUeS7bNr+45Sn6DEJg/SATrD9DUAKPatBMh/nTGAg3x UJ0Qwoz/LSuRuMiWgpBsm+Y/k1SzAB8fVJOyJelHYZKlzbzMKhNio72OB3IvFkccLaoksE VlNy6A18KJEOdS0BtASxDh0OVuHbSadvZ0wdYJCIWuBatNLHveyn5uxMWYCux3vrFW3k+e NVR5QAFpxyNPvRW2kA7em0FdDZvQSfSX28hHS3LiShehRZZcuQJNDrZzZsFonvlDBaPg5t IfXwk76JlRJPS/K9hoo5C+1IawLfTnGM4maxs8oiuwMn5dO5W+7R1SO4Vdg3LA== 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 24C311252D; Thu, 7 Apr 2022 14:52:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 237Eqdtv039449; Thu, 7 Apr 2022 14:52:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 237EqdqE039448; Thu, 7 Apr 2022 14:52:39 GMT (envelope-from git) Date: Thu, 7 Apr 2022 14:52:39 GMT Message-Id: <202204071452.237EqdqE039448@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: be461cdfb36e - main - pf syncookies: fix 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: be461cdfb36e229040aafae07a2ba68f73091431 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649343159; 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=1lwEAE1JbUn+z/C3ETUrmZUjKq7r9ggre4hS1XBQVGs=; b=T1CndMWsxyurP99dnrA7gj6W3rEhifxfWLYV8wLz5Y6AgKziLOfYWhSn5b7TcExli1Rb4h y0xwvNV9pqQUiiDWroyIJR6cl/1yKk6SEDpuv5Jp8eV8iAkrHEbuPFQIxlm+Zb+ghOWtng rAZZPQ9PMBb9FAjJ2bU9sL5TBd4ydeR2TQl95e6sfr3Y4lDGHRHZXDTXw8/mHDxhXbuO/A gcjz4MnD15sPpe3A/PLPnjvknH+zaZETQreuGnKZLACxLfR2vEQmKiUIxBs+Xpf1H5/MaZ RJ0aQ6jtOesewxsQ2Nc+MvtN9Q9Y0rElnJsphf7DRN59zujyQyHAiLW9VoHO1Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649343159; a=rsa-sha256; cv=none; b=OeG0X2Izcuxv0ivTyRdwIp3joX6Im0wEYnLlxT//Emj+21UO1r6l4SRkVjH2BPz1U9qfxr WzYRm8WDpAE50HEEPu32YmAZs96mwYWqwlLkCHbYkLyh5/+1+Ufg8CUnYzJQxuE6P/zata jSWEo11TfV38v2+R+zmhaOGiN2uS33mO9UQDFHjyqK0g1W5YfdzIKJFUOvr8YE/MIPlTlc 2uZ2EGkI8fe7CP0C/l7Fhvwdzj5TmsOwsyHkYUJ7gxsO2q/FcY6JZbXW9EME2spTXdXzKj DMbp+1v6QrHqLJgszxIUn2SOYDioPsHNWz85UJ0pf7gPnO9Iccjyl/QWcXEH6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=be461cdfb36e229040aafae07a2ba68f73091431 commit be461cdfb36e229040aafae07a2ba68f73091431 Author: Kristof Provost AuthorDate: 2022-04-07 06:41:37 +0000 Commit: Kristof Provost CommitDate: 2022-04-07 12:51:52 +0000 pf syncookies: fix memory leak We forgot to free the nvlist (and packed nvlist) on success. While here start using the ERROUT macro to clean up error handling, and to add SDTs for better debugging. Reported by: Coverity CID: 1473150 --- sys/netpfil/pf/pf_syncookies.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/sys/netpfil/pf/pf_syncookies.c b/sys/netpfil/pf/pf_syncookies.c index 32b2bec6c3d6..5230502be30c 100644 --- a/sys/netpfil/pf/pf_syncookies.c +++ b/sys/netpfil/pf/pf_syncookies.c @@ -141,10 +141,13 @@ pf_get_syncookies(struct pfioc_nv *nv) { nvlist_t *nvl = NULL; void *nvlpacked = NULL; + int error; + +#define ERROUT(x) ERROUT_FUNCTION(errout, x) nvl = nvlist_create(0); if (nvl == NULL) - return (ENOMEM); + ERROUT(ENOMEM); nvlist_add_bool(nvl, "enabled", V_pf_status.syncookies_mode != PF_SYNCOOKIES_NEVER); @@ -154,21 +157,23 @@ pf_get_syncookies(struct pfioc_nv *nv) nvlist_add_number(nvl, "lowwater", V_pf_syncookie_status.lowat); nvlpacked = nvlist_pack(nvl, &nv->len); - if (nvlpacked == NULL) { - nvlist_destroy(nvl); - return (ENOMEM); - } + if (nvlpacked == NULL) + ERROUT(ENOMEM); + if (nv->size == 0) { - nvlist_destroy(nvl); - free(nvlpacked, M_TEMP); - return (0); + ERROUT(0); } else if (nv->size < nv->len) { - nvlist_destroy(nvl); - free(nvlpacked, M_TEMP); - return (ENOSPC); + ERROUT(ENOSPC); } - return (copyout(nvlpacked, nv->data, nv->len)); + error = copyout(nvlpacked, nv->data, nv->len); + +#undef ERROUT +errout: + nvlist_destroy(nvl); + free(nvlpacked, M_TEMP); + + return (error); } int