[packages/libmnl] Rel 2. Reject nlmsg_len > INT_MAX in mnl_nlmsg_ok().
arekm
arekm at pld-linux.org
Thu Oct 29 08:42:37 CET 2026
commit 363f5c2c1b823c80087a5f53dc7da528ced888a3
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Oct 29 00:47:28 2026 +0100
Rel 2. Reject nlmsg_len > INT_MAX in mnl_nlmsg_ok().
libmnl-nlmsg-ok-len.patch | 62 +++++++++++++++++++++++++++++++++++++++++++++++
libmnl.spec | 11 +++++----
2 files changed, 68 insertions(+), 5 deletions(-)
---
diff --git a/libmnl.spec b/libmnl.spec
index b9852a3..6517fad 100644
--- a/libmnl.spec
+++ b/libmnl.spec
@@ -7,12 +7,14 @@ Summary: A minimalistic user-space library oriented to Netlink developers
Summary(pl.UTF-8): Minimalistyczna biblioteka przestrzeni użytkownika dla programistów Netlinka
Name: libmnl
Version: 1.0.5
-Release: 1
+Release: 2
License: LGPL v2.1+
Group: Libraries
-Source0: http://www.netfilter.org/projects/libmnl/files/%{name}-%{version}.tar.bz2
+Source0: https://www.netfilter.org/projects/libmnl/files/%{name}-%{version}.tar.bz2
# Source0-md5: 0bbb70573119ec5d49435114583e7a49
-URL: http://www.netfilter.org/projects/libmnl/index.html
+# mnl_nlmsg_ok() accepted nlmsg_len > INT_MAX; upstream 754c9de5ea1b
+Patch0: %{name}-nlmsg-ok-len.patch
+URL: https://www.netfilter.org/projects/libmnl/index.html
BuildRequires: autoconf >= 2.50
BuildRequires: automake >= 1.6
%{?with_apidocs:BuildRequires: doxygen}
@@ -99,6 +101,7 @@ Dokumentacja API biblioteki libmnl.
%prep
%setup -q
+%patch -P0 -p1
%build
%{__libtoolize}
@@ -120,8 +123,6 @@ rm -rf $RPM_BUILD_ROOT
DESTDIR=$RPM_BUILD_ROOT
%if %{with apidocs}
-# junk
-%{__rm} $RPM_BUILD_ROOT%{_mandir}/man3/_*.3
# too common names
%{__rm} $RPM_BUILD_ROOT%{_mandir}/man3/{attr,batch,callback,socket}.3
%endif
diff --git a/libmnl-nlmsg-ok-len.patch b/libmnl-nlmsg-ok-len.patch
new file mode 100644
index 0000000..47bbcb9
--- /dev/null
+++ b/libmnl-nlmsg-ok-len.patch
@@ -0,0 +1,62 @@
+From 754c9de5ea1bea821495523cf01989299552e524 Mon Sep 17 00:00:00 2001
+From: Jeremy Sowden <jeremy at azazel.net>
+Date: Sat, 4 Nov 2023 23:01:54 +0000
+Subject: [PATCH] nlmsg: fix false positives when validating buffer sizes
+
+The `len` parameter of `mnl_nlmsg_ok`, which holds the buffer length and
+is compared to the size of the object expected to fit into the buffer,
+is signed because the function validates the length, and it can be
+negative in the case of malformed messages. Comparing it to unsigned
+operands used to lead to compiler warnings:
+
+ msg.c: In function 'mnl_nlmsg_ok':
+ msg.c:136: warning: comparison between signed and unsigned
+ msg.c:138: warning: comparison between signed and unsigned
+
+and so commit 73661922bc3b ("fix warning in compilation due to different
+signess") added casts of the unsigned operands to `int`. However, the
+comparison to `nlh->nlmsg_len`:
+
+ (int)nlh->nlmsg_len <= len
+
+is problematic, since `nlh->nlmsg_len` is of type `__u32` and so may
+hold values greater than `INT_MAX`. In the case where `len` is positive
+and `nlh->nlmsg_len` is greater than `INT_MAX`, the cast will yield a
+negative value and `mnl_nlmsg_ok` will incorrectly return true.
+
+Instead, assign `len` to an unsigned local variable, check for a
+negative value first, then use the unsigned local for the other
+comparisons, and remove the casts.
+
+Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1691
+Fixes: 73661922bc3b ("fix warning in compilation due to different signess")
+Signed-off-by: Jeremy Sowden <jeremy at azazel.net>
+Signed-off-by: Pablo Neira Ayuso <pablo at netfilter.org>
+---
+ src/nlmsg.c | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/src/nlmsg.c b/src/nlmsg.c
+index c634501..30a7e63 100644
+--- a/src/nlmsg.c
++++ b/src/nlmsg.c
+@@ -152,9 +152,14 @@ EXPORT_SYMBOL void *mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh,
+ */
+ EXPORT_SYMBOL bool mnl_nlmsg_ok(const struct nlmsghdr *nlh, int len)
+ {
+- return len >= (int)sizeof(struct nlmsghdr) &&
++ size_t ulen = len;
++
++ if (len < 0)
++ return false;
++
++ return ulen >= sizeof(struct nlmsghdr) &&
+ nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
+- (int)nlh->nlmsg_len <= len;
++ nlh->nlmsg_len <= ulen;
+ }
+
+ /**
+--
+2.56.0
+
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/libmnl.git/commitdiff/363f5c2c1b823c80087a5f53dc7da528ced888a3
More information about the pld-cvs-commit
mailing list