lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191018160726.18901-1-jiri@resnulli.us>
Date:   Fri, 18 Oct 2019 18:07:26 +0200
From:   Jiri Pirko <jiri@...nulli.us>
To:     netdev@...r.kernel.org
Cc:     davem@...emloft.net, jakub.kicinski@...ronome.com, andrew@...n.ch,
        mlxsw@...lanox.com
Subject: [patch net-next] devlink: add format requirement for devlink param names

From: Jiri Pirko <jiri@...lanox.com>

Currently, the name format is not required by the code, however it is
required during patch review. All params added until now are in-lined
with the following format:
1) lowercase characters, digits and underscored are allowed
2) underscore is neither at the beginning nor at the end and
   there is no more than one in a row.

Add checker to the code to require this format from drivers and warn if
they don't follow.

Signed-off-by: Jiri Pirko <jiri@...lanox.com>
---
 net/core/devlink.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index 97e9a2246929..5969cab5bc31 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -20,6 +20,7 @@
 #include <linux/workqueue.h>
 #include <linux/u64_stats_sync.h>
 #include <linux/timekeeping.h>
+#include <linux/ctype.h>
 #include <rdma/ib_verbs.h>
 #include <net/netlink.h>
 #include <net/genetlink.h>
@@ -7040,10 +7041,37 @@ void devlink_resource_occ_get_unregister(struct devlink *devlink,
 }
 EXPORT_SYMBOL_GPL(devlink_resource_occ_get_unregister);
 
+static bool devlink_param_valid_name(const char *name)
+{
+	int len = strlen(name);
+	int i;
+
+	/* Name can contain lowercase characters or digits.
+	 * Underscores are also allowed, but not at the beginning
+	 * or end of the name and not more than one in a row.
+	 */
+
+	for (i = 0; i < len; i++) {
+		if (islower(name[i]) || isdigit(name[i]))
+			continue;
+		if (name[i] != '_')
+			return false;
+		if (i == 0 || i + 1 == len)
+			return false;
+		if (name[i - 1] == '_')
+			return false;
+	}
+	return true;
+}
+
 static int devlink_param_verify(const struct devlink_param *param)
 {
 	if (!param || !param->name || !param->supported_cmodes)
 		return -EINVAL;
+
+	if (WARN_ON(!devlink_param_valid_name(param->name)))
+		return -EINVAL;
+
 	if (param->generic)
 		return devlink_param_generic_verify(param);
 	else
-- 
2.21.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ