mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ice: clamp package info count to the response buffer
@ 2026-11-08 23:55 Noah Weinberger
  2026-11-09 13:02 ` Przemek Kitszel
  0 siblings, 1 reply; 2+ messages in thread
From: Noah Weinberger @ 2026-11-08 23:55 UTC (permalink / raw)
  To: anthony.l.nguyen, przemyslaw.kitszel; +Cc: linux-kernel

Hello,

ice_get_pkg_info() and the DDP-load compatibility check iterate
over the count field of the admin-queue GET_PKG_INFO response, but
the response buffer is a flexible array sized ICE_PKG_CNT (4):

    DEFINE_RAW_FLEX(struct ice_aqc_get_pkg_info_resp, pkg_info, pkg_info,
                    ICE_PKG_CNT);
    ...
    for (i = 0; i < le32_to_cpu(pkg_info->count); i++) {

A device (or compromised firmware) that reports more than four
entries makes both loops read past the stack buffer, and the
'active package' name/version handling then copies out-of-bounds
stack data into hw->active_pkg_name. The patch clamps both loops to
the buffer size.

Affected version/commit: mainline 8a65162514fbad21a2c58ffed65f42b27e92b163 (v7.4-rc2 window, 2026-11-08), drivers/net/ethernet/intel/ice/ice_ddp.c:1993-2015 (ice_get_pkg_info: DEFINE_RAW_FLEX(..., ICE_PKG_CNT = 4) then for (i = 0; i < le32_to_cpu(pkg_info->count); i++)), :2067-2077 (same pattern with pkg->count)
Longstanding; converted to DEFINE_RAW_FLEX at some point without adding the clamp.

This was found during an assisted (AI-supported) static source review of
mainline 8a65162514fbad21a2c58ffed65f42b27e92b163 (v7.4-rc2 window, 2026-11-08). The patch below has NOT been compiled and has
NOT been runtime tested, and no reproducer was produced - the triggering
conditions are described above instead. Please treat this as a report for
verification rather than a battle-tested fix.

---
diff --git a/drivers/net/ethernet/intel/ice/ice_ddp.c b/drivers/net/ethernet/intel/ice/ice_ddp.c
index 3b2d9c4369..bb037ee96b 100644
--- a/drivers/net/ethernet/intel/ice/ice_ddp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ddp.c
@@ -1998,7 +1998,7 @@ static enum ice_ddp_state ice_get_pkg_info(struct ice_hw *hw)
 	if (ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL))
 		return ICE_DDP_PKG_ERR;
 
-	for (i = 0; i < le32_to_cpu(pkg_info->count); i++) {
+	for (i = 0; i < le32_to_cpu(pkg_info->count) && i < ICE_PKG_CNT; i++) {
 #define ICE_PKG_FLAG_COUNT 4
 		char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
 		u8 place = 0;
@@ -2067,7 +2067,7 @@ static enum ice_ddp_state ice_chk_pkg_compat(struct ice_hw *hw,
 	if (ice_aq_get_pkg_info_list(hw, pkg, size, NULL))
 		return ICE_DDP_PKG_LOAD_ERROR;
 
-	for (i = 0; i < le32_to_cpu(pkg->count); i++) {
+	for (i = 0; i < le32_to_cpu(pkg->count) && i < ICE_PKG_CNT; i++) {
 		/* loop till we find the NVM package */
 		if (!pkg->pkg_info[i].is_in_nvm)
 			continue;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-09 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 23:55 [PATCH] ice: clamp package info count to the response buffer Noah Weinberger
2026-11-09 13:02 ` Przemek Kitszel

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®