Guest API answers a connection as another instance after a pid is reused
Description
Originally reported in Incus: GHSA-63p9-v6jg-fvvp.
The guest API records the peer's credentials once, when a connection is accepted, and resolves which instance to answer as from the recorded pid number on every subsequent request. Nothing ties that number to the process that opened the connection.
A caller inside an instance can hold connections open from children that have since exited, drive the host's pid counter past its wrap point and stop. The next process created in another instance receives one of the held pid numbers, and requests on that connection are then answered as that other instance. The only additional check compares the instance's root uid, which is identical for every instance sharing the default id map.
This exposes the other instance's user.* and cloud-init.* configuration, which commonly carries passwords and tokens, along with its metadata and device list, across project boundaries, in the default configuration.
Instances configured with security.idmap.isolated=true are not affected.
All supported branches are affected.