From nobody Thu Sep 21 22:21:40 2023 X-Original-To: dev-commits-src-branches@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 4Rs8yD6Qg3z4v4tm; Thu, 21 Sep 2023 22:21:40 +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 4Rs8yD5xwbz4GGj; Thu, 21 Sep 2023 22:21:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695334900; 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=nelOBqjwlxJdRFD6FZVcwS+f5xkrnMyrEjju800w00A=; b=Ap3bBay1pGZeJb2U4fljKMZOpFrZ8wGTSSvd2zEPv72jhU952sTcfIxoPQivWICPXMkRjp kt4Fngh0FZon7tG3hwuQFg1dTPaoBVJr557xJrlU0gguPELcgx/1fCqe0bxNam8xPdkDka dDtbgc3cx3KpbUM9hjVDkhhqKTm+NLYIy6BAJceCbXgWqKzFI9ekmbGWOcFMJEf1CLYwVk DC+BJaHyIwPr+5lwLSL8+FYIWQl/Wgd4JorUWuQVt+znW5hkfky5X7Qb+z6X8tO66YlkoK 1f4Px+fKj8Xnqqsx/P3cHJQjddFfaFjehtCDFWj2GiUwCOQzi9lSNXipENK/mQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695334900; a=rsa-sha256; cv=none; b=qJH9R0+LYJffvj/R1p9og0U2QUBkwiGpDnm1tj3CoOGJYQgtiKer1FfEOScOQzT4xR/Msf K+t5UPcKShu9qkfVxtN257zSf1LOV/TBUz1/g9ZplU7cLKOm2QOWF0ahFAuY5Hp0eLkHcZ cPVgsBkavweLGjLNmrqreIDuVwUAE/eM7PJE02XB3Jc+jH36gPXfcjyoyT9+o+sBrxjsCG P2OJXZNOkKSR+agIwMdP6Ja8MAcQDyaNXFyKkZ2PRz+AjZ4jK3K26ZadHnOb6oENqQmWLD UXgTHTyBPx047M49tMD+p21ovbznHCAQ1e4I1/dLTiszQ+QyMoF2ofBxlb1Jew== 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=1695334900; 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=nelOBqjwlxJdRFD6FZVcwS+f5xkrnMyrEjju800w00A=; b=SA5Y7y5j+v+EWjoxtr50BPQMyGqmJiRI6nifv3prxBpUqlO8eXMafCOEp+nFX/qQJKUzaj MKo/+1kh4nRQMIdHMrWzMPR3Ov7fRmGu3Nds+IkAS8kAFHf1iN06NaXGhJwlD6JZAwupaw smiy4ISHMJCkS88cWb+YsGDnCsulEqXoXbUAUkbD+q+tr/AHH94wwZiGLMja7GTMVtwYRy TZreqaCjUpLNAw7INs+kIKfTMwJQaY5oBArz1ZqfnnkZ3NAjgIIQJ+pQniEiHhEz+hJM4G h2Tkf6f1g7g8O2qQq/+9Gfbd3CDADJ08a9CSiIY0uVduhK4hEO1SlK9BQJOHAg== 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 4Rs8yD5195zwyh; Thu, 21 Sep 2023 22:21:40 +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 38LMLe6m088484; Thu, 21 Sep 2023 22:21:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38LMLeOh088481; Thu, 21 Sep 2023 22:21:40 GMT (envelope-from git) Date: Thu, 21 Sep 2023 22:21:40 GMT Message-Id: <202309212221.38LMLeOh088481@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: 3676929d3cae - stable/13 - Fix zfsd with the device_removal pool feature. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 3676929d3caea131170a48f8e054299d68c81ec5 Auto-Submitted: auto-generated The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=3676929d3caea131170a48f8e054299d68c81ec5 commit 3676929d3caea131170a48f8e054299d68c81ec5 Author: Alan Somers AuthorDate: 2023-09-12 01:20:39 +0000 Commit: Alan Somers CommitDate: 2023-09-21 22:20:43 +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 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 5a515f91e2ec..e2294856b87d 100644 --- a/cddl/usr.sbin/zfsd/vdev_iterator.cc +++ b/cddl/usr.sbin/zfsd/vdev_iterator.cc @@ -100,10 +100,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;