From nobody Fri Dec 06 14:51:35 2024 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 4Y4Z2w0JZvz5gNqF; Fri, 06 Dec 2024 14:51:36 +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 4Y4Z2v6yW5z4FjQ; Fri, 6 Dec 2024 14:51:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733496696; 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=MO2eubgGQ7UL0EyEv8ixdKISsMls4B9oxmBd5CT+fEs=; b=xaZrMKEy5cYb5AULWbHHRJxfrJyMCAZcEA9BI1fuiOYm2hQI1FuDCm2qxB8iMmyZ5+sNAA hOrIOLcK7ASDxHoFjbCdZmiu1P+ZwdXyRg51LMzvo7MotAse0Gy1QZHsqBIHRM63BtcbYl 9yKoVGj2+yeOdbqD0W71sB6QBIHygFphbimOGlVBAg3DSyPO8izLD/JEHemtPuKCOeQbeS DUppPER2XTpcA1agZyOMQOQSU4UDGm33cSzYUheCIb784kaQejv8eqHOUhwYQ515ugZCil uRdEKYu3HFLxVL+FQG5ZMUGvQHMk3DBEIG5LfBlugl9SXoJTJu5g6LhmG0gYjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733496696; 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=MO2eubgGQ7UL0EyEv8ixdKISsMls4B9oxmBd5CT+fEs=; b=nUwUiD1AoIuG7bWtedYoNPIUQPCzyWOBHmwELAkSRuc+aZZU0ZOPlJfNWdxEUSDAmKhfnJ iq+fMGWlNynXqPzTW4mFst8dCtznp7Wydndx3zBSrqoELPzISBBVbqoNA/rEQu3dkp0hJN GKBJVNmyJbV8awuhsbE/RfPyHE4OFGosYbtcXZSasPPkOVdYFIAMiD0mPRwo7Kr++XVEcr X78e2gNdWNmEE+Mc2zLjDWOqKYtxsxtUnCZOZNQB0q0nsSjzHiMSNTJqPp3qV7NVRnrVDW YBaZZIz6jaQKDMjwPVP15py9ZZ4y7sD0/8lAkNksHhEwds56oezjPRzWmocWVA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733496696; a=rsa-sha256; cv=none; b=kBq07g2tbrvpJe/ufkubFQ+8ZYqpTYiHsIr22x9hn1w4THutNdC4ZE74brhJW/8+RrKuuK nCsHwiXh6HJCgENGRopmmZCYUkGYt97tUG7URGzr51xjeAZDH5MygYf4ggkJU6Sppc+t/i hBKKzx0AU81ddd4R2W5awOXzEk3BRIHH7DbhXMRtNcVtNfgnzhxB4MUHFhFA8NPcV2F2Tv i9XuBm1/HfdFG3p7c/fbtflA2QnclzzqV8l3vFB7s2YrCNKxRWAwGkjzaefyxVM3mqKcXY VixFz2u2STArNCKYi0mKMesUXgAxBYBe8Wj+WXYPyN65CG6hs2sKFHsiNxqrCA== 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 4Y4Z2v6YnVzhy7; Fri, 6 Dec 2024 14:51:35 +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 4B6EpZHT028237; Fri, 6 Dec 2024 14:51:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B6EpZpZ028234; Fri, 6 Dec 2024 14:51:35 GMT (envelope-from git) Date: Fri, 6 Dec 2024 14:51:35 GMT Message-Id: <202412061451.4B6EpZpZ028234@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 804dbdeea266 - stable/14 - devd tests: Fix client_test 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 804dbdeea266599bdb7cb576048f8b13038b521f Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=804dbdeea266599bdb7cb576048f8b13038b521f commit 804dbdeea266599bdb7cb576048f8b13038b521f Author: Mark Johnston AuthorDate: 2024-11-21 18:55:13 +0000 Commit: Mark Johnston CommitDate: 2024-12-06 14:51:09 +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 (cherry picked from commit 30cafaa9611d82525ab32ec32304b93835a5124a) --- 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); }