summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-02-18 13:23:31 +0100
committerThomas Haller <thaller@redhat.com>2020-02-26 17:51:13 +0100
commitef567805bb35ce872d01bff694364e91be14baad (patch)
treed5a2f76312f53ff54a95c5ba1241607dbdcf8652
parentb15a9b3dc4459f228e699a5cf6a3bd4a5ff71ee3 (diff)
downloadNetworkManager-ef567805bb35ce872d01bff694364e91be14baad.tar.gz
shared: reject '%' from nm_utils_ifname_valid() for kernel names
Generally, it's dangerous to reject values that were accepted previously. This will lead to NetworkManager being unable to load a profile from disk, which was loadable previously. On the other hand, kernel would not have treated this setting as it was intended. So, I would argue that the such a setting was not working (as intended) anyway. We can only hope that users don't configure arbitrary interface names. It generally isn't a good idea to do, so "breaking" such things is less of a concern.
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index c9bfbb07fe..ace652f4c3 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -4126,8 +4126,34 @@ nm_utils_ifname_valid_kernel (const char *name, GError **error)
return FALSE;
}
+/*****************************************************************************/
+
+static gboolean
+_nm_utils_ifname_valid_kernel (const char *name, GError **error)
+{
+ if (!nm_utils_ifname_valid_kernel (name, error))
+ return FALSE;
+
+ if (strchr (name, '%')) {
+ /* Kernel's dev_valid_name() accepts (almost) any binary up to 15 chars.
+ * However, '%' is treated special as a format specifier. Try
+ *
+ * ip link add 'dummy%dx' type dummy
+ *
+ * Don't allow that for "connection.interface-name", which either
+ * matches an existing netdev name (thus, it cannot have a '%') or
+ * is used to configure a name (in which case we don't want kernel
+ * to replace the format specifier). */
+ g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN,
+ _("'%%' is not allowed in interface names"));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static gboolean
-_nm_utils_ifname_valid_ovs (const char* name, GError **error)
+_nm_utils_ifname_valid_ovs (const char *name, GError **error)
{
const char *ch;
@@ -4169,7 +4195,7 @@ nm_utils_ifname_valid (const char* name,
switch (type) {
case NMU_IFACE_KERNEL:
- return nm_utils_ifname_valid_kernel (name, error);
+ return _nm_utils_ifname_valid_kernel (name, error);
case NMU_IFACE_OVS:
return _nm_utils_ifname_valid_ovs (name, error);
}