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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210623075925.2610908-3-idosch@idosch.org>
Date:   Wed, 23 Jun 2021 10:59:23 +0300
From:   Ido Schimmel <idosch@...sch.org>
To:     netdev@...r.kernel.org
Cc:     davem@...emloft.net, kuba@...nel.org, jiri@...dia.com,
        andrew@...n.ch, vladyslavt@...dia.com, moshe@...dia.com,
        vadimp@...dia.com, mkubecek@...e.cz, mlxsw@...dia.com,
        Ido Schimmel <idosch@...dia.com>
Subject: [RFC PATCH net-next 2/4] ethtool: Split module EEPROM attributes validation to a function

From: Ido Schimmel <idosch@...dia.com>

The same validation will be needed for module EEPROM write access in the
subsequent patch, so split it into a function.

Modify the extack messages a bit to not be specific to read access.

No functional changes intended.

Signed-off-by: Ido Schimmel <idosch@...dia.com>
Reviewed-by: Jiri Pirko <jiri@...dia.com>
---
 net/ethtool/eeprom.c | 58 ++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 23 deletions(-)

diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c
index ed5f677f27cd..945b95e64f0d 100644
--- a/net/ethtool/eeprom.c
+++ b/net/ethtool/eeprom.c
@@ -144,10 +144,41 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
 	return ret;
 }
 
+static int eeprom_validate(struct nlattr **tb, struct netlink_ext_ack *extack)
+{
+	u32 offset = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_OFFSET]);
+	u32 length = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_LENGTH]);
+	u8 page = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_PAGE]);
+
+	/* The following set of conditions limit the API to only access 1/2
+	 * EEPROM page without crossing low page boundary located at offset
+	 * 128. For pages higher than 0, only high 128 bytes are accessible.
+	 */
+	if (page && offset < ETH_MODULE_EEPROM_PAGE_LEN) {
+		NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_PAGE],
+				    "access to lower half page is allowed for page 0 only");
+		return -EINVAL;
+	}
+
+	if (offset < ETH_MODULE_EEPROM_PAGE_LEN &&
+	    offset + length > ETH_MODULE_EEPROM_PAGE_LEN) {
+		NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
+				    "crossing half page boundary is illegal");
+		return -EINVAL;
+	} else if (offset + length > ETH_MODULE_EEPROM_PAGE_LEN * 2) {
+		NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
+				    "crossing page boundary is illegal");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb,
 				struct netlink_ext_ack *extack)
 {
 	struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_info);
+	int err;
 
 	if (!tb[ETHTOOL_A_MODULE_EEPROM_OFFSET] ||
 	    !tb[ETHTOOL_A_MODULE_EEPROM_LENGTH] ||
@@ -155,6 +186,10 @@ static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr *
 	    !tb[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS])
 		return -EINVAL;
 
+	err = eeprom_validate(tb, extack);
+	if (err)
+		return err;
+
 	request->i2c_address = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS]);
 	request->offset = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_OFFSET]);
 	request->length = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_LENGTH]);
@@ -162,29 +197,6 @@ static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr *
 	if (tb[ETHTOOL_A_MODULE_EEPROM_BANK])
 		request->bank = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_BANK]);
 
-	/* The following set of conditions limit the API to only dump 1/2
-	 * EEPROM page without crossing low page boundary located at offset 128.
-	 * This means user may only request dumps of length limited to 128 from
-	 * either low 128 bytes or high 128 bytes.
-	 * For pages higher than 0 only high 128 bytes are accessible.
-	 */
-	if (request->page && request->offset < ETH_MODULE_EEPROM_PAGE_LEN) {
-		NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_PAGE],
-				    "reading from lower half page is allowed for page 0 only");
-		return -EINVAL;
-	}
-
-	if (request->offset < ETH_MODULE_EEPROM_PAGE_LEN &&
-	    request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) {
-		NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
-				    "reading cross half page boundary is illegal");
-		return -EINVAL;
-	} else if (request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN * 2) {
-		NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
-				    "reading cross page boundary is illegal");
-		return -EINVAL;
-	}
-
 	return 0;
 }
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ