Package: nvme-stas
Severity: normal
Tags: patch
User: [email protected]
Usertags: origin-ubuntu noble ubuntu-patch

Dear Maintainer,

After applying fixes from bug 1054533 [1], autopkgtest
for nvme-stas hangs on s390x and ends up failing on timeout.

Excerpt from an autopkgtest run on Ubuntu [2].

> 96s test__data_matches_ip (test-iputil.Test.test__data_matches_ip) ... ok
> 596s test_get_interface (test-iputil.Test.test_get_interface)
> 10600s Check that get_interface() returns the right info ... autopkgtest 
> [02:09:30]: ERROR: timed out on command "su -s /bin/bash ubuntu -c set -e; 
> [...]

This is caused by an endianness issue in staslib.iputil when
packing/unpacking netlink data structures. It can be fixed by using host
byte ordering instead of "hard-coding" little endian.

I forwarded the fix upstream [3].

In Ubuntu, the attached patch was applied to achieve the following:

  * Fix endianness issues in staslib.iputil causing hangs on s390x.
    (LP: #2045000)

Thanks for considering the patch.

[1] https://bugs.debian.org/1054533
[2] 
https://autopkgtest.ubuntu.com/results/autopkgtest-noble/noble/s390x/n/nvme-stas/20231128_021002_94626@/log.gz
[3] https://github.com/linux-nvme/nvme-stas/pull/406

-- System Information:
Debian Release: trixie/sid
  APT prefers mantic-updates
  APT policy: (500, 'mantic-updates'), (500, 'mantic-security'), (500, 'mantic')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.1.0-16-generic (SMP w/8 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff -Nru nvme-stas-2.3/debian/control nvme-stas-2.3/debian/control
--- nvme-stas-2.3/debian/control        2023-11-27 17:45:04.000000000 +0100
+++ nvme-stas-2.3/debian/control        2023-11-28 11:01:46.000000000 +0100
@@ -1,8 +1,7 @@
 Source: nvme-stas
 Section: net
 Priority: optional
-Maintainer: Ubuntu Developers <[email protected]>
-XSBC-Original-Maintainer: Daniel Baumann <[email protected]>
+Maintainer: Daniel Baumann <[email protected]>
 Uploaders:
  Benjamin Drung <[email protected]>,
 Build-Depends:
diff -Nru nvme-stas-2.3/debian/patches/fix-iputil-endianness-issue.patch 
nvme-stas-2.3/debian/patches/fix-iputil-endianness-issue.patch
--- nvme-stas-2.3/debian/patches/fix-iputil-endianness-issue.patch      
1970-01-01 01:00:00.000000000 +0100
+++ nvme-stas-2.3/debian/patches/fix-iputil-endianness-issue.patch      
2023-11-28 11:01:46.000000000 +0100
@@ -0,0 +1,103 @@
+Description: iputil: pack and unpack using native byte ordering
+ On big-endian architectures (such as s390x), tests defined in
+ test-iputil.py would hang:
+ .
+  > 596s test_get_interface (test-iputil.Test.test_get_interface)
+  >   10600s Check that get_interface() returns the right info ...
+ .
+ Indeed, running the following hangs as well:
+ .
+  > from staslib import iputil
+  >
+  > iputil.net_if_addrs()
+ .
+ This is an endianness issue that can be fixed by using native
+ byte-ordering when packing and unpacking netlink data structures such as
+ ifaddrmsg.
+Author: Olivier Gayot <[email protected]>
+Bug-Ubuntu: https://launchpad.net/bugs/2045000
+Forwarded: https://github.com/linux-nvme/nvme-stas/pull/406
+Last-Update: 2023-11-28
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/staslib/iputil.py
++++ b/staslib/iputil.py
+@@ -42,7 +42,7 @@
+         __u32 nlmsg_pid;   /* Sending process port ID */
+     };
+     '''
+-    return struct.pack('<LHHLL', NLMSG_LENGTH(msg_len), nlmsg_type, 
nlmsg_flags, nlmsg_seq, nlmsg_pid)
++    return struct.pack('=LHHLL', NLMSG_LENGTH(msg_len), nlmsg_type, 
nlmsg_flags, nlmsg_seq, nlmsg_pid)
+ 
+ 
+ def _ifaddrmsg(family=0, prefixlen=0, flags=0, scope=0, index=0):
+@@ -55,7 +55,7 @@
+         __u32  ifa_index;      /* Link index           */
+     };
+     '''
+-    return struct.pack('<BBBBL', family, prefixlen, flags, scope, index)
++    return struct.pack('=BBBBL', family, prefixlen, flags, scope, index)
+ 
+ 
+ def _ifinfomsg(family=0, dev_type=0, index=0, flags=0, change=0):
+@@ -69,7 +69,7 @@
+         unsigned int    ifi_change; /* change mask: IFF_* */
+     };
+     '''
+-    return struct.pack('<BBHiII', family, 0, dev_type, index, flags, change)
++    return struct.pack('=BBHiII', family, 0, dev_type, index, flags, change)
+ 
+ 
+ def _nlmsg(nlmsg_type, nlmsg_flags, msg: bytes):
+@@ -102,7 +102,7 @@
+                 nlmsg += sock.recv(8192)
+ 
+             nlmsghdr = nlmsg[nlmsg_idx : nlmsg_idx + NLMSG_HDRLEN]
+-            nlmsg_len, nlmsg_type, _, _, _ = struct.unpack('<LHHLL', nlmsghdr)
++            nlmsg_len, nlmsg_type, _, _, _ = struct.unpack('=LHHLL', nlmsghdr)
+ 
+             if nlmsg_type == NLMSG_DONE:
+                 break
+@@ -110,13 +110,13 @@
+             if nlmsg_type == RTM_BASE:
+                 msg_indx = nlmsg_idx + NLMSG_HDRLEN
+                 msg = nlmsg[msg_indx : msg_indx + IFINFOMSG_SZ]  # ifinfomsg
+-                _, _, ifi_type, ifi_index, _, _ = struct.unpack('<BBHiII', 
msg)
++                _, _, ifi_type, ifi_index, _, _ = struct.unpack('=BBHiII', 
msg)
+ 
+                 if ifi_type in (ARPHRD_LOOPBACK, ARPHRD_ETHER):
+                     rtattr_indx = msg_indx + IFINFOMSG_SZ
+                     while rtattr_indx < (nlmsg_idx + nlmsg_len):
+                         rtattr = nlmsg[rtattr_indx : rtattr_indx + RTATTR_SZ]
+-                        rta_len, rta_type = struct.unpack('<HH', rtattr)
++                        rta_len, rta_type = struct.unpack('=HH', rtattr)
+                         if rta_type == IFLA_ADDRESS:
+                             data = nlmsg[rtattr_indx + RTATTR_SZ : 
rtattr_indx + rta_len]
+                             if _data_matches_mac(data, mac):
+@@ -206,7 +206,7 @@
+                 nlmsg += sock.recv(8192)
+ 
+             nlmsghdr = nlmsg[nlmsg_idx : nlmsg_idx + NLMSG_HDRLEN]
+-            nlmsg_len, nlmsg_type, _, _, _ = struct.unpack('<LHHLL', nlmsghdr)
++            nlmsg_len, nlmsg_type, _, _, _ = struct.unpack('=LHHLL', nlmsghdr)
+ 
+             if nlmsg_type == NLMSG_DONE:
+                 break
+@@ -214,7 +214,7 @@
+             if nlmsg_type == RTM_NEWADDR:
+                 msg_indx = nlmsg_idx + NLMSG_HDRLEN
+                 msg = nlmsg[msg_indx : msg_indx + IFADDRMSG_SZ]  # ifaddrmsg
+-                ifa_family, _, _, _, ifa_index = struct.unpack('<BBBBL', msg)
++                ifa_family, _, _, _, ifa_index = struct.unpack('=BBBBL', msg)
+ 
+                 if ifa_family in (socket.AF_INET, socket.AF_INET6):
+                     interfaces.setdefault(ifa_index, {4: [], 6: []})
+@@ -222,7 +222,7 @@
+                     rtattr_indx = msg_indx + IFADDRMSG_SZ
+                     while rtattr_indx < (nlmsg_idx + nlmsg_len):
+                         rtattr = nlmsg[rtattr_indx : rtattr_indx + RTATTR_SZ]
+-                        rta_len, rta_type = struct.unpack('<HH', rtattr)
++                        rta_len, rta_type = struct.unpack('=HH', rtattr)
+ 
+                         if rta_type == IFLA_IFNAME:
+                             data = nlmsg[rtattr_indx + RTATTR_SZ : 
rtattr_indx + rta_len]
diff -Nru nvme-stas-2.3/debian/patches/series 
nvme-stas-2.3/debian/patches/series
--- nvme-stas-2.3/debian/patches/series 2023-11-27 17:45:04.000000000 +0100
+++ nvme-stas-2.3/debian/patches/series 2023-11-28 11:01:46.000000000 +0100
@@ -1,2 +1,3 @@
 fix-test-libnvme-version.patch
 fix-test-udev-failing-multiple-IPv6.patch
+fix-iputil-endianness-issue.patch

Reply via email to