From owner-dev-commits-src-main@freebsd.org Tue Jul 27 16:06:26 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EEB6A662A13; Tue, 27 Jul 2021 16:06:26 +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 4GZ1r2684vz4gp3; Tue, 27 Jul 2021 16:06:26 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 ACEE15B2A; Tue, 27 Jul 2021 16:06:26 +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 16RG6Q9B016951; Tue, 27 Jul 2021 16:06:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16RG6Q9j016950; Tue, 27 Jul 2021 16:06:26 GMT (envelope-from git) Date: Tue, 27 Jul 2021 16:06:26 GMT Message-Id: <202107271606.16RG6Q9j016950@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bryan Drewery Subject: git: a573243370d3 - main - netdump: Fix leaking debugnet state on errors. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bdrewery X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a573243370d3f4ffad81c740591004851f2beb45 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jul 2021 16:06:27 -0000 The branch main has been updated by bdrewery: URL: https://cgit.FreeBSD.org/src/commit/?id=a573243370d3f4ffad81c740591004851f2beb45 commit a573243370d3f4ffad81c740591004851f2beb45 Author: Bryan Drewery AuthorDate: 2021-07-26 23:27:07 +0000 Commit: Bryan Drewery CommitDate: 2021-07-27 16:06:23 +0000 netdump: Fix leaking debugnet state on errors. Reviewed by: cem, markj Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D31319 --- 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 06a833c20c07..2669ec879d75 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. */