Tomas Bzatek 10280e
From 26fcef727d68af97b1187d2ac3cad19acc3d97c8 Mon Sep 17 00:00:00 2001
Tomas Bzatek 10280e
From: Tomas Bzatek <tbzatek@redhat.com>
Tomas Bzatek 10280e
Date: Tue, 16 May 2023 18:33:59 +0200
Tomas Bzatek 10280e
Subject: [PATCH 1/2] iscsi: Set node parameters before the Login/Logout action
Tomas Bzatek 10280e
Tomas Bzatek 10280e
This allows to properly pass required arguments like the CHAP
Tomas Bzatek 10280e
auth algorithms, etc.
Tomas Bzatek 10280e
---
Tomas Bzatek 10280e
 modules/iscsi/udisksiscsiutil.c | 54 ++++++++++++++++++---------------
Tomas Bzatek 10280e
 1 file changed, 29 insertions(+), 25 deletions(-)
Tomas Bzatek 10280e
Tomas Bzatek 10280e
diff --git a/modules/iscsi/udisksiscsiutil.c b/modules/iscsi/udisksiscsiutil.c
Tomas Bzatek 10280e
index 78890106f0..b279442876 100644
Tomas Bzatek 10280e
--- a/modules/iscsi/udisksiscsiutil.c
Tomas Bzatek 10280e
+++ b/modules/iscsi/udisksiscsiutil.c
Tomas Bzatek 10280e
@@ -186,9 +186,10 @@ iscsi_perform_login_action (UDisksLinuxModuleISCSI     *module,
Tomas Bzatek 10280e
 }
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
 static gint
Tomas Bzatek 10280e
-iscsi_node_set_parameters (struct libiscsi_context *ctx,
Tomas Bzatek 10280e
-                           struct libiscsi_node    *node,
Tomas Bzatek 10280e
-                           GVariant                *params)
Tomas Bzatek 10280e
+iscsi_node_set_parameters (struct libiscsi_context  *ctx,
Tomas Bzatek 10280e
+                           struct libiscsi_node     *node,
Tomas Bzatek 10280e
+                           GVariant                 *params,
Tomas Bzatek 10280e
+                           gchar                   **errorstr)
Tomas Bzatek 10280e
 {
Tomas Bzatek 10280e
   GVariantIter  iter;
Tomas Bzatek 10280e
   GVariant     *value;
Tomas Bzatek 10280e
@@ -207,9 +208,11 @@ iscsi_node_set_parameters (struct libiscsi_context *ctx,
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
       /* Update the node parameter value. */
Tomas Bzatek 10280e
       err = libiscsi_node_set_parameter (ctx, node, key, param_value);
Tomas Bzatek 10280e
+      if (errorstr && err != 0)
Tomas Bzatek 10280e
+        *errorstr = g_strdup (libiscsi_get_error_string (ctx));
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
       g_variant_unref (value);
Tomas Bzatek 10280e
-      g_free ((gpointer) key);
Tomas Bzatek 10280e
+      g_free (key);
Tomas Bzatek 10280e
     }
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
   return 0;
Tomas Bzatek 10280e
@@ -279,7 +282,7 @@ iscsi_login (UDisksLinuxModuleISCSI *module,
Tomas Bzatek 10280e
   const gchar *password = NULL;
Tomas Bzatek 10280e
   const gchar *reverse_username = NULL;
Tomas Bzatek 10280e
   const gchar *reverse_password = NULL;
Tomas Bzatek 10280e
-  gint err;
Tomas Bzatek 10280e
+  gint err = 0;
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
   g_return_val_if_fail (UDISKS_IS_LINUX_MODULE_ISCSI (module), 1);
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
@@ -304,17 +307,18 @@ iscsi_login (UDisksLinuxModuleISCSI *module,
Tomas Bzatek 10280e
   /* Get iscsi context. */
Tomas Bzatek 10280e
   ctx = udisks_linux_module_iscsi_get_libiscsi_context (module);
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
-  /* Login */
Tomas Bzatek 10280e
-  err = iscsi_perform_login_action (module,
Tomas Bzatek 10280e
-                                    ACTION_LOGIN,
Tomas Bzatek 10280e
-                                    &node,
Tomas Bzatek 10280e
-                                    &auth_info,
Tomas Bzatek 10280e
-                                    errorstr);
Tomas Bzatek 10280e
+  /* Update node parameters. */
Tomas Bzatek 10280e
+  if (params)
Tomas Bzatek 10280e
+    err = iscsi_node_set_parameters (ctx, &node, params_without_chap, errorstr);
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
-  if (err == 0 && params)
Tomas Bzatek 10280e
+  /* Login */
Tomas Bzatek 10280e
+  if (err == 0)
Tomas Bzatek 10280e
     {
Tomas Bzatek 10280e
-      /* Update node parameters. */
Tomas Bzatek 10280e
-      err = iscsi_node_set_parameters (ctx, &node, params_without_chap);
Tomas Bzatek 10280e
+      err = iscsi_perform_login_action (module,
Tomas Bzatek 10280e
+                                        ACTION_LOGIN,
Tomas Bzatek 10280e
+                                        &node,
Tomas Bzatek 10280e
+                                        &auth_info,
Tomas Bzatek 10280e
+                                        errorstr);
Tomas Bzatek 10280e
     }
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
   g_variant_unref (params_without_chap);
Tomas Bzatek 10280e
@@ -334,7 +338,7 @@ iscsi_logout (UDisksLinuxModuleISCSI *module,
Tomas Bzatek 10280e
 {
Tomas Bzatek 10280e
   struct libiscsi_context *ctx;
Tomas Bzatek 10280e
   struct libiscsi_node node = {0,};
Tomas Bzatek 10280e
-  gint err;
Tomas Bzatek 10280e
+  gint err = 0;
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
   g_return_val_if_fail (UDISKS_IS_LINUX_MODULE_ISCSI (module), 1);
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
@@ -344,18 +348,18 @@ iscsi_logout (UDisksLinuxModuleISCSI *module,
Tomas Bzatek 10280e
   /* Get iscsi context. */
Tomas Bzatek 10280e
   ctx = udisks_linux_module_iscsi_get_libiscsi_context (module);
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
-  /* Logout */
Tomas Bzatek 10280e
-  err = iscsi_perform_login_action (module,
Tomas Bzatek 10280e
-                                    ACTION_LOGOUT,
Tomas Bzatek 10280e
-                                    &node,
Tomas Bzatek 10280e
-                                    NULL,
Tomas Bzatek 10280e
-                                    errorstr);
Tomas Bzatek 10280e
+  /* Update node parameters. */
Tomas Bzatek 10280e
+  if (params)
Tomas Bzatek 10280e
+    err = iscsi_node_set_parameters (ctx, &node, params, errorstr);
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
-  if (err == 0 && params)
Tomas Bzatek 10280e
+  /* Logout */
Tomas Bzatek 10280e
+  if (err == 0)
Tomas Bzatek 10280e
     {
Tomas Bzatek 10280e
-      /* Update node parameters. */
Tomas Bzatek 10280e
-      err = iscsi_node_set_parameters (ctx, &node, params);
Tomas Bzatek 10280e
-
Tomas Bzatek 10280e
+      err = iscsi_perform_login_action (module,
Tomas Bzatek 10280e
+                                        ACTION_LOGOUT,
Tomas Bzatek 10280e
+                                        &node,
Tomas Bzatek 10280e
+                                        NULL,
Tomas Bzatek 10280e
+                                        errorstr);
Tomas Bzatek 10280e
     }
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
   return err;
Tomas Bzatek 10280e
Tomas Bzatek 10280e
From 749812784abcc4c0492bda0703bff5d3dae052f9 Mon Sep 17 00:00:00 2001
Tomas Bzatek 10280e
From: Tomas Bzatek <tbzatek@redhat.com>
Tomas Bzatek 10280e
Date: Tue, 16 May 2023 18:35:42 +0200
Tomas Bzatek 10280e
Subject: [PATCH 2/2] tests: Disallow MD5 for iscsi CHAP login
Tomas Bzatek 10280e
Tomas Bzatek 10280e
MD5 is unavailable in FIPS mode:
Tomas Bzatek 10280e
Tomas Bzatek 10280e
  iscsid[82167]: iscsid: Ignoring CHAP algorthm request for MD5 due to crypto lib configuration
Tomas Bzatek 10280e
  iscsid[82167]: iscsid: Couldn't set CHAP algorithm list
Tomas Bzatek 10280e
  kernel: rx_data returned 0, expecting 48.
Tomas Bzatek 10280e
  kernel: iSCSI Login negotiation failed.
Tomas Bzatek 10280e
---
Tomas Bzatek 10280e
 src/tests/dbus-tests/test_30_iscsi.py | 3 +++
Tomas Bzatek 10280e
 1 file changed, 3 insertions(+)
Tomas Bzatek 10280e
Tomas Bzatek 10280e
diff --git a/src/tests/dbus-tests/test_30_iscsi.py b/src/tests/dbus-tests/test_30_iscsi.py
Tomas Bzatek 10280e
index 09e975f30c..02ba6c92b0 100644
Tomas Bzatek 10280e
--- a/src/tests/dbus-tests/test_30_iscsi.py
Tomas Bzatek 10280e
+++ b/src/tests/dbus-tests/test_30_iscsi.py
Tomas Bzatek 10280e
@@ -161,6 +161,7 @@ def test_login_chap_auth(self):
Tomas Bzatek 10280e
         self.assertEqual(port, self.port)
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
         options = dbus.Dictionary(signature='sv')
Tomas Bzatek 10280e
+        options['node.session.auth.chap_algs'] = 'SHA3-256,SHA256,SHA1'  # disallow MD5
Tomas Bzatek 10280e
         options['username'] = self.initiator
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
         msg = 'Login failed: initiator reported error \(24 - iSCSI login failed due to authorization failure\)'
Tomas Bzatek 10280e
@@ -227,6 +228,7 @@ def test_login_mutual_auth(self):
Tomas Bzatek 10280e
         self.assertEqual(port, self.port)
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
         options = dbus.Dictionary(signature='sv')
Tomas Bzatek 10280e
+        options['node.session.auth.chap_algs'] = 'SHA3-256,SHA256,SHA1'  # disallow MD5
Tomas Bzatek 10280e
         options['username'] = self.initiator
Tomas Bzatek 10280e
         options['password'] = self.password
Tomas Bzatek 10280e
         options['reverse-username'] = self.mutual_iqn
Tomas Bzatek 10280e
@@ -335,6 +337,7 @@ def test_login_noauth_badauth(self):
Tomas Bzatek 10280e
 
Tomas Bzatek 10280e
         # first attempt - wrong password
Tomas Bzatek 10280e
         options = dbus.Dictionary(signature='sv')
Tomas Bzatek 10280e
+        options['node.session.auth.chap_algs'] = 'SHA3-256,SHA256,SHA1'  # disallow MD5
Tomas Bzatek 10280e
         options['username'] = self.initiator
Tomas Bzatek 10280e
         msg = r'Login failed: initiator reported error \((19 - encountered non-retryable iSCSI login failure|24 - iSCSI login failed due to authorization failure)\)'
Tomas Bzatek 10280e
         with six.assertRaisesRegex(self, dbus.exceptions.DBusException, msg):