hash_netportnet4_uadt() canonicalizes the port to zero for protocols without ports and clears with_ports. The range path nevertheless reads IPSET_ATTR_PORT_TO and iterates the supplied port range. A request with an address range and a portless protocol can therefore add keys that packet-side matching never generates, consuming maxelem or evicting valid entries when forceadd is enabled. Only expand the port dimension when the protocol supports ports. Address ranges continue to be processed with the canonical zero port. Fixes: 7c3ad056ef79 ("netfilter: ipset: Add hash:net,port,net module to kernel.") Cc: stable@vger.kernel.org Reported-by: Vega Link: https://bugtracker.nebusec.ai/f/12359 Assisted-by: LLM Signed-off-by: Zhiling Zou --- net/netfilter/ipset/ip_set_hash_netportnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/ipset/ip_set_hash_netportnet.c b/net/netfilter/ipset/ip_set_hash_netportnet.c index 61af1ce271279..dd6cf8c36ba07 100644 --- a/net/netfilter/ipset/ip_set_hash_netportnet.c +++ b/net/netfilter/ipset/ip_set_hash_netportnet.c @@ -278,7 +278,7 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[], } port_to = port = ntohs(e.port); - if (tb[IPSET_ATTR_PORT_TO]) { + if (with_ports) { port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]); if (port > port_to) swap(port, port_to);