Netdev List
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, dsahern@kernel.org,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH iproute2-main] libnetlink: handle failed time seeds and sequence wrap
Date: Tue,  3 Nov 2026 13:59:32 -0800	[thread overview]
Message-ID: <20261103215932.1191741-1-f.fainelli@gmail.com> (raw)

A 32-bit time_t overflows when the board clock is beyond 2038. time()
returns -1, and the first request then has sequence zero. The sequence
range check underflows and discards the valid reply, leaving ip blocked
in recvmsg(). The same range check also fails on a normal counter wrap.

Use zero as a fallback seed when time() fails. Compare the unsigned
sequence distance against the number of requests, allowing wraparound
and rejecting the sequence immediately before the first request.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 lib/libnetlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index edf3a8ba7ce0..5bc7c43245fb 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -194,6 +194,7 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
 		      int protocol)
 {
 	socklen_t addr_len;
+	time_t now;
 	int sndbuf = 32768;
 	int one = 1;
 
@@ -246,7 +247,8 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
 			rth->local.nl_family);
 		goto err;
 	}
-	rth->seq = time(NULL);
+	now = time(NULL);
+	rth->seq = now == (time_t)-1 ? 0 : (__u32)now;
 	return 0;
 err:
 	rtnl_close(rth);
@@ -1092,7 +1094,7 @@ next:
 
 			if (nladdr.nl_pid != 0 ||
 			    h->nlmsg_pid != rtnl->local.nl_pid ||
-			    h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) {
+			    (unsigned int)(seq - h->nlmsg_seq) >= iovlen) {
 				/* Don't forget to skip that message. */
 				status -= NLMSG_ALIGN(len);
 				h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
-- 
2.53.0


             reply	other threads:[~2026-11-03 22:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 21:59 Florian Fainelli [this message]
2026-11-09  1:58 ` [PATCH iproute2-main] libnetlink: handle failed time seeds and sequence wrap Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103215932.1191741-1-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox