From nobody Thu Sep 21 22:24:19 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 4Rs91H63MWz4v4jn; Thu, 21 Sep 2023 22:24:19 +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 4Rs91H5W4kz4HKH; Thu, 21 Sep 2023 22:24:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695335059; 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=qVUvIUoZPQVKEslrDVTAoE1yFv2toSL7I8QjuTcIFbE=; b=HBl8fNilNrEcA8N0nogRFUN7yoc8hurZl5yHoZH43Rcj13SIERRJTgxE/Jf3dCnlRAhZNB YCrEtOZmkVGK0GlrCZje/vnkAkzAkAf2u3M2gi0m3h3Bt6Ojaf/po+Y33epWJwV2FtiJcg wvAyfYSk/yoiTlqmVKAyo3NaxfloVIp6WSS1pnl9iYjuWZxNTzv7FaieInC3Y2/osc3zEE wnVUyWkeF+vaASnCVdtrXRGbDzXyIfyjMiWY1gjtcFzC4gwP8Wvhovcai2cW1vvfya9pOl eXkyBp4263Eyt6zq5j23arTP7tEZ18Gpsw5vV2TDg4YRzm7ZruehJofOFZQTOA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695335059; a=rsa-sha256; cv=none; b=RmV30a8C27BwXjaCJ05GoupZaEklExQ3mK/mPcM/RbiCrN1aYkTexW0E0j4ACH4AXwVazB OWD2LevqC5Hm6Ye/ikQUfk9FwUs4bOzkbKZt00eHMcKigZG3/3W1XOixJisU5dohogdKhi wCuBzfNjyVzBlE857Pu4HqD7Ia/XpNQof3UExsTRClqay1DVuoUm1KScpVQNCMEaQRbBOj AJDi/z9e47crWFU2VRGdhNJ1BH6+xFJwEYZQ3UVMHCyvgvAjbkQon7MclDvGtwWLt9lfme miB5SYhJ19FWLggdo/D8Rddjd/pIPsedh/WCBKVtWPx9yglCurC3Z/bW0DWcKQ== 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=1695335059; 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=qVUvIUoZPQVKEslrDVTAoE1yFv2toSL7I8QjuTcIFbE=; b=eSybQhuXeus3LqkqocDlbPjS4XL/VNukMDvPGebP4Wrpb+Ubs2EqhBJNmFbp7SeMMMdRgV oHll9GUwXdABLMZcPPVzLJ3c/gfkpF6f+fGw5oiKtsH00oPWRIB/Cbkf+TlTzDa2lRGnfO 7RyeSrsQlqfeqD2smdEzsfN3nvUXDs8WD4FM/WkI/gpvFhq6rwjX6DGe69p8mt6FzPHbg4 x9e+ONIivK68JQhVc/8Ypt3uBQq1u12fRpvMkpm3ZTXC3grj+yxFAb/g2RPwmbCOQkTSaY px21Q18c0ZLO6dbKwdCeQxxmCnmilBYF0T6aQx1+Ocvir4BhY89Jq9oYwB0unQ== 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 4Rs91H4YkMzx07; Thu, 21 Sep 2023 22:24:19 +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 38LMOJTQ090852; Thu, 21 Sep 2023 22:24:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38LMOJJ8090849; Thu, 21 Sep 2023 22:24:19 GMT (envelope-from git) Date: Thu, 21 Sep 2023 22:24:19 GMT Message-Id: <202309212224.38LMOJJ8090849@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: a015b9e690d8 - releng/14.0 - 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/releng/14.0 X-Git-Reftype: branch X-Git-Commit: a015b9e690d87c45c73dd08840712f576894dbf9 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=a015b9e690d87c45c73dd08840712f576894dbf9 commit a015b9e690d87c45c73dd08840712f576894dbf9 Author: Alan Somers AuthorDate: 2023-09-12 01:20:39 +0000 Commit: Alan Somers CommitDate: 2023-09-21 22:23:47 +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 Approved by: gjb (re) (cherry picked from commit 0b294a386d34f6584848ed52407687df7ae59861) (cherry picked from commit a39aac5bb8e46b0d9cd77e85be8a65808f8a89ce) --- 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;