From nobody Thu Nov 21 18:55:55 2024 X-Original-To: dev-commits-src-main@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 4XvS9l6rb1z5dRSL; Thu, 21 Nov 2024 18:55:55 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XvS9l6FN9z4d90; Thu, 21 Nov 2024 18:55:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732215355; 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=Sra3WHKDZpJawFuwVgCE32tnHRwz2ZUMYBIcjeWScZ4=; b=IuE1LhJOkqOMDLg93XyXIvUTU8gEJpJVKWoTNcTNxdcA/JMzUjMPChtFWf9nEcsbVAw7VV blF/o/RDOUm4cNnQSlVESYUV4NflMTwVmD5S+j31I1fz8Mi8ZjquUbGrCr3+vLIihKNoQx al+/icS59BhH2g3fUioIhsFOWr1Ld2TvqYiuYfCIaiM7kNkyryL0f5L3dwAlfHjnCaLdOT 5Dfd7BbZxHXuq+oiDiCw2fQRaj26tGMopNuw3Xbbi6V6lDu8K63Lyb9JTrphVQYefkf4a+ SXYq8CIy2LnW9r3C63Dq8GUUt7VURmLbxF4UWOVpYqyUpvo42aJNONT6/0T5Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732215355; 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=Sra3WHKDZpJawFuwVgCE32tnHRwz2ZUMYBIcjeWScZ4=; b=sWJo9+eGEqFzsYxQIzOXXRgFsxCzUZ4XngTW5EYM41IT/mRHvfoIyZjx/ctH/9hxdJuYCq Rdcc+FhrS1JimHivxCky08TCyoplomdaHvXIWd092Vmjl6e4rlRk7pSJEikYGl/4+OKRjJ y95b5+HfITU5P1UOqsCTstEcLr5gWsE00gaBSkLhmpVXt2anjjVFIun+8iNCAXHaih6ruR 1HAw6OHp9PDuoL5Oxt+pA3DzLntjIKjaL+SMeJzDRJ5DRhHzrJg8NJgrgUcUJ9f8WkycWF e/H6a078Y6FENyscXNHlvYUrbuOwhUjDNAGNZLJT5cXD1F5RIIZYENJmy2uhxA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732215355; a=rsa-sha256; cv=none; b=BdttoQZgmYeHZcU76IylBl5jCtCpxZNc4cinnwx3ohS5I4LCcCkoJ9d57TPKrvFMPT2HZZ tVFkKK/Tg+A+R0nnyPdh/lQlpoRxRxdhyc/nZHLhMN8PA8YLUif2olrykMzSwUE6oWWte2 lOYgmaK0VvDgMEqDcY+Prdfispu940Q6OcNGAVBnjIXAszdCkCKEIjfXAQcnJMb1/51Sco EKvN/z6DnZMsVST2tBEf2k5/cv+YeIV2mwmC5FDjrfjndCl3Ddy38ytme9Gj+ujypjVvMj XpbYB2xGJXQn03SPfYX7lGY00pGgRN73ezJeH67AYHPa2MNqhkDPLl9tDeWCTA== 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 4XvS9l5rbkzrMf; Thu, 21 Nov 2024 18:55:55 +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 4ALItttS013174; Thu, 21 Nov 2024 18:55:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ALIttcp013171; Thu, 21 Nov 2024 18:55:55 GMT (envelope-from git) Date: Thu, 21 Nov 2024 18:55:55 GMT Message-Id: <202411211855.4ALIttcp013171@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 30cafaa9611d - main - devd tests: Fix client_test List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 30cafaa9611d82525ab32ec32304b93835a5124a Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=30cafaa9611d82525ab32ec32304b93835a5124a commit 30cafaa9611d82525ab32ec32304b93835a5124a Author: Mark Johnston AuthorDate: 2024-11-21 18:55:13 +0000 Commit: Mark Johnston CommitDate: 2024-11-21 18:55:13 +0000 devd tests: Fix client_test The loop doesn't check for overflow of the event buffer, which can easily happen if other tests are running in parallel (the bectl tests in particular trigger devd events). When that overflow occurs, a funny thing can happen: the loop ends up trying to read 0 bytes from the socket, succeeds, and then prints its buffer to stdout. It does this as fast as possible, eventually timing out. Then, because kyua wants to log the test's output, it slurps the output file into memory so that it can insert it into the test db. This output file is quite large, usually around 8GB when I see it happen, and is large enough to trigger an OOM kill in my test suite runner VM. Fix the test: use a larger buffer and fail the test if we fill it before both events are observed. Also don't print the output buffer on every loop iteration, since unlike the seqpacket test that will just print the same output over and over. Reviewed by: imp, asomers MFC after: 2 weeks Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D47625 --- sbin/devd/tests/client_test.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/sbin/devd/tests/client_test.c b/sbin/devd/tests/client_test.c index 729c7a2f8bad..fdac3c98b3c6 100644 --- a/sbin/devd/tests/client_test.c +++ b/sbin/devd/tests/client_test.c @@ -22,15 +22,14 @@ * SUCH DAMAGE. */ -#include -#include -#include - #include -#include #include #include +#include +#include +#include + #include const char create_pat[] = "!system=DEVFS subsystem=CDEV type=CREATE cdev=md"; @@ -134,29 +133,37 @@ ATF_TC_BODY(seqpacket, tc) ATF_TC_WITHOUT_HEAD(stream); ATF_TC_BODY(stream, tc) { + char *event; int s; bool got_create_event = false; bool got_destroy_event = false; - ssize_t len = 0; + size_t len = 0, sz; s = common_setup(SOCK_STREAM, "/var/run/devd.pipe"); + + /* + * Use a large buffer: we're reading from a stream socket so can't rely + * on record boundaries. Instead, we just keep appending to the buffer. + */ + sz = 1024 * 1024; + event = malloc(sz); + ATF_REQUIRE(event != NULL); + /* * Loop until both events are detected on the same or different reads. * There may be extra events due to unrelated system activity. * If we never get both events, then the test will timeout. */ - while (!(got_create_event && got_destroy_event)) { - char event[1024]; + while (!(got_create_event && got_destroy_event) && len < sz - 1) { ssize_t newlen; char *create_pos, *destroy_pos; /* Read 1 less than sizeof(event) to allow space for NULL */ - newlen = read(s, &event[len], sizeof(event) - len - 1); - ATF_REQUIRE(newlen != -1); + newlen = read(s, &event[len], sz - len - 1); + ATF_REQUIRE(newlen > 0); len += newlen; /* NULL terminate the result */ event[len] = '\0'; - printf("%s", event); create_pos = strstr(event, create_pat); if (create_pos != NULL) @@ -166,7 +173,11 @@ ATF_TC_BODY(stream, tc) if (destroy_pos != NULL) got_destroy_event = true; } + printf("%s", event); + if (len >= sz - 1) + atf_tc_fail("Event buffer overflowed"); + free(event); close(s); }