From nobody Tue Oct 25 02:50:01 2022 X-Original-To: freebsd-virtualization@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 4MxGdF0CHdz4gMCQ for ; Tue, 25 Oct 2022 02:50:09 +0000 (UTC) (envelope-from brooks@spindle.one-eyed-alien.net) Received: from spindle.one-eyed-alien.net (spindle.one-eyed-alien.net [199.48.129.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4MxGdC51x9z3bhn; Tue, 25 Oct 2022 02:50:07 +0000 (UTC) (envelope-from brooks@spindle.one-eyed-alien.net) Received: by spindle.one-eyed-alien.net (Postfix, from userid 3001) id 9F60B3C0199; Tue, 25 Oct 2022 02:50:01 +0000 (UTC) Date: Tue, 25 Oct 2022 02:50:01 +0000 From: Brooks Davis To: Mark Johnston Cc: jhb@freebsd.org, freebsd-virtualization@freebsd.org Subject: Re: bhyve nvlist constness bug Message-ID: <20221025025001.GA33111@spindle.one-eyed-alien.net> References: List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="fdj2RfSjLxBAspz7" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspamd-Queue-Id: 4MxGdC51x9z3bhn X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of brooks@spindle.one-eyed-alien.net has no SPF policy when checking 199.48.129.229) smtp.mailfrom=brooks@spindle.one-eyed-alien.net X-Spamd-Result: default: False [-3.89 / 15.00]; SIGNED_PGP(-2.00)[]; AUTH_NA(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-0.99)[-0.991]; FORGED_SENDER(0.30)[brooks@freebsd.org,brooks@spindle.one-eyed-alien.net]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; MLMMJ_DEST(0.00)[freebsd-virtualization@freebsd.org]; ASN(0.00)[asn:36236, ipnet:199.48.128.0/22, country:US]; MIME_TRACE(0.00)[0:+,1:+,2:~]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; R_SPF_NA(0.00)[no SPF record]; DMARC_NA(0.00)[freebsd.org]; FREEFALL_USER(0.00)[brooks]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[brooks@freebsd.org,brooks@spindle.one-eyed-alien.net]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-ThisMailContainsUnwantedMimeParts: N --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 23, 2022 at 02:18:54PM -0400, Mark Johnston wrote: > I'm going through compiler warnings in the bhyve code with the aim of > bumping WARNS, since the current setting hides bugs. There's one in the > config code that looks a bit tricky to resolve and I was hoping for some > guidance on the right way to do that. >=20 > The basic problem is _lookup_config_node() may return an nvlist via > nvlist_get_nvlist(), but nvlist_get_nvlist() returns a const nvlist_t > *, so _lookup_config_node() is discarding the const qualifier. And > indeed, some callers will modify the returned node. The use of > nvlist_move_nvlist() in _lookup_config_node() has a similar problem: > nvlist_move_* "consumes" the passed value and is not supposed to be > mutated after. >=20 > I'm pretty sure this is actually a non-issue with our nvlist > implementation; when adding an nvlist value to an nvlist, it doesn't > store anything except for the pointer itself, so you can mutate it > safely. Note, this is not true for all value types, specifically > arrays. However, there are multiple nvlist implementations out there, > and ours might change such that bhyve's config code becomes incorrect. >=20 > The bug seems annoying to fix because consumers can do this: >=20 > nvlist_t *nvl =3D find_config_node(path); > set_config_value_node(nvl, "foo", "bar"); Probalby not entirely relevant, but FWIW, there are comments in the OpenZFS nvpair implementation that basically say you can't pass a const nvlist (or string or array) to nvlist_add_*. /* * This discards the const from nvp, so all callers for these * types must not accept const nvpairs. */ -- Brooks --fdj2RfSjLxBAspz7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJjV07YAAoJEKzQXbSebgfAOEgH/Ak1ConhuBwuF0Qiy2hv9m3W vXM8TrNQsrUT0FmtkqxCuk/k3xf+YeJN8NZe1YnaAVZ4B/tQ6NW7+XCqlLUYzqNT RQj+RQxZ8h67flAqSa7TchI17NUTxuSLOFZy+Dg+kia5L74oao1Pg5Qel+J6iSvx UYeKiES/DEakQgdSSs51lLOhZ5weKydgCCKBdPd7N7tPQKRgCqF13vWEldf1HYPy nWROcNrr8seLZrtTE6hmVZfvnT9luSBmqrDRWp0wiuVFxfrC8wh8btjoUv1cSmGG KPICML8FwgtG3WDoaaG2VD2cW0bBR3sXEBTIAkTM9iFXHOAeMaV5+GZLYkv/UrY= =Sd6L -----END PGP SIGNATURE----- --fdj2RfSjLxBAspz7--