Skip to content

Commit 5750313

Browse files
Fix Y2038 netlink sequence number in libbpf- sonic-net#606
Signed-off-by: Subhasri-Ramasamy <subharam@cisco.com>
1 parent 67e357a commit 5750313

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: SONiC Build <build@sonic.net>
3+
Date: Thu, 6 Aug 2026 12:00:00 +0000
4+
Subject: [PATCH] libbpf: Fix Y2038 netlink sequence number in libbpf_netlink_send_recv
5+
6+
Coverity CID 3439741 (Y2K38_SAFETY): libbpf_netlink_send_recv() used
7+
time(NULL) to seed nlmsg_seq, implicitly truncating 64-bit time_t into
8+
the 32-bit nlmsg_seq field.
9+
10+
Netlink sequence numbers only need to match responses to requests and
11+
should be monotonically increasing; a timestamp is unnecessary. Use a
12+
static counter instead and drop the unused time.h include.
13+
14+
Signed-off-by: SONiC Build <build@sonic.net>
15+
---
16+
tools/lib/bpf/netlink.c | 5 +++--
17+
1 file changed, 3 insertions(+), 2 deletions(-)
18+
19+
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
20+
--- a/tools/lib/bpf/netlink.c
21+
+++ b/tools/lib/bpf/netlink.c
22+
@@ -12,8 +12,6 @@
23+
#include <linux/rtnetlink.h>
24+
#include <linux/tc_act/tca_bpf.h>
25+
#include <errno.h>
26+
-#include <time.h>
27+
-
28+
#include "bpf.h"
29+
#include "libbpf.h"
30+
#include "libbpf_internal.h"
31+
@@ -219,6 +217,8 @@ done:
32+
return ret;
33+
}
34+
35+
+static __u32 libbpf_nlmsg_seq;
36+
+
37+
static int libbpf_netlink_send_recv(struct libbpf_nla_req *req,
38+
int proto, __dump_nlmsg_t parse_msg,
39+
libbpf_dump_nlmsg_t parse_attr,
40+
@@ -232,7 +232,7 @@ static int libbpf_netlink_send_recv(struct libbpf_nla_req *req,
41+
return sock;
42+
43+
req->nh.nlmsg_pid = 0;
44+
- req->nh.nlmsg_seq = time(NULL);
45+
+ req->nh.nlmsg_seq = ++libbpf_nlmsg_seq;
46+
47+
if (send(sock, req, req->nh.nlmsg_len, 0) < 0) {
48+
ret = -errno;

0 commit comments

Comments
 (0)