mdio-tools: backport segfault fix

Return an ENOMEM error when the buffer is too small to perform the operation.

Before:
$ mdio mt7530-0 0x05:31 dump 0x0+512
Segmentation fault

After:
$ mdio mt7530-0 0x05:31 dump 0x0+512
ERROR: Dump operation failed (-12)

Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
This commit is contained in:
Aleksander Jan Bajkowski
2025-09-07 19:24:07 +02:00
committed by Robert Marko
parent 2590594111
commit 63656f59ec
2 changed files with 35 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=mdio-tools
PKG_VERSION:=1.3.1
PKG_RELEASE:=2
PKG_RELEASE:=3
PKG_SOURCE_URL:=https://github.com/wkz/mdio-tools
PKG_SOURCE_PROTO:=git

View File

@@ -0,0 +1,34 @@
From d7e314e45c112198d15220333b869604478a2e49 Mon Sep 17 00:00:00 2001
From: Aleksander Jan Bajkowski <olek2@wp.pl>
Date: Sun, 28 Sep 2025 23:31:00 +0200
Subject: [PATCH] mdio: fix segmentation fault in dump operation
Return an ENOMEM error when the buffer is too small to
perform the operation.
Before:
$ mdio mt7530-0 0x05:31 dump 0x0+512
Segmentation fault
After:
$ mdio mt7530-0 0x05:31 dump 0x0+512
ERROR: Dump operation failed (-12)
Fixes: 882488711ca0 ("mdio: Add common dump operation to read ranges of registers")
Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
---
src/mdio/mdio.c | 3 +++
1 file changed, 3 insertions(+)
--- a/src/mdio/mdio.c
+++ b/src/mdio/mdio.c
@@ -613,6 +613,9 @@ int mdio_xfer_timeout(const char *bus, s
struct nlmsghdr *nlh;
int err;
+ if (prog->len * sizeof(*prog->insns) > len)
+ return -ENOMEM;
+
nlh = msg_init(MDIO_GENL_XFER, NLM_F_REQUEST | NLM_F_ACK);
if (!nlh)
return -ENOMEM;