mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wanquan Zhong <zwq2226404116@163.com>
To: netdev@vger.kernel.org
Cc: chandrashekar.devegowda@intel.com, haijun.liu@mediatek.com,
	ricardo.martinez@linux.intel.com, loic.poulain@oss.qualcomm.com,
	ryazanov.s.a@gmail.com, johannes@sipsolutions.net,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org,
	zwq2226404116@163.com
Subject: [PATCH net 3/5] t7xx: reject malformed runtime-feature handshake data
Date: Thu,  3 Dec 2026 14:26:33 +0800	[thread overview]
Message-ID: <eddba215978ad61a8ade0d4b383dc341b4a67bb3.1796279181.git.zwq2226404116@163.com> (raw)
In-Reply-To: <cover.1796279181.git.zwq2226404116@163.com>

This is for B.1. Malformed runtime-feature blobs can make the host
walk off the end of the handshake buffer.

Validate the feature header and payload lengths before using them.
Fail a truncated header or data_len with -EINVAL. Propagate PORT_ENUM
errors for MUST features.

Do not require FEATURE_COUNT entries: firmware may advertise a
subset of complete runtime features. A truncated record is not a
subset; a subset ends on a complete feature at offset == length.

Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
 drivers/net/wwan/t7xx/t7xx_modem_ops.c | 42 ++++++++++++++++----------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.c b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
index adb29d30c63f..e5065bf55bd6 100644
--- a/drivers/net/wwan/t7xx/t7xx_modem_ops.c
+++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
@@ -453,40 +453,50 @@ static int t7xx_parse_host_rt_data(struct t7xx_fsm_ctl *ctl, struct t7xx_sys_inf
 {
 	enum mtk_feature_support_type ft_spt_st, ft_spt_cfg;
 	struct mtk_runtime_feature *rt_feature;
-	int i, offset;
+	int i, offset, ret = 0;
+	size_t remaining, feat_data_len;
 
 	offset = sizeof(struct feature_query);
-	for (i = 0; i < FEATURE_COUNT && offset < data_length; i++) {
-		size_t remaining = data_length - offset;
-		size_t feat_data_len, feat_total;
+	if (!data || data_length < offset)
+		return -EINVAL;
 
-		if (remaining < sizeof(*rt_feature))
+	for (i = 0; i < FEATURE_COUNT && offset < data_length; i++) {
+		remaining = data_length - offset;
+		if (remaining < sizeof(*rt_feature)) {
+			ret = -EINVAL;
 			break;
+		}
 
 		rt_feature = data + offset;
 		feat_data_len = le32_to_cpu(rt_feature->data_len);
-
-		if (feat_data_len > remaining - sizeof(*rt_feature))
+		if (feat_data_len > remaining - sizeof(*rt_feature)) {
+			ret = -EINVAL;
 			break;
-
-		feat_total = sizeof(*rt_feature) + feat_data_len;
-		offset += feat_total;
+		}
 
 		ft_spt_cfg = FIELD_GET(FEATURE_MSK, core->feature_set[i]);
-		if (ft_spt_cfg != MTK_FEATURE_MUST_BE_SUPPORTED)
+		if (ft_spt_cfg != MTK_FEATURE_MUST_BE_SUPPORTED) {
+			offset += sizeof(*rt_feature) + feat_data_len;
 			continue;
+		}
 
 		ft_spt_st = FIELD_GET(FEATURE_MSK, rt_feature->support_info);
-		if (ft_spt_st != MTK_FEATURE_MUST_BE_SUPPORTED)
-			return -EINVAL;
+		if (ft_spt_st != MTK_FEATURE_MUST_BE_SUPPORTED) {
+			ret = -EINVAL;
+			break;
+		}
 
 		if (i == RT_ID_MD_PORT_ENUM || i == RT_ID_AP_PORT_ENUM) {
-			t7xx_port_enum_msg_handler(ctl->md, rt_feature->data,
-						   feat_data_len);
+			ret = t7xx_port_enum_msg_handler(ctl->md, rt_feature->data,
+							 feat_data_len);
+			if (ret)
+				break;
 		}
+
+		offset += sizeof(*rt_feature) + feat_data_len;
 	}
 
-	return 0;
+	return ret;
 }
 
 static int t7xx_core_reset(struct t7xx_modem *md)
-- 
2.53.0


  parent reply	other threads:[~2026-12-03  6:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
2026-12-03  6:26 ` [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill Wanquan Zhong
2026-12-03 13:47   ` kernel test robot
2026-12-03  6:26 ` [PATCH net 2/5] t7xx: validate control-message and PORT_ENUM payload lengths Wanquan Zhong
2026-12-03  6:26 ` Wanquan Zhong [this message]
2026-12-03  6:26 ` [PATCH net 4/5] t7xx: stop in-flight CLDMA IRQ and work before ring teardown Wanquan Zhong
2026-12-03  6:26 ` [PATCH net 5/5] t7xx: fix handshake races and skb double-free on TX/RX Wanquan Zhong
2026-12-03  6:33 ` [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown netdev-bot+sinfo

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=eddba215978ad61a8ade0d4b383dc341b4a67bb3.1796279181.git.zwq2226404116@163.com \
    --to=zwq2226404116@163.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=chandrashekar.devegowda@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=haijun.liu@mediatek.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ricardo.martinez@linux.intel.com \
    --cc=ryazanov.s.a@gmail.com \
    /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

all inboxes | Powered by JetHome®