From nobody Mon Jun 27 19:35:31 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 7E93C86E02C; Mon, 27 Jun 2022 19:35:32 +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 4LWycg6X9kz3lRR; Mon, 27 Jun 2022 19:35:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656358532; 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=ujrA4duZaEN4oDQDnGMT13zCfvxp9eOMwClB5YW+m8k=; b=xfKQahV0SSZKWVeG9kQfnmmjXNQ0TKjhNIaSdXCEHkDdP09VuY0BFs0thN4+DeoSsrqy62 Q+GyxjZ4XJGkQnTHSWPpAteEuMeNLMKCluaXc1u+6mugCCjZEpqtO+Y/EdQBU8tBlbC2x5 cnijE0vxBW+ksSwrs8K3+HQtSCIFjvLxhrIJmdpXvI1sLWa2m0HQsStxkFqIdhK6pEja87 m9InYtVh0C65mYzt9BD4umrEC5laBSD7vcmBQBNhI1vqdI0NBxxn6Im9wFuONmN79nYIc+ P4F2YJjwDPNNC7x1pat287AQb5MP2YmtpFCRPWDTNWLNmaIC54kbd0btbDj8gA== 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 4C4BD6951; Mon, 27 Jun 2022 19:35:31 +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 25RJZVX9019714; Mon, 27 Jun 2022 19:35:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25RJZVda019713; Mon, 27 Jun 2022 19:35:31 GMT (envelope-from git) Date: Mon, 27 Jun 2022 19:35:31 GMT Message-Id: <202206271935.25RJZVda019713@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: ad78db5a3ff7 - stable/13 - netdump: Fix leaking debugnet state on errors. 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ad78db5a3ff7c804e5021c2879888ef436367d92 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656358532; 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=ujrA4duZaEN4oDQDnGMT13zCfvxp9eOMwClB5YW+m8k=; b=tf6OHBwp3EY0lGxF5l7/w9K6a6T71SjXw41WlOVW15i6gcxj6f7qA5NN3EFB2IVpWDdKCN IjuduI9Gjbr3rHMpfCnSiXJDadGDF0+Go7fN+ync8yHUVa2U9dmSrxcVlCzhc6tTxvU+rr 13oXOBa9972UZDeqgwLDuBluUUU+GscBhvfnfYvveyDoDfbI2zyi7aLN18iyPgoumR/lMw k90tcvb3XuaUxWU95VruiOqE+0eNwWuxSGRpPG2yJV3TDT0h85UTHkloBvddNEOEYyBnwZ +Wis0fo4hUdbBXoDSkwQJozh5x2S0wdgGgWzM02tezg1le/fa7xECDYmDa64Hw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656358532; a=rsa-sha256; cv=none; b=HWqVMY5JZyomN+rGsjqvfLoC7LeAYjYNr5C4juQ6iM5P4FQ7Hz+5Ko6XMcSokdRF9ot0Fi GiDlbPRN0Ze4mNllnKatxx7gbBXNRwwpuzHwZCWFkXAaRoQE9UY2qDBPb7b7hewP3201x6 pPcwcA0IKjqqrWwJvNtOAEi/OWcgznuJ9A9qo5ohldQQe8eAEIBcrnc4IJi2a3UVPSfgOR o/2L6Ky5mlxtkBXpIlIZ+mhCTLO2bijScxwjG99xjF6Aq92TOj8g0cmftiio6KkAZLudMU AjvbgCDqIbNf1su+d7GX9RmmuyqR9MPBhYJu7xNctGTTmyldInyH1OkgFIpWlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=ad78db5a3ff7c804e5021c2879888ef436367d92 commit ad78db5a3ff7c804e5021c2879888ef436367d92 Author: Bryan Drewery AuthorDate: 2021-07-26 23:27:07 +0000 Commit: Mitchell Horne CommitDate: 2022-06-27 19:32:06 +0000 netdump: Fix leaking debugnet state on errors. Reviewed by: cem, markj Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D31319 (cherry picked from commit a573243370d3f4ffad81c740591004851f2beb45) --- sys/netinet/netdump/netdump_client.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/sys/netinet/netdump/netdump_client.c b/sys/netinet/netdump/netdump_client.c index dc209062b359..0ebb8d3dd636 100644 --- a/sys/netinet/netdump/netdump_client.c +++ b/sys/netinet/netdump/netdump_client.c @@ -85,6 +85,7 @@ __FBSDID("$FreeBSD$"); printf(("%s: " f), __func__, ## __VA_ARGS__); \ } while (0) +static void netdump_cleanup(void); static int netdump_configure(struct diocskerneldump_arg *, struct thread *); static int netdump_dumper(void *priv __unused, void *virtual, @@ -254,12 +255,13 @@ netdump_dumper(void *priv __unused, void *virtual, printf("failed to close the transaction\n"); else printf("\nnetdump finished.\n"); - debugnet_free(nd_conf.nd_pcb); - nd_conf.nd_pcb = NULL; + netdump_cleanup(); return (0); } - if (length > sizeof(nd_buf)) + if (length > sizeof(nd_buf)) { + netdump_cleanup(); return (ENOSPC); + } if (nd_conf.nd_buf_len + length > sizeof(nd_buf) || (nd_conf.nd_buf_len != 0 && nd_conf.nd_tx_off + @@ -267,6 +269,7 @@ netdump_dumper(void *priv __unused, void *virtual, error = netdump_flush_buf(); if (error != 0) { dump_failed = 1; + netdump_cleanup(); return (error); } nd_conf.nd_tx_off = offset; @@ -344,20 +347,37 @@ netdump_write_headers(struct dumperinfo *di, struct kerneldumpheader *kdh, error = netdump_flush_buf(); if (error != 0) - return (error); + goto out; memcpy(nd_buf, kdh, sizeof(*kdh)); error = debugnet_send(nd_conf.nd_pcb, NETDUMP_KDH, nd_buf, sizeof(*kdh), NULL); if (error == 0 && keysize > 0) { - if (keysize > sizeof(nd_buf)) - return (EINVAL); + if (keysize > sizeof(nd_buf)) { + error = EINVAL; + goto out; + } memcpy(nd_buf, key, keysize); error = debugnet_send(nd_conf.nd_pcb, NETDUMP_EKCD_KEY, nd_buf, keysize, NULL); } +out: + if (error != 0) + netdump_cleanup(); return (error); } +/* + * Cleanup routine for a possibly failed netdump. + */ +static void +netdump_cleanup(void) +{ + if (nd_conf.nd_pcb != NULL) { + debugnet_free(nd_conf.nd_pcb); + nd_conf.nd_pcb = NULL; + } +} + /*- * KLD specific code. */