From nobody Tue Sep 12 14:47:50 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 4RlRJk3PpYz4t96T; Tue, 12 Sep 2023 14:47:50 +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 4RlRJk2d4Mz4VmT; Tue, 12 Sep 2023 14:47:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694530070; 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=WjBYs0SYcP3quJZ+cHRt0bQu6EqVtGTZ6NivNZtnAeY=; b=T2A3C7ZzkFIRJEDvRTXMku/KMa60SktCDli3N3QDBp6AYGLVw7QG/1k6YJIgUyDVwKu/qO x862+L/kXJGOfyk8i+Tc1dS1MviErMmj4ob7Y4wqmUvgG1RFsXdbyMyKx6rSyjFveTOgtN g28FdL6IjbFknGh+bmxR/ibhSqoBzQb6alglx65O7f1WMll57GCuB5b4RbXXndJ35RqI1n 1nOO7cOif6k1DjuRwMVIgL0NNeKuF+R4xqTN/yD7dC/3NcqwSsbScOBhVSTl3c1FCwHIQ7 8N7YjBbC2TYd5hNw8xHA1oJYG027K+B0/40nRcNcjojJwg3E52AJlVBEOnyOVQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694530070; a=rsa-sha256; cv=none; b=W/SQEM+qkPvhN2BMhBakp7ff7bAlhU+NKlKWHFWwfSP3inO8apJ21v77BZQMInS94+IySo VZHWxQkDqw9VZtxi6zw03QnMYMsySktf+DuV4HLXS5dwfhKYvb67vyI741y0WYASd0q6Et dx028qCDpMTm7MYtgnOdlvVKfvBeih1rKcsbavZxGhINPd6Bvzr77w1DFyewuLYqzBI0KO /eKw5W0w0eLyFTSL0S+XyS3I+i7tvjRa9FVTI4Groimg+reUUlwyYK9TWWrvkmh6pAtT7A K6mEFVmcar+dPua+A9ZRZ6VkKq2gkMsqUPCGBUs4S9o8FO+e3SaN+/X2ZDL2MA== 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=1694530070; 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=WjBYs0SYcP3quJZ+cHRt0bQu6EqVtGTZ6NivNZtnAeY=; b=a+WSozUGj0odSYPciETNBmFRyvyzzrt3TBnp3O0JUR75q8vyc+/LQrJinxEnP2GYtHlucG uZNuiGl/m6Q8tmO0L3ZF/8lt0IqGxoDBooK+xi7dgoDVwAMUMcmkskbQm0mDbRHY1m71OQ /H/Cfu1zB2vcAUZsXLmND/9udctFIs2p2xOwQDF8k4ywMMaaQTv2lriqMdqAZOJlnXnQvP KrGxiMJHcT1LY/zRX5QBQKALHQU6Et9q1hFZ72Hz3C0QkXTRZsbDToZH6kjf78LkdRdkP8 Dn2wBxMNTYnyIMOneZaBwGw/pa9N+4pla3nHu+v2Zs4HXbVrkwDoYTtrO8ghtA== 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 4RlRJk1PPSzbYG; Tue, 12 Sep 2023 14:47:50 +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 38CEloOo069892; Tue, 12 Sep 2023 14:47:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38CElo3w069889; Tue, 12 Sep 2023 14:47:50 GMT (envelope-from git) Date: Tue, 12 Sep 2023 14:47:50 GMT Message-Id: <202309121447.38CElo3w069889@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 0b294a386d34 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0b294a386d34f6584848ed52407687df7ae59861 Auto-Submitted: auto-generated The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=0b294a386d34f6584848ed52407687df7ae59861 commit 0b294a386d34f6584848ed52407687df7ae59861 Author: Alan Somers AuthorDate: 2023-09-12 01:20:39 +0000 Commit: Alan Somers CommitDate: 2023-09-12 14:46:12 +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 MFC after: 1 week Sponsored by: Axcient Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D41818 --- 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 f3fea2ca83f4..caeb077a3de8 100644 --- a/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc +++ b/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc @@ -766,3 +766,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 f64b0d98440d..e9283108ed3c 100644 --- a/cddl/usr.sbin/zfsd/vdev_iterator.cc +++ b/cddl/usr.sbin/zfsd/vdev_iterator.cc @@ -109,10 +109,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;