Date: Tue, 25 Oct 2022 02:50:01 +0000 From: Brooks Davis <brooks@freebsd.org> To: Mark Johnston <markj@freebsd.org> Cc: jhb@freebsd.org, freebsd-virtualization@freebsd.org Subject: Re: bhyve nvlist constness bug Message-ID: <20221025025001.GA33111@spindle.one-eyed-alien.net> In-Reply-To: <Y1WFjpZ8zzVOrhTK@nuc> References: <Y1WFjpZ8zzVOrhTK@nuc>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20221025025001.GA33111>