From 190829705e315972a7c674d2fa55d322aa18d26e Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 5 Dec 2024 15:26:02 +1100 Subject: [PATCH] flow: Remove over-zealous sanity checks in flow_sidx_hash() In flow_sidx_hash() we verify that the flow we're hashing doesn't have an unspecified endpoint address, or zero for either port. The hash table only works if we're looking for exact matches of address and port, and this is attempting to catch any cases where we might have left address or port unpopulated or filled with a wildcard. This doesn't really work though, because there are cases where unspecified addresses or zero ports are correct: * We already use unspecified addresses for our address in cases where we don't know the specific local address for that side, and exclude the obvious extra check on side->oaddr for that reason. * Zero port numbers aren't strictly forbidden over the wire. We forbid them for TCP & UDP because they can't safely be handled on the socket side. However for ICMP a zero id, which goes in the port field is valid. * Possible future flow types (for example, for multicast protocols) might legitimately have an unspecified address. Although it makes them easier to miss, these sorts of sanity checks really have to be done at the protocol / flow type layer, and we already do so. Remove the checks in flow_sidx_hash() other than checking that the pif is specified. Reported-by: Stefan Link: https://bugs.passt.top/show_bug.cgi?id=105 Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- flow.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/flow.c b/flow.c index 1ea112b..ee1221b 100644 --- a/flow.c +++ b/flow.c @@ -597,12 +597,7 @@ static uint64_t flow_sidx_hash(const struct ctx *c, flow_sidx_t sidx) const struct flowside *side = &f->side[sidx.sidei]; uint8_t pif = f->pif[sidx.sidei]; - /* For the hash table to work, entries must have complete endpoint - * information, and at least a forwarding port. - */ - ASSERT(pif != PIF_NONE && !inany_is_unspecified(&side->eaddr) && - side->eport != 0 && side->oport != 0); - + ASSERT(pif != PIF_NONE); return flow_hash(c, FLOW_PROTO(f), pif, side); }