Skip to content

addr_matches_if_netmask: mask the address for a dotted IPv6 netmask - #599

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:ipv6-netmask-mask-addr
Nov 15, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:ipv6-netmask-mask-addr

Conversation

@iefa-m

@iefa-m iefa-m commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

addr_matches_if_netmask() masks the target address with the netmask for IPv4 and for an IPv6 prefix length, but when the IPv6 netmask is written as an address (host 2001:db8::1/ffff:ffff:ffff:ffff::) the mask comes from inet_pton() and the address is never masked. The match loop then compares each interface address ANDed with the mask against the unmasked target, so a network/netmask entry whose address has host bits set does not match the local host, while the equivalent /64 prefix form does.

Mask the address once the netmask is known, the same way the IPv4 path does. A plain host = ... rule written this way fails closed, but a negated entry used as an exclusion (ALL, !2001:db8:mgmt::1/ffff:ffff:ffff:ffff::) fails open: the missed match drops the exclusion so the host is no longer denied. I checked it by calling addr_matches() against a fixed interface list containing 2001:db8:1:2::5: 2001:db8:1:2::abcd/64 and the equivalent 2001:db8:1:2::abcd/ffff:ffff:ffff:ffff:: now both match, the IPv4 prefix and dotted forms are unchanged, and an out-of-network address still does not match.

The IPv4 path and the IPv6 prefix-length path AND the netmask into the
address before comparing it to the local interfaces, but when an IPv6
netmask is given in address form (host 2001:db8::1/ffff:ffff:ffff:ffff::)
the mask is taken from inet_pton() and the address is never masked.  The
match loop then compares each interface address ANDed with the mask
against the unmasked target, so an entry whose address has host bits set
does not match, unlike the equivalent /64 prefix form.

Mask the address once the netmask is known, as the IPv4 path already
does.
@millert
millert merged commit 40e1489 into sudo-project:main Nov 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants