[Git][NTPsec/ntpsec][master] ntpd/ntp_io.c: stop netlink walk when cnt goes negative

Matt Selsky (@selsky) gitlab at mg.gitlab.com
Wed Oct 28 01:46:46 UTC 2026



Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
8311a3e5 by Matt Selsky at 2026-10-26T23:02:05+00:00
ntpd/ntp_io.c: stop netlink walk when cnt goes negative

NLMSG_NEXT() subtracts the 4-byte-aligned length of each message from
cnt, so after a final message whose length is not a multiple of 4, cnt
goes slightly negative. Cast to an unsigned type for NLMSG_OK(), that
becomes a huge length, and the loop keeps parsing whatever stale bytes
follow the data in buffer until it crashes. Jorge Sauma hit this during
VRF switches (NTPsec/ntpsec!1558).

Stop the loop on the signed value before NLMSG_OK() sees it.

Reported-by: Jorge Sauma <jorge.sauma at hpe.com>

- - - - -


1 changed file:

- ntpd/ntp_io.c


Changes:

=====================================
ntpd/ntp_io.c
=====================================
@@ -3062,7 +3062,8 @@ process_routing_msgs(struct asyncio_reader *reader)
 	 */
 #ifdef HAVE_LINUX_RTNETLINK_H
 	for (nh = (struct nlmsghdr *)buffer;
-	     NLMSG_OK(nh, (unsigned) cnt);
+	     cnt >= (ssize_t)sizeof(struct nlmsghdr)
+	     && NLMSG_OK(nh, (size_t)cnt);
 	     nh = NLMSG_NEXT(nh, cnt)) {
 		msg_type = nh->nlmsg_type;
 #else



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/8311a3e58fc9219905e2055db4a5ea2bb24050ed

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/8311a3e58fc9219905e2055db4a5ea2bb24050ed
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20261028/8ea094b0/attachment.htm>


More information about the vc mailing list