From 8c53e3a35c667d57ff5b27666806171206b951e9 Mon Sep 17 00:00:00 2001 From: iefa m Date: Sun, 15 Nov 2026 14:50:51 +0530 Subject: [PATCH] addr_matches_if_netmask: mask the address for a dotted IPv6 netmask 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. --- plugins/sudoers/match_addr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/sudoers/match_addr.c b/plugins/sudoers/match_addr.c index 81f8d4ccd6..00175ce2fc 100644 --- a/plugins/sudoers/match_addr.c +++ b/plugins/sudoers/match_addr.c @@ -141,16 +141,18 @@ addr_matches_if_netmask(const char *n, const char *m) "IPv6 netmask %s: %s", m, errstr); debug_return_int(DENY); } - for (i = 0; i < sizeof(addr.ip6.s6_addr); i++) { + for (i = 0; i < sizeof(mask.ip6.s6_addr); i++) { if (j < i * 8) mask.ip6.s6_addr[i] = 0; else if (i * 8 + 8 <= j) mask.ip6.s6_addr[i] = 0xff; else mask.ip6.s6_addr[i] = 0xff00 >> (j - i * 8); - addr.ip6.s6_addr[i] &= mask.ip6.s6_addr[i]; } } + /* Mask off the address bits, as we do for IPv4. */ + for (i = 0; i < sizeof(addr.ip6.s6_addr); i++) + addr.ip6.s6_addr[i] &= mask.ip6.s6_addr[i]; } #endif /* HAVE_STRUCT_IN6_ADDR */