Netdev List
 help / color / mirror / Atom feed
From: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
To: netdev@vger.kernel.org
Cc: Prabhakar Pujeri <prabhakar.pujeri@dell.com>,
	Michal Kubecek <mkubecek@suse.cz>
Subject: [PATCH ethtool 2/2] ethtool: validate module EEPROM offset and length
Date: Mon, 31 Aug 2026 10:41:24 +0000	[thread overview]
Message-ID: <20260831104125.2203-3-prabhakar.pujeri@dell.com> (raw)
In-Reply-To: <20260831104125.2203-1-prabhakar.pujeri@dell.com>

do_getmodule() clamps a requested range by adding its offset and length.
An offset beyond the EEPROM makes the later subtraction underflow, while
a very large length can make the addition wrap.  Either case can produce
an unexpectedly large allocation request.

Reject offsets at or beyond the reported EEPROM size.  Once the offset is
known to be valid, compare the requested length with the remaining size
instead of adding the two user-controlled values.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
---
 ethtool.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ethtool.c b/ethtool.c
index 3076c12..fa0f729 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5051,10 +5051,17 @@ static int do_getmodule(struct cmd_context *ctx)
 		return 1;
 	}
 
+	if (geeprom_offset >= modinfo.eeprom_len) {
+		fprintf(stderr,
+			"Invalid offset %u: module EEPROM is %u bytes\n",
+			geeprom_offset, modinfo.eeprom_len);
+		return 1;
+	}
+
 	if (!geeprom_length_seen)
 		geeprom_length = modinfo.eeprom_len;
 
-	if (modinfo.eeprom_len < geeprom_offset + geeprom_length)
+	if (geeprom_length > modinfo.eeprom_len - geeprom_offset)
 		geeprom_length = modinfo.eeprom_len - geeprom_offset;
 
 	eeprom = calloc(1, sizeof(*eeprom)+geeprom_length);
-- 
2.55.0


      parent reply	other threads:[~2026-08-31 10:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 10:41 [PATCH ethtool 0/2] harden module EEPROM length handling Prabhakar Pujeri
2026-08-31 10:41 ` [PATCH ethtool 1/2] netlink: module-eeprom: clamp data length to attribute payload size Prabhakar Pujeri
2026-08-31 10:41 ` Prabhakar Pujeri [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260831104125.2203-3-prabhakar.pujeri@dell.com \
    --to=prabhakar.pujeri@dell.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox