Commit 69942f952c for frr

commit 69942f952c1f3523486d79e5f1244f9a322b6bf6
Author: Donald Sharp <sharpd@nvidia.com>
Date:   Thu Nov 26 15:20:45 2026 -0500

    zebra: fix bounds checks in macOS kernel_ifindex_read()

    The NET_RT_IFLIST loop guarded each iteration with p + sizeof(*ifm) <=
    end (112 bytes on macOS), which silently skipped trailing RTM_NEWADDR
    messages (struct ifa_msghdr is 20 bytes, total ~68-76 bytes). It also
    did not verify ifm->ifm_msglen against the remaining buffer size.

    Check only the common message prefix in the loop guard, validate
    ifm_msglen against min_hdr and remaining buffer length (end - p), and
    verify per-message header size before calling ifm_read() or ifam_read().

    Signed-off-by: Donald Sharp <sharpd@nvidia.com>

diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index e5ac37993b..0201dffa45 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -1631,15 +1631,21 @@ static void kernel_ifindex_read(unsigned int ifindex)
 	 */
 	if (sysctl(mib, 6, buf, &len, NULL, 0) == 0 &&
 	    (len < sizeof(*ifm) || ifm->ifm_type != RTM_IFINFO || ifm->ifm_flags)) {
+		const size_t min_hdr = offsetof(struct if_msghdr, ifm_type) + sizeof(ifm->ifm_type);
+
 		end = buf + len;
-		for (p = buf; p + sizeof(*ifm) <= end; p += ifm->ifm_msglen) {
+		for (p = buf; (size_t)(end - p) >= min_hdr; p += ifm->ifm_msglen) {
 			ifm = (struct if_msghdr *)p;
-			if (ifm->ifm_msglen == 0)
+			if (ifm->ifm_msglen < min_hdr ||
+			    (size_t)ifm->ifm_msglen > (size_t)(end - p))
 				break;
-			if (ifm->ifm_type == RTM_IFINFO)
-				ifm_read(ifm);
-			else if (ifm->ifm_type == RTM_NEWADDR)
-				ifam_read((struct ifa_msghdr *)ifm);
+			if (ifm->ifm_type == RTM_IFINFO) {
+				if (ifm->ifm_msglen >= sizeof(*ifm))
+					ifm_read(ifm);
+			} else if (ifm->ifm_type == RTM_NEWADDR) {
+				if (ifm->ifm_msglen >= sizeof(struct ifa_msghdr))
+					ifam_read((struct ifa_msghdr *)ifm);
+			}
 		}
 	}
 	XFREE(MTYPE_TMP, buf);