From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD6A8C9833E for ; Mon, 28 Sep 2026 07:01:47 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36E3C40E40; Mon, 28 Sep 2026 09:00:23 +0200 (CEST) Received: from forward501a.mail.yandex.net (forward501a.mail.yandex.net [178.154.239.81]) by mails.dpdk.org (Postfix) with ESMTP id A6D0A4026D for ; Sun, 27 Sep 2026 13:20:56 +0200 (CEST) Received: from mail-nwsmtp-smtp-production-main-84.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-84.vla.yp-c.yandex.net [IPv6:2a02:6b8:c0f:39a:0:640:15c4:0]) by forward501a.mail.yandex.net (postfix) with ESMTPS id 08FDA810FF; Sun, 27 Sep 2026 14:20:56 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-84.vla.yp-c.yandex.net (smtp) with ESMTPSA id kKeTQKZfsSw0-QpQQkqdT; Sun, 27 Sep 2026 14:20:55 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1790508055; bh=0q4ww7LCMRBS9U86lNM8DD8v55F/mfu8pJ0FvScSxiQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=BHohJdad1yUZugOcVwHMtAA7GZmrqz53zG6BEtTuJuIpUOX3+geJ2pj1MQH8P5D2A XEu8q98/Mh/rTSpO8Bk3Zq4oCjryiy2HIjDNk43jOLt7ZjNjZmbruzccfl0hGZMXwV pHKuRbwTOLelqsxMGrdBdNwTBg8LylYmkioSKtDY= Authentication-Results: mail-nwsmtp-smtp-production-main-84.vla.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Roman Khromenok To: dev@dpdk.org Cc: Thomas Monjalon , Andrew Rybchenko Subject: [PATCH 2/4] ethdev: check module EEPROM length before decoding Date: Sun, 27 Sep 2026 13:20:39 +0200 Message-ID: <20260927112041.775972-3-roma55592@yandex.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260927112041.775972-1-roma55592@yandex.ru> References: <20260927112041.775972-1-roma55592@yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 28 Sep 2026 08:59:13 +0200 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The SFF decoders assume the buffer is large enough for the module type: SFF-8079 and SFF-8472 do not receive the length at all, and SFF-8636 only uses it to detect the optional page 03h. If a driver reports a length shorter than the type requires, the decoders read past the end of the buffer. Move the type dispatch into a common internal function which checks the minimal length for each type before decoding: - SFF-8079 and SFF-8436/8636 require at least 256 bytes, - SFF-8472 requires 256 bytes for the base information, and the diagnostics (page A2h) are decoded only if 512 bytes are available. This is a preparation for exposing the decoders to applications, which may pass buffers of arbitrary length. Signed-off-by: Roman Khromenok --- lib/ethdev/sff_telemetry.c | 37 +++++++++++++++++++++++++++++-------- lib/ethdev/sff_telemetry.h | 8 ++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/ethdev/sff_telemetry.c b/lib/ethdev/sff_telemetry.c index 8c8e95affe..72d55322b6 100644 --- a/lib/ethdev/sff_telemetry.c +++ b/lib/ethdev/sff_telemetry.c @@ -99,25 +99,46 @@ sff_port_module_eeprom_parse(uint16_t port_id, struct rte_tel_data *d) return; } - switch (minfo.type) { + ret = sff_decode_module_eeprom(minfo.type, einfo.data, einfo.length, &out); + if (ret == -ENOTSUP) + RTE_ETHDEV_LOG_LINE(NOTICE, "Unsupported module type: %u", minfo.type); + else if (ret != 0) + RTE_ETHDEV_LOG_LINE(ERR, "Port %u module EEPROM is too short: %u bytes", + port_id, einfo.length); + + free(einfo.data); +} + +int +sff_decode_module_eeprom(uint32_t type, const uint8_t *data, uint32_t length, + struct sff_output *d) +{ + switch (type) { /* parsing module EEPROM data base on different module type */ case RTE_ETH_MODULE_SFF_8079: - sff_8079_show_all(einfo.data, &out); + if (length < RTE_ETH_MODULE_SFF_8079_LEN) + return -EINVAL; + sff_8079_show_all(data, d); break; case RTE_ETH_MODULE_SFF_8472: - sff_8079_show_all(einfo.data, &out); - sff_8472_show_all(einfo.data, &out); + if (length < RTE_ETH_MODULE_SFF_8079_LEN) + return -EINVAL; + sff_8079_show_all(data, d); + /* diagnostics are in the second page (A2h) */ + if (length >= RTE_ETH_MODULE_SFF_8472_LEN) + sff_8472_show_all(data, d); break; case RTE_ETH_MODULE_SFF_8436: case RTE_ETH_MODULE_SFF_8636: - sff_8636_show_all(einfo.data, einfo.length, &out); + if (length < RTE_ETH_MODULE_SFF_8636_LEN) + return -EINVAL; + sff_8636_show_all(data, length, d); break; default: - RTE_ETHDEV_LOG_LINE(NOTICE, "Unsupported module type: %u", minfo.type); - break; + return -ENOTSUP; } - free(einfo.data); + return 0; } void diff --git a/lib/ethdev/sff_telemetry.h b/lib/ethdev/sff_telemetry.h index 2a6d79a9c1..1d2c8fd444 100644 --- a/lib/ethdev/sff_telemetry.h +++ b/lib/ethdev/sff_telemetry.h @@ -25,6 +25,14 @@ void sff_8472_show_all(const uint8_t *data, struct sff_output *d); /* SFF-8636 Optics diagnostics */ void sff_8636_show_all(const uint8_t *data, uint32_t eeprom_len, struct sff_output *d); +/* + * Decode module EEPROM of the given type (RTE_ETH_MODULE_SFF_*). + * Returns 0 on success, -EINVAL if the data is too short for the type, + * -ENOTSUP if the type is unknown. + */ +int sff_decode_module_eeprom(uint32_t type, const uint8_t *data, uint32_t length, + struct sff_output *d); + int eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params, struct rte_tel_data *d); -- 2.47.3