diff mbox series

[nf,4/4] netfilter: ipset: hash:ip,port,net: stop IPv4 range walk at upper bound

Message ID bd39fa4962c67bb0d1cfe4dfb9f1abd5ae0c99a7.1778482529.git.tonanli66@gmail.com
State Accepted, archived
Delegated to: Florian Westphal
Headers show
Series [nf,1/4] netfilter: ipset: stop hash:ip,mark range iteration at end | expand

Commit Message

Ren Wei May 12, 2026, 8:50 a.m. UTC
From: Nan Li <tonanli66@gmail.com>

The IPv4 range expansion path in hash:ip,port,net updates the first
dimension iterator in the loop control statement. When the requested
range reaches the last IPv4 address, the iterator can wrap before the
loop terminates.

Handle the increment explicitly at the end of the loop and stop once
the upper bound has been processed. This keeps the range walk bounded
to the requested interval and preserves the existing retry behaviour.

Fixes: 48596a8ddc46 ("netfilter: ipset: Fix adding an IPv4 range containing more than 2^31 addresses")
Cc: stable@kernel.org
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Nan Li <tonanli66@gmail.com>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
---
 net/netfilter/ipset/ip_set_hash_ipportnet.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/netfilter/ipset/ip_set_hash_ipportnet.c b/net/netfilter/ipset/ip_set_hash_ipportnet.c
index 5c6de605a9fb..2d6652d43199 100644
--- a/net/netfilter/ipset/ip_set_hash_ipportnet.c
+++ b/net/netfilter/ipset/ip_set_hash_ipportnet.c
@@ -274,7 +274,7 @@  hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
 		p = port;
 		ip2 = ip2_from;
 	}
-	for (; ip <= ip_to; ip++) {
+	for (; ip <= ip_to;) {
 		e.ip = htonl(ip);
 		for (; p <= port_to; p++) {
 			e.port = htons(p);
@@ -298,6 +298,9 @@  hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
 			ip2 = ip2_from;
 		}
 		p = port;
+		if (ip == ip_to)
+			break;
+		ip++;
 	}
 	return ret;
 }