From 86c8501e4021015452739ddffa7343381c49e781 Mon Sep 17 00:00:00 2001 From: sxt1001 Date: Mon, 29 May 2023 23:12:00 +0800 Subject: [PATCH] Fix res_id byte order (cherry picked from commit 9c03d0a5baf25a57825dc6b67adf302b3e1fcdd8) --- backport-libnftnl-Fix-res_id-byte-order.patch | 51 +++++++++++++++++++ libnftnl.spec | 6 ++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 backport-libnftnl-Fix-res_id-byte-order.patch diff --git a/backport-libnftnl-Fix-res_id-byte-order.patch b/backport-libnftnl-Fix-res_id-byte-order.patch new file mode 100644 index 0000000..ffa254a --- /dev/null +++ b/backport-libnftnl-Fix-res_id-byte-order.patch @@ -0,0 +1,51 @@ +From 7e867f5d66510cb70bfae7be2d4ec28351934f66 Mon Sep 17 00:00:00 2001 +From: Ian Pilcher +Date: Tue, 18 Oct 2022 11:45:28 -0500 +Subject: [PATCH] libnftnl: Fix res_id byte order + +The res_id member of struct nfgenmsg is supposed to be in network +byte order (big endian). Call htons() in __nftnl_nlmsg_build_hdr() +to ensure that this is true on little endian systems. + +There is a kernel workaround that was introduced in 4.3 to address +this issue: + + commit a9de9777d613500b089a7416f936bf3ae5f070d2 + Author: Pablo Neira Ayuso + Date: Fri Aug 28 21:01:43 2015 +0200 + + netfilter: nfnetlink: work around wrong endianess in res_id field + +And current oldest stable kernel branch in 4.9, merge this to fix +the incorrect endianness from userspace. + +Signed-off-by: Ian Pilcher +Signed-off-by: Pablo Neira Ayuso +--- + src/common.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/common.c b/src/common.c +index 2d83c12..08572c3 100644 +--- a/src/common.c ++++ b/src/common.c +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -37,7 +38,7 @@ static struct nlmsghdr *__nftnl_nlmsg_build_hdr(char *buf, uint16_t type, + nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg)); + nfh->nfgen_family = family; + nfh->version = NFNETLINK_V0; +- nfh->res_id = res_id; ++ nfh->res_id = htons(res_id); + + return nlh; + } +-- +2.33.0 + diff --git a/libnftnl.spec b/libnftnl.spec index 21400b0..76fe85e 100644 --- a/libnftnl.spec +++ b/libnftnl.spec @@ -1,6 +1,6 @@ Name: libnftnl Version: 1.2.0 -Release: 3 +Release: 4 Summary: Library for low-level interaction with nftables Netlink's API over libmnl License: GPLv2+ URL: http://netfilter.org/projects/libnftnl/ @@ -8,6 +8,7 @@ Source0: http://netfilter.org/projects/libnftnl/files/%{name}-%{version}.tar.bz2 Patch6000: backport-rule-set_elem-fix-printing-of-user-data.patch Patch6001: backport-rule-set_elem-remove-trailing-n-in-userdata-snprintf.patch +Patch6002: backport-libnftnl-Fix-res_id-byte-order.patch BuildRequires: libmnl-devel jansson-devel gcc @@ -54,6 +55,9 @@ make %{?_smp_mflags} check %{_includedir}/libnftnl %changelog +* Mon May 29 2023 shixuantong - 1.2.0-4 +- Fix res_id byte order + * Sun May 28 2023 shixuantong - 1.2.0-3 - sync community patch