diff options
| author | Eric Dumazet <edumazet@google.com> | 2026-03-02 19:39:33 +0300 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-03-05 03:51:10 +0300 |
| commit | c26b8c4e291c55c7b2138d7bcb27348ca3a5ae59 (patch) | |
| tree | db9a44805f438b49c9272ef9e93e1f665396a375 /net | |
| parent | 98d95000bb1207f86a0e5876755ac2308ac86d2d (diff) | |
| download | linux-c26b8c4e291c55c7b2138d7bcb27348ca3a5ae59.tar.xz | |
net: fix off-by-one in udp_flow_src_port() / psp_write_headers()
udp_flow_src_port() and psp_write_headers() use ip_local_port_range.
ip_local_port_range is inclusive : all ports between min and max
can be used.
Before this patch, if ip_local_port_range was set to 40000-40001
40001 would not be used as a source port.
Use reciprocal_scale() to help code readability.
Not tagged for stable trees, as this change could break user
expectations.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260302163933.1754393-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net')
| -rw-r--r-- | net/psp/psp_main.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c index d4c04c923c5a..9508b6c38003 100644 --- a/net/psp/psp_main.c +++ b/net/psp/psp_main.c @@ -202,7 +202,7 @@ static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi, * reciprocal divide. */ hash ^= hash << 16; - uh->source = htons((((u64)hash * (max - min)) >> 32) + min); + uh->source = htons(reciprocal_scale(hash, max - min + 1) + min); } else { uh->source = udp_flow_src_port(net, skb, 0, 0, false); } |
