From owner-svn-src-head@freebsd.org Mon Aug 19 16:29:52 2019 Return-Path: Delivered-To: svn-src-head@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 A0F35CAC23; Mon, 19 Aug 2019 16:29:52 +0000 (UTC) (envelope-from markj@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46Bzsr3nlxz413m; Mon, 19 Aug 2019 16:29:52 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 49C071D4E4; Mon, 19 Aug 2019 16:29:52 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7JGTq00046808; Mon, 19 Aug 2019 16:29:52 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7JGTqHq046807; Mon, 19 Aug 2019 16:29:52 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201908191629.x7JGTqHq046807@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Mon, 19 Aug 2019 16:29:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351219 - head/sys/netinet/netdump X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/netinet/netdump X-SVN-Commit-Revision: 351219 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Aug 2019 16:29:52 -0000 Author: markj Date: Mon Aug 19 16:29:51 2019 New Revision: 351219 URL: https://svnweb.freebsd.org/changeset/base/351219 Log: Fix netdump buffering after r348473. nd_buf is used to buffer headers (for both the kernel dump itself and for EKCD) before the final call to netdump_dumper(), which flushes residual data in nd_buf. As a result, a small portion of the residual data would be corrupted. This manifests when kernel dump compression is enabled since both zstd and zlib detect the corruption during decompression. Reviewed by: cem Differential Revision: https://reviews.freebsd.org/D21294 Modified: head/sys/netinet/netdump/netdump_client.c Modified: head/sys/netinet/netdump/netdump_client.c ============================================================================== --- head/sys/netinet/netdump/netdump_client.c Mon Aug 19 14:33:22 2019 (r351218) +++ head/sys/netinet/netdump/netdump_client.c Mon Aug 19 16:29:51 2019 (r351219) @@ -923,6 +923,24 @@ netdump_network_poll(void) */ /* + * Flush any buffered vmcore data. + */ +static int +netdump_flush_buf(void) +{ + int error; + + error = 0; + if (nd_conf.nd_buf_len != 0) { + error = netdump_send(NETDUMP_VMCORE, nd_conf.nd_tx_off, + nd_buf, nd_conf.nd_buf_len); + if (error == 0) + nd_conf.nd_buf_len = 0; + } + return (error); +} + +/* * Callback from dumpsys() to dump a chunk of memory. * Copies it out to our static buffer then sends it across the network. * Detects the initial KDH and makes sure it is given a special packet type. @@ -948,13 +966,9 @@ netdump_dumper(void *priv __unused, void *virtual, virtual, (uintmax_t)offset, length); if (virtual == NULL) { - if (nd_conf.nd_buf_len != 0) { - error = netdump_send(NETDUMP_VMCORE, nd_conf.nd_tx_off, nd_buf, - nd_conf.nd_buf_len); - if (error != 0) { - dump_failed = 1; - } - } + error = netdump_flush_buf(); + if (error != 0) + dump_failed = 1; if (dump_failed != 0) printf("failed to dump the kernel core\n"); @@ -968,16 +982,14 @@ netdump_dumper(void *priv __unused, void *virtual, if (length > sizeof(nd_buf)) return (ENOSPC); - if (nd_conf.nd_buf_len + length > sizeof(nd_buf) || - (nd_conf.nd_buf_len != 0 && nd_conf.nd_tx_off + + if (nd_conf.nd_buf_len + length > sizeof(nd_buf) || + (nd_conf.nd_buf_len != 0 && nd_conf.nd_tx_off + nd_conf.nd_buf_len != offset)) { - error = netdump_send(NETDUMP_VMCORE, nd_conf.nd_tx_off, nd_buf, - nd_conf.nd_buf_len); + error = netdump_flush_buf(); if (error != 0) { dump_failed = 1; return (error); } - nd_conf.nd_buf_len = 0; nd_conf.nd_tx_off = offset; } @@ -1078,6 +1090,9 @@ netdump_write_headers(struct dumperinfo *di, struct ke { int error; + error = netdump_flush_buf(); + if (error != 0) + return (error); memcpy(nd_buf, kdh, sizeof(*kdh)); error = netdump_send(NETDUMP_KDH, 0, nd_buf, sizeof(*kdh)); if (error == 0 && keysize > 0) {