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: <20240712180706.466124-1-kuba@kernel.org>
Date: Fri, 12 Jul 2024 11:07:06 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: mkubecek@...e.cz
Cc: netdev@...r.kernel.org,
	andrew@...n.ch,
	Jakub Kicinski <kuba@...nel.org>,
	idosch@...dia.com,
	danieller@...dia.com
Subject: [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump

The code does not differentiate between user asking for page 0 and
page not being set on the CLI at all. This is problematic because
drivers don't support old type of dumping for newer module types.
For example trying to hex dump EEPROM of a QSFP-DD on mlx5 gives
us in kernel logs:

  mlx5_query_module_eeprom[...]: Module ID not recognized: 0x18

We can dump all the non-zero pages, and without "hex on" ethtool
also uses the page-aware API to get the information it will print.
But hex dumping page 0 is not possible.

Instead of using zero / non-zero to figure out whether param was
set - add a bitmap of which params got set on command line.
The nl_param()'s dest option is not used by any other command,
so we're free to change the format.

Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
CC: idosch@...dia.com
CC: danieller@...dia.com
---
 netlink/module-eeprom.c | 30 +++++++++++++++++++++---------
 netlink/parser.c        | 11 +++++++++--
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c
index fe02c5ab2b65..2b30d042c00a 100644
--- a/netlink/module-eeprom.c
+++ b/netlink/module-eeprom.c
@@ -22,6 +22,7 @@
 #define ETH_I2C_MAX_ADDRESS	0x7F
 
 struct cmd_params {
+	unsigned long present;
 	u8 dump_hex;
 	u8 dump_raw;
 	u32 offset;
@@ -31,6 +32,14 @@ struct cmd_params {
 	u32 i2c_address;
 };
 
+enum {
+	PARAM_OFFSET = 2,
+	PARAM_LENGTH,
+	PARAM_PAGE,
+	PARAM_BANK,
+	PARAM_I2C,
+};
+
 static const struct param_parser getmodule_params[] = {
 	{
 		.arg		= "hex",
@@ -44,31 +53,31 @@ static const struct param_parser getmodule_params[] = {
 		.dest_offset	= offsetof(struct cmd_params, dump_raw),
 		.min_argc	= 1,
 	},
-	{
+	[PARAM_OFFSET] = {
 		.arg		= "offset",
 		.handler	= nl_parse_direct_u32,
 		.dest_offset	= offsetof(struct cmd_params, offset),
 		.min_argc	= 1,
 	},
-	{
+	[PARAM_LENGTH] = {
 		.arg		= "length",
 		.handler	= nl_parse_direct_u32,
 		.dest_offset	= offsetof(struct cmd_params, length),
 		.min_argc	= 1,
 	},
-	{
+	[PARAM_PAGE] = {
 		.arg		= "page",
 		.handler	= nl_parse_direct_u32,
 		.dest_offset	= offsetof(struct cmd_params, page),
 		.min_argc	= 1,
 	},
-	{
+	[PARAM_BANK] = {
 		.arg		= "bank",
 		.handler	= nl_parse_direct_u32,
 		.dest_offset	= offsetof(struct cmd_params, bank),
 		.min_argc	= 1,
 	},
-	{
+	[PARAM_I2C] = {
 		.arg		= "i2c",
 		.handler	= nl_parse_direct_u32,
 		.dest_offset	= offsetof(struct cmd_params, i2c_address),
@@ -267,15 +276,18 @@ int nl_getmodule(struct cmd_context *ctx)
 	 * ioctl. Netlink can only request specific pages.
 	 */
 	if ((getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) &&
-	    !getmodule_cmd_params.page && !getmodule_cmd_params.bank &&
-	    !getmodule_cmd_params.i2c_address) {
+	    !(getmodule_cmd_params.present & (1 << PARAM_PAGE |
+					      1 << PARAM_BANK |
+					      1 << PARAM_I2C))) {
 		nlctx->ioctl_fallback = true;
 		return -EOPNOTSUPP;
 	}
 
 #ifdef ETHTOOL_ENABLE_PRETTY_DUMP
-	if (getmodule_cmd_params.page || getmodule_cmd_params.bank ||
-	    getmodule_cmd_params.offset || getmodule_cmd_params.length)
+	if (getmodule_cmd_params.present & (1 << PARAM_PAGE |
+					    1 << PARAM_BANK |
+					    1 << PARAM_OFFSET |
+					    1 << PARAM_LENGTH))
 #endif
 		getmodule_cmd_params.dump_hex = true;
 
diff --git a/netlink/parser.c b/netlink/parser.c
index 6f863610a490..cd32752a9ddb 100644
--- a/netlink/parser.c
+++ b/netlink/parser.c
@@ -996,7 +996,7 @@ static void tmp_buff_destroy(struct tmp_buff *head)
  *               and their handlers; the array must be terminated by null
  *               element {}
  * @dest:        optional destination to copy parsed data to (at
- *               param_parser::offset)
+ *               param_parser::offset); buffer should start with presence bitmap
  * @group_style: defines if identifiers in .group represent separate messages,
  *               nested attributes or are not allowed
  * @msgbuffs:    (only used for @group_style = PARSER_GROUP_MSG) array to store
@@ -1096,7 +1096,14 @@ int nl_parser(struct nl_context *nlctx, const struct param_parser *params,
 			buff = tmp_buff_find(buffs, parser->group);
 		msgbuff = buff ? buff->msgbuff : &nlsk->msgbuff;
 
-		param_dest = dest ? ((char *)dest + parser->dest_offset) : NULL;
+		if (dest) {
+			unsigned long index = parser - params;
+
+			param_dest = ((char *)dest + parser->dest_offset);
+			set_bit(index, (unsigned long *)dest);
+		} else {
+			param_dest = NULL;
+		}
 		ret = parser->handler(nlctx, parser->type, parser->handler_data,
 				      msgbuff, param_dest);
 		if (ret < 0)
-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ