On 10 Nov 2026, at 20:48, Aaron Conole via dev wrote:

> random_uint32() is a xorshift32 PRNG (see lib/random.c): it holds many
> properties including uniformity and reversibility, so recovering the
> internal state from any single observed output lets an attacker compute
> every other output of that (per-thread) stream, forward and backward.
> Using it for anything security-relevant is documented in random.c
> itself as inappropriate.
>
> ct->hash_basis salts every conntrack hash table, to include
> connection, zone, timeout policy and ALG expectation lookups and it is
> also the secret input to NAT tuple selection.  Most NAT tuple
> selection does not call random_uint32() directly.  Instead,
> nat_get_unique_tuple() picks both the NAT
> address (get_addr_in_range()) and, in the common case, the NAT
> port (set_sport_range()/set_dport_range()) via nat_range_hash(), a
> deterministic hash of the flow tuple mixed with that single 32-bit
> value, which was previously drawn once from random_uint32() at
> conntrack_init() time.  An attacker able to recover the xorshift state
> feeding that one random_uint32() call, e.g. by observing any other
> output drawn from the same per-thread PRNG stream elsewhere in the
> process, would learn the basis and could then predict every NAT tuple
> ovs-vswitchd assigns for the lifetime of the process.
>
> Two narrower paths draw directly from random_uint32() per new
> connection rather than through the hash: the 'nat(...,random)' port
> path, and the retry offset used when the hash-selected port collides
> with an existing connection under range congestion.  These are
> directly observable per-connection outputs.
>
> Fix this by drawing ct->hash_basis, and the two per-connection port
> paths above, from a cryptographic source: the recently added CSPRNG
> support in random.c which is a ChaCha20 based CSPRNG.  Conntrack
> randomness is then independent of every other random_uint32()
> consumer, and the per-connection draws are no longer part of a
> reversible stream.  A zero basis is redrawn because
> nat_get_unique_tuple() reads it as the NAT_PERSISTENT case.
>
> This does not, by itself, make hash-selected tuples unpredictable:
> nat_range_hash() has only the 32-bit basis as a secret, so an attacker
> observing a few translated tuples can still search for it offline.
> Hardening the selection function against that is a separate problem.
>
> Signed-off-by: Aaron Conole <[email protected]>

This patch looks good to me.

Acked-by: Eelco Chaudron <[email protected]>
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to