From f9f84fc1d52c651618b85ed24cf2f37d0827d7a2 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Mon, 3 Nov 2025 14:52:09 +0100 Subject: [PATCH] iSCSI: don't crash when LUN ID >= 256 Resolves: RHEL-122305 --- 0003-iSCSI-dont-crash-when-LUN-ID-256.patch | 91 +++++++++++++++++++++ python-blivet.spec | 7 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 0003-iSCSI-dont-crash-when-LUN-ID-256.patch diff --git a/0003-iSCSI-dont-crash-when-LUN-ID-256.patch b/0003-iSCSI-dont-crash-when-LUN-ID-256.patch new file mode 100644 index 0000000..c6fe3f0 --- /dev/null +++ b/0003-iSCSI-dont-crash-when-LUN-ID-256.patch @@ -0,0 +1,91 @@ +From f496c4c42d4ba4331909b0a9c7749cf9f581840d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Renaud=20M=C3=A9trich?= +Date: Fri, 17 Oct 2025 14:21:06 +0200 +Subject: [PATCH 1/2] iSCSI: don't crash when LUN ID >= 256 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +When LUN ID >= 256, systemd udev function format_lun_number() generates +an address of the form "lun-0x...". +Due to this, using int(lun) fails with a backtrace. + +Signed-off-by: Renaud Métrich + +Resolves: RHEL-122305 +--- + blivet/devices/disk.py | 12 +++++++++++- + 1 file changed, 11 insertions(+), 1 deletion(-) + +diff --git a/blivet/devices/disk.py b/blivet/devices/disk.py +index d9907fda3..04800e54d 100644 +--- a/blivet/devices/disk.py ++++ b/blivet/devices/disk.py +@@ -28,6 +28,7 @@ + from gi.repository import GLib + + import os ++import re + from collections import namedtuple + + from .. import errors +@@ -354,8 +355,17 @@ def __init__(self, device, **kwargs): + self.offload = kwargs.pop("offload") + name = kwargs.pop("name") + self.target = kwargs.pop("target") ++ lun = kwargs.pop("lun") + try: +- self.lun = int(kwargs.pop("lun")) ++ self.lun = int(lun) ++ except ValueError: ++ # See systemd udev function format_lun_number() ++ m = re.fullmatch('0x([0-9a-fA-F]{4})([0-9a-fA-F]{4})00000000', lun) ++ if m is None: ++ log.warning("Failed to extract hex from lun '%s'", lun) ++ self.lun = None ++ else: ++ self.lun = int(m.group(1), 16) + (1 << 16) * int(m.group(2), 16) + except TypeError as e: + log.warning("Failed to set lun attribute of iscsi disk: %s", e) + self.lun = None + +From 0a5a1bbb6e180cba9be6e70869129e5123aebd85 Mon Sep 17 00:00:00 2001 +From: Vojtech Trefny +Date: Mon, 20 Oct 2025 11:19:39 +0200 +Subject: [PATCH 2/2] tests: Add a simple test case for parsing iSCSI lun + +Related: RHEL-122305 +--- + tests/unit_tests/devices_test/disk_test.py | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/tests/unit_tests/devices_test/disk_test.py b/tests/unit_tests/devices_test/disk_test.py +index e414aeb4c..f6a011200 100644 +--- a/tests/unit_tests/devices_test/disk_test.py ++++ b/tests/unit_tests/devices_test/disk_test.py +@@ -1,7 +1,7 @@ + import unittest + from unittest.mock import patch + +-from blivet.devices import DiskDevice ++from blivet.devices import DiskDevice, iScsiDiskDevice + from blivet.devicelibs import disk as disklib + from blivet.devicelibs import raid + from blivet.size import Size +@@ -47,3 +47,16 @@ def test_disk_raid_properties(self): + self.assertIsNone(test3.raid_level) + self.assertIsNone(test3.raid_stripe_size) + self.assertIsNone(test3.raid_disk_count) ++ ++ ++class iScsiDiskDeviceTestCase(unittest.TestCase): ++ def test_iscsi_lun(self): ++ kwargs = {"node": "", "ibft": "", "nic": "", "initiator": "", ++ "offload": False, "name": "", "target": "", ++ "address": "", "port": "", "iface": "", "id_path": ""} ++ ++ disk1 = iScsiDiskDevice("test1", lun="1", **kwargs) ++ self.assertEqual(disk1.lun, 1) ++ ++ disk2 = iScsiDiskDevice("test1", lun="0x0101000000000000", **kwargs) ++ self.assertEqual(disk2.lun, 257) diff --git a/python-blivet.spec b/python-blivet.spec index 47b4cae..32dc9db 100644 --- a/python-blivet.spec +++ b/python-blivet.spec @@ -5,7 +5,7 @@ Version: 3.13.0 #%%global prerelease .b2 # prerelease, if defined, should be something like .a1, .b1, .b2.dev1, or .c2 -Release: 2%{?prerelease}%{?dist} +Release: 3%{?prerelease}%{?dist} Epoch: 1 License: LGPL-2.1-or-later %global realname blivet @@ -18,6 +18,7 @@ Patch0: 0001-remove-btrfs-plugin.patch %endif Patch1: 0002-Temporarily-reintroduce-the-safe_dbus-module.patch +Patch2: 0003-iSCSI-dont-crash-when-LUN-ID-256.patch # Versions of required components (done so we make sure the buildrequires # match the requires versions of things). @@ -115,6 +116,10 @@ make DESTDIR=%{buildroot} install %{python3_sitelib}/* %changelog +* Mon Nov 03 2025 Vojtech Trefny - 3.13.0-3 +- iSCSI: don't crash when LUN ID >= 256 + Resolves: RHEL-122305 + * Wed Oct 29 2025 Vojtech Trefny - 3.13.0-2 - Temporarily reintroduce the safe_dbus module Related: RHEL-115005