From nobody Thu Sep 21 22:27:21 2023 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 4Rs94p0Y0Mz4v5Cd; Thu, 21 Sep 2023 22:27:22 +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 4Rs94n6y16z4HqT; Thu, 21 Sep 2023 22:27:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695335242; 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=F9Bc+fCely7wyBJtda8V6E0+OnK1Mq7qDuutRlJjIsA=; b=Cg2Kvq/OvJG88jJcAQzE+ZIX8EnPhXN1xuDK9QRz+ZPh/eyesfeLvweA/Bty7Ps/zAmQR8 3cKkd8lv/KoBCy0Z6mxe/U0XkB70RXGDJmkeKgq9Sq+fHn3tgn8F+gN7u/iarH38blnsT4 fznX92e1jf7p0L0sXCrKu06v906+/EgjlIYIMJFeTzlxQoMPeWjUjZc+vp+RadFqYMNoXN lsSwFUHS5WZ7Gfod3Jy9bkfoZEqjihPot4yUIdHSMAG2KmEwh2z8pNG4vYn8IG+74EPwLh tmWNSLCi9YajZ3+USw8aayfr+njAsLlVRYGHdn2QouTA7J5nJQwp6OIdLLIuLQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695335242; a=rsa-sha256; cv=none; b=y2bswf1R5v/wNeFaCz0QQfqsH0hVbVcHxcsS/guRKd1pv43AvKIxKzsBLwaHLGhjfrAWt7 Vt8/d0OsnwWb4qYFhTHq33MjTh78P9F4PHWLJuumslpEhbE1wgo2VijkBJXuadSohuU0LS acSBz8YJWvwHcn/9SbhH4xdNrsuTYW2pluO4pIjuq5eABkzPVUi5RzpDTyY7K1iJuOhDED 2OdnCIg63oEbmTqZXwKyxfvyw/m4d/ovUSBmEb+cp9fGdWpGVhjAMVQcBXFXjBd+zUadtO KL31bt2Y2PBQrAbfsXILV8XEPtHaA0AUNL898huyZmK7OVXCWTyc9bph3lqwIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695335242; 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=F9Bc+fCely7wyBJtda8V6E0+OnK1Mq7qDuutRlJjIsA=; b=dNVDp9s0CDDCS63G8t/zWI+Tbe2fH0vQeN5laT4YigR6jnXY2S6ORjMmbndMvZFobNASOO 9FD8NxUAJmhpTouzHK4Y5bInMXdSmQ3j8Bq8PcTWUkbYuS0zsHdvD0g/sJHf0+KM3oZspo CFQxnlmXZ0QBEqf4+VS06PJu5fb8tX2fs4zPTos9Zid4DzmeABc4jq64spJUGYQrTC3i5C ra/DQTAx4m2MUrf06t0AHCZaV2B8hfjz8zhb804hL2W6Go3onQ4eXunN6rQ1H8rbW6P6KX WfMmm4ZRAd0hm/sNBIjvKZzGXOmWGiIbZhGIwnCMipib26e9F+WLmoeZFS7uGg== 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 4Rs94n5yGNzx5p; Thu, 21 Sep 2023 22:27:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38LMRL3I091420; Thu, 21 Sep 2023 22:27:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38LMRLTm091417; Thu, 21 Sep 2023 22:27:21 GMT (envelope-from git) Date: Thu, 21 Sep 2023 22:27:21 GMT Message-Id: <202309212227.38LMRLTm091417@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: b2dff90c0be7 - stable/12 - Fix zfsd with the device_removal pool feature. 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: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b2dff90c0be7c92a228fdbee5f69335dcc8044fb Auto-Submitted: auto-generated The branch stable/12 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=b2dff90c0be7c92a228fdbee5f69335dcc8044fb commit b2dff90c0be7c92a228fdbee5f69335dcc8044fb Author: Alan Somers AuthorDate: 2023-09-12 01:20:39 +0000 Commit: Alan Somers CommitDate: 2023-09-21 22:26:29 +0000 Fix zfsd with the device_removal pool feature. Previously zfsd would crash in the presence of a pool with a top-level-vdev that had previously been removed. The crash happened because the configuration nvlist of such a TLV contains an empty ZPOOL_CONFIG_CHILDREN array, which led to a pop_front from an empty list, which has undefined behavior. The crash only happened in stable/14 and later, probably do to differences in libcxx, but the change should be MFCed anyway. PR: 273663 Reported by: Marek Zarychta Sponsored by: Axcient Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D41818 (cherry picked from commit 0b294a386d34f6584848ed52407687df7ae59861) --- cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc | 37 +++++++++++++++++++++++++++++++ cddl/usr.sbin/zfsd/vdev_iterator.cc | 5 +---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc b/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc index d65295075c1f..b4f1cecca033 100644 --- a/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc +++ b/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc @@ -768,3 +768,40 @@ TEST_F(ReEvaluateByGuidTest, ReEvaluateByGuid_five) delete CaseFile4; delete CaseFile5; } + +/* + * Test VdevIterator + */ +class VdevIteratorTest : public ::testing::Test +{ +}; + +bool VdevIteratorTestCB(Vdev &vdev, void *cbArg) { + return (false); +} + +/* + * VdevIterator::Next should not crash when run on a pool that has a previously + * removed vdev. Regression for + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273663 + */ +TEST_F(VdevIteratorTest, VdevRemoval) +{ + nvlist_t* poolConfig, *rootVdev; + + ASSERT_EQ(0, nvlist_alloc(&rootVdev, NV_UNIQUE_NAME, 0)); + ASSERT_EQ(0, nvlist_add_uint64(rootVdev, ZPOOL_CONFIG_GUID, 0x5678)); + /* + * Note: pools with previously-removed top-level VDEVs will contain a + * TLV in their labels that has 0 children. + */ + ASSERT_EQ(0, nvlist_add_nvlist_array(rootVdev, ZPOOL_CONFIG_CHILDREN, + NULL, 0)); + ASSERT_EQ(0, nvlist_alloc(&poolConfig, NV_UNIQUE_NAME, 0)); + ASSERT_EQ(0, nvlist_add_uint64(poolConfig, + ZPOOL_CONFIG_POOL_GUID, 0x1234)); + ASSERT_EQ(0, nvlist_add_nvlist(poolConfig, ZPOOL_CONFIG_VDEV_TREE, + rootVdev)); + + VdevIterator(poolConfig).Each(VdevIteratorTestCB, NULL); +} diff --git a/cddl/usr.sbin/zfsd/vdev_iterator.cc b/cddl/usr.sbin/zfsd/vdev_iterator.cc index 31a4ce962970..6e60e13eeeb7 100644 --- a/cddl/usr.sbin/zfsd/vdev_iterator.cc +++ b/cddl/usr.sbin/zfsd/vdev_iterator.cc @@ -101,10 +101,7 @@ VdevIterator::Next() { nvlist_t *vdevConfig; - if (m_vdevQueue.empty()) - return (NULL); - - for (;;) { + for (vdevConfig = NULL; !m_vdevQueue.empty();) { nvlist_t **vdevChildren; int result; u_int numChildren;