Skip to contentSkip to conversation

netfilter: ipset: stop hash:ip,mark range iteration at end

PATCH New Ren Wei 1 participant 4 messages May 12 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

PATCH 1/4 netfilter: ipset: stop hash:ip,mark range iteration at end

From: Nan Li <[email protected]>

hash:ip,mark iterates IPv4 ranges with a 32-bit iterator.

The iterator must stop once the last address in the requested range has been processed. Advancing it once more can move the traversal state past the end of the request, so a later retry may continue from an unintended position.

Handle the iterator increment explicitly at the end of the loop and stop once the upper bound has been processed. This keeps the existing retry behaviour intact for valid ranges while preventing traversal from continuing past the original boundary.

Fixes 48596a8ddc46 ("netfilter: ipset: Fix adding an IPv4 range containing more than 2^31 addresses")
---
 net/netfilter/ipset/ip_set_hash_ipmark.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_ipmark.c +5 -1
index a22ec1a6f6ec..e26ca2a370e3 100644
@@ -150,7 +150,7 @@ hash_ipmark4_uadt(struct ip_set *set, struct nlattr *tb[],
 
 	if (retried)
 		ip = ntohl(h->next.ip);
-	for (; ip <= ip_to; ip++, i++) {
+	for (; ip <= ip_to; i++) {
 		e.ip = htonl(ip);
 		if (i > IPSET_MAX_RANGE) {
 			hash_ipmark4_data_next(&h->next, &e);
@@ -162,6 +162,10 @@ hash_ipmark4_uadt(struct ip_set *set, struct nlattr *tb[],
 			return ret;
 
 		ret = 0;
+
+		if (ip == ip_to)
+			break;
+		ip++;
 	}
 	return ret;
 }
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/4 netfilter: ipset: stop hash:ip,port,ip range iteration at end

In reply to a message not in the archive

From: Nan Li <[email protected]>

hash:ip,port,ip iterates IPv4 ranges with a 32-bit iterator.

The iterator must stop once the last address in the requested range has been processed. Advancing it once more can move the traversal state past the end of the request, so a later retry may continue from an unintended position.

Stop the outer IPv4 loop after the end of the requested range is handled. This keeps the existing retry behavior intact for valid ranges while preventing traversal from continuing past the original boundary.

Fixes 48596a8ddc46 ("netfilter: ipset: Fix adding an IPv4 range containing more than 2^31 addresses")
---
 net/netfilter/ipset/ip_set_hash_ipportip.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_ipportip.c +4 -1
index 39a01934b153..b9ac2efaa15c 100644
@@ -182,7 +182,7 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],
 
 	if (retried)
 		ip = ntohl(h->next.ip);
-	for (; ip <= ip_to; ip++) {
+	for (; ip <= ip_to;) {
 		p = retried && ip == ntohl(h->next.ip) ? ntohs(h->next.port)
 						       : port;
 		for (; p <= port_to; p++, i++) {
@@ -199,6 +199,9 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],
 
 			ret = 0;
 		}
+		if (ip == ip_to)
+			break;
+		ip++;
 	}
 	return ret;
 }
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH 3/4 netfilter: ipset: stop hash:ip,port range iteration at end

In reply to a message not in the archive

From: Nan Li <[email protected]>

hash:ip,port iterates IPv4 ranges with a 32-bit iterator.

The iterator must stop once the last address in the requested range has been processed. Advancing it once more can move the traversal state past the end of the request, so a later retry may continue from an unintended position.

Stop the outer IPv4 loop after the end of the requested range is handled. This keeps the existing retry behavior intact for valid ranges while preventing traversal from continuing past the original boundary.

Fixes 48596a8ddc46 ("netfilter: ipset: Fix adding an IPv4 range containing more than 2^31 addresses")
---
 net/netfilter/ipset/ip_set_hash_ipport.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_ipport.c +4 -1
index e977b5a9c48d..41ca24a22a02 100644
@@ -186,7 +186,7 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],
 
 	if (retried)
 		ip = ntohl(h->next.ip);
-	for (; ip <= ip_to; ip++) {
+	for (; ip <= ip_to;) {
 		p = retried && ip == ntohl(h->next.ip) ? ntohs(h->next.port)
 						       : port;
 		for (; p <= port_to; p++, i++) {
@@ -203,6 +203,9 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],
 
 			ret = 0;
 		}
+		if (ip == ip_to)
+			break;
+		ip++;
 	}
 	return ret;
 }
Signature · 1 line
2.43.0
author
#4 lore raw

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

In reply to a message not in the archive

From: Nan Li <[email protected]>

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")
---
 net/netfilter/ipset/ip_set_hash_ipportnet.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_ipportnet.c +4 -1
index 5c6de605a9fb..2d6652d43199 100644
@@ -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;
 }
Signature · 1 line
2.43.0