On Sun, May 03, 2026 at 11:56:08PM +0200, Stefano Brivio wrote:
On Sun, 26 Apr 2026 11:31:24 +1000 David Gibson
wrote: On Sat, Apr 25, 2026 at 11:31:40AM -0400, Jon Maloy wrote:
On 2026-04-21 02:24, David Gibson wrote:
Although fwd_rule_add() performs some sanity checks on the rule it is given, there are invalid rules we don't check for, assuming that its callers will do that.
diff --git a/fwd.c b/fwd.c index c7fd1a9d..979c1494 100644 --- a/fwd.c +++ b/fwd.c @@ -367,17 +367,59 @@ int fwd_rule_add(struct fwd_table *fwd, const struct fwd_rule *new) new->first, new->last); return -EINVAL; } + if (!new->first) { + warn("Forwarding rule attempts to map from port 0"); + return -EINVAL; + } + if (!new->to || + (in_port_t)(new->to + new->last - new->first) < new->to) { + warn("Forwarding rule attempts to map to port 0");
Not strictly true. We are also catching a range overflow case. Maybe "Forwarding rule maps to invalid port number"
Well.. the specific overflow case is that the target range "wraps around", thereby covering port 0, is the reasoning here.
...and any other range overflow case is covered by the earlier check:
if (new->first > new->last) { warn("Rule has invalid port range %u-%u", new->first, new->last); return -EINVAL; }
so I'm leaving this as it was, in v6.
Right, that's pretty much what I was suggesting. -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson