From nobody Tue Sep 30 21:14:44 2025 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 4cbrRS6jmxz69Lxv; Tue, 30 Sep 2025 21:14:44 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cbrRS1gwnz3tG0; Tue, 30 Sep 2025 21:14:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759266884; 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=AlVkPxMxJM14F9FZqpNTHi1tLmU4O5XlYJkKPsyMbn8=; b=sutQlMQbdhenmyhf/z5T/4U5TUo1J4aueVBuDmPsXcndjiPPIP6TJ4N2wPRX+9J+Dd0kXW Y/YbHk5S2//k9D11tQnUb1EftvX2pgbmHSlv7UyyxJlumKb7CMSRpmi7DTFiegIVUr9t7B xVJnhL5AdCNF80OvYjJqivr/DNJCS+aNFK7GVUXQSfzObv6K1PK0+6FZF7cvdJ+U2wdDVR 0MKiR3gOyCMKlugF+2VELwFOHYoXMbtsGdg1idddmi8aex4vHcS5cWFRLNulZwSBneLqoK PRHXGMvDFtp9taAQt5K/sUxhUK0ySLWRfKuv2RZndRszEEvBwfu6byivev6egA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759266884; 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=AlVkPxMxJM14F9FZqpNTHi1tLmU4O5XlYJkKPsyMbn8=; b=X1vDCuGrJI5RMO146SNWrU/ZCOygWGOHdKbs83bEOh0whIiE9aH03Iyi5zfTUfGipXun2G BKALnPpOntQpBFApBzhYVOemsohOolVvtmJZSBNmh/JqgbkX1pFt4c9kp/czr/mqnfu2JL kOF8a91CZxlsciLKZRtxylEd6VJzneRoH1zXSAHbpofQjdbfZJv53IE6zB3DUPXFpVCXI3 zk1bb7CcJkrxa4y/sJJokdX9Cd2Upeb+hq2D7wT5G0rWEMqof0GjLi2IN/nlpLuitOmx7+ UiIQUJ+gxqkvwJ8U5mTXTafBdV32fS6n/XuZnSx9+ni+8pwgJQwZUD4iK+aPgw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759266884; a=rsa-sha256; cv=none; b=hlN/e8A78swiXIJJvtNXgZLVsJBEguTwjkLcJS+XvxunBBipbCzgFb5dozXe2DiOaicuHJ n5M+cTuAQV7/pc20Zo226yibAe1lQR5b9jYpqiS101yfq82DnPl3sZEdFiPVHWpwWYJCkQ GIpK9BD2nOMd6u78r71TTsa/jxYeGGAxrDbGPqxR2wa0IFNwtsJvbF+3QoaJ88H3Vgbtoj wH7IyOmawx4fKoxzwxkjRjSCulFk+3gOlqVpmh6zuREk0iB/PP5K4+usDU0O8mcQeYy8cd 6Lfc9wUMlf1dFHTngzqDK5yJVnr5MQ/dM++kVp+MWYsw0QR99thAsuW5psx0WQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cbrRS1315ztVD; Tue, 30 Sep 2025 21:14:44 +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 58ULEiBX010465; Tue, 30 Sep 2025 21:14:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58ULEiba010462; Tue, 30 Sep 2025 21:14:44 GMT (envelope-from git) Date: Tue, 30 Sep 2025 21:14:44 GMT Message-Id: <202509302114.58ULEiba010462@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: 72ac96ed8fa9 - stable/14 - libnv: Fix handling of nvlist_dump() and nvlist_send() for child nvlists 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: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: 72ac96ed8fa9415c2be1a5ceb0289b45578ba7bd Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=72ac96ed8fa9415c2be1a5ceb0289b45578ba7bd commit 72ac96ed8fa9415c2be1a5ceb0289b45578ba7bd Author: Mark Johnston AuthorDate: 2025-09-10 14:33:35 +0000 Commit: Mark Johnston CommitDate: 2025-09-30 21:14:29 +0000 libnv: Fix handling of nvlist_dump() and nvlist_send() for child nvlists Suppose an nvlist nvl belongs to a parent nvlist or nvlist array. In this case, nvl contains a pointer to its container. This trips up nvlist_send(nvl) and nvlist_dump(nvl), which intuitively should only operate on nvl and its nvpairs. In particular, both of these functions will traverse to nvl's parent and start sending/dumping the parent's nvpairs, which results in assertion failures or nonsensical output, respectively. Reviewed by: oshogbo MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D52360 (cherry picked from commit 0b68e3ce6e0e437fa480b25a0ef706ee08562257) --- sys/contrib/libnv/nvlist.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/contrib/libnv/nvlist.c b/sys/contrib/libnv/nvlist.c index 92d6e655876a..058ec032d3a3 100644 --- a/sys/contrib/libnv/nvlist.c +++ b/sys/contrib/libnv/nvlist.c @@ -486,7 +486,7 @@ nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level) void nvlist_dump(const nvlist_t *nvl, int fd) { - const nvlist_t *tmpnvl; + const nvlist_t *tmpnvl, *top; nvpair_t *nvp, *tmpnvp; void *cookie; int level; @@ -495,6 +495,7 @@ nvlist_dump(const nvlist_t *nvl, int fd) if (nvlist_dump_error_check(nvl, fd, level)) return; + top = nvl; nvp = nvlist_first_nvpair(nvl); while (nvp != NULL) { dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp), @@ -653,6 +654,8 @@ nvlist_dump(const nvlist_t *nvl, int fd) while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { do { + if (nvl == top) + return; cookie = NULL; if (nvlist_in_array(nvl)) dprintf(fd, "%*s,\n", level * 4, ""); @@ -855,7 +858,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) { unsigned char *buf, *ptr; size_t left, size; - const nvlist_t *tmpnvl; + const nvlist_t *tmpnvl, *top; nvpair_t *nvp, *tmpnvp; void *cookie; @@ -876,6 +879,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) ptr = nvlist_pack_header(nvl, ptr, &left); + top = nvl; nvp = nvlist_first_nvpair(nvl); while (nvp != NULL) { NVPAIR_ASSERT(nvp); @@ -966,6 +970,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) goto fail; while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { do { + if (nvl == top) + goto out; cookie = NULL; if (nvlist_in_array(nvl)) { ptr = nvpair_pack_nvlist_array_next(ptr,