From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C65C4481FD7 for ; Mon, 18 May 2026 14:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779113396; cv=none; b=uuRP2US3BW31y3tfNIbTouPOcjZlc/mrgVQHsa9IQGJOUd/yVmLBlGtXXuTTtiFo4G2lwTk+1NjEDW+2YW9ksjZw9XaOgAIAksLwF4pMSTbv6oU2rqY98lWqoJ0NtMuydP7KxTj/iSYVCnLurZy2N2LtpbEBh7zsy7aPAwzK0h0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779113396; c=relaxed/simple; bh=THmElVxW+1xGlC65m3NTKfeXYXU2Nv6oKr1bGetAz/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WmcKTXFYnlgVrC7vjiZzRe4ZTo/1YsvsFdENvOubwGGefQvPR8EZuaKC+ajpQ3pGILTnH2xb2ZqzZmXt1RQP2VVxASLLjei/bkYOZ4B85urxnF5mZTjvNNW7tBNZvVNHg+SkwcZU/YxtBKvcnSEG3jqop0FyVTBskG/KpZoKcLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AdQF9M+/; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AdQF9M+/" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-51306c36c3eso29428711cf.0 for ; Mon, 18 May 2026 07:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779113394; x=1779718194; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JcCkhUrBAXbdWT6IfHUQo8JZZr8OMY5xmgFkJbZZrG4=; b=AdQF9M+/Q1Mj7bjSWEAqxN1vjgk8Dx8JL9Y1thVf5fl1q5VtTVenWs3TCwdoCgRtVf WQKOSFDzPei2F1kB5FK8G2XyeaeQZj183nEURjRwatEa0LmhG8wEPlYQ+B5PSeuTe/EM 4ulL2pqjVrnGYX094Z2R5gAkJE8bVDdjwFKzWSclbEI99/WAA/478p59OyvOyYmCvx9T wOzcXz/DAGAnG50i8hbFH7ozirUCNSthjzPeGGglR3YlOvaCG5USZldUELoPqjlXk/DR tK43/XUXucOgoCxHaqQMD5gc73RnVGP3D6FhC4bTQzjUxpC3TCFzLMXSIzKg/vnTxGJh eCQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779113394; x=1779718194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JcCkhUrBAXbdWT6IfHUQo8JZZr8OMY5xmgFkJbZZrG4=; b=bsJMJIoCMqLx73IQ0Gmznv8Py5tPdWub1hd/V3f4pigLp7HOYWaGe4cpjYo6MkIYpF 6Rxc4lZZIVLBemrSqVvf6PQFqWUQ/cdmeKHF59sqJ/EDhdeV900rWtXkcIoR/C2eEGef nrYixTgsHcPnDJIoz3hv4K6NO6R/fEOLTUQrWH6OzQhs8QAyQJ/l9Zn9q0rywKS6u3Mm kxO46Wy4Z76tz2wy8jo0pXlvBqxGEVEVorjmA5dSevIsqJa+lc2ZnaQpdLSrnEgLkv0l zuTqhaMLOmJF81SoqRUEW7ff+lQH4KDhkKKHdHpoaTg0KupdS4vtZ/71vwhujNk/uR/J s4IQ== X-Forwarded-Encrypted: i=1; AFNElJ9Trs8gTK+FC8HwFuKnJh7Ym0BYZRUeeOp+RQ5j+V4i1dfItTM9Ps8tNckG0ItnKKPRntXgLQmIx0uStJxF+Kc=@vger.kernel.org X-Gm-Message-State: AOJu0YzBAbXjMFzyTurQAxZmDkA3UDcS38dtL4L0rcEZXKyysUqjGTqR cqES8BRKXxD3PvpRxqYuFZ98z/z+jN/iruEC0g9rI6Q7RmryzVLTTp89 X-Gm-Gg: Acq92OHJka8VQymN/GzRiNmbEtIrliN4FT+Bx2fJqsMSfQGgFPfP8e2RcO8UmKjaVBE rzboBcaZYxQx3ayZMXjCU+rTQ4ifqJvms/VXGXhimBAQbL1wQbKdqEXDeigq4c3bm1vnhmnyX6/ wIFy8R7Z1eOte+FET9mgEBghWJImAvFz82zbNw6tDW3/313NzsRvb/VR/EpS5cOo3xvjARK+hwz zwtqHeXeN5P9Yt/jxaxmsDgGtym+kR0Dis6/lhd3uCYIoa7td7Bt5M0FZbSYfgb7NM09Sk9AjZ1 UARf/UhUF9bdpms0dUK9F5JWocn0/vBS2BefFWE+1SPUbD8OZ9jCMEci7Rx4BpEX4JcTAGpCOdC 7puL6XMrHv9nCauU6l2pymVUGwb9b3yEM4A8/uOophD2dh7gF96xsQbKCu86g/Fht6L0SI7QLaU pa4LpeC44E/uNwAWKT8quXKgQvrDR95GOE59WpR3wyHRDpZsRECMys0QgH8OVJvY9rBiBSENOzZ 44BCB74WtiXk/RerCSQEUFL79X5nlkykcHRzgk14t8= X-Received: by 2002:a05:622a:5e13:b0:50b:487c:f3d1 with SMTP id d75a77b69052e-5165a0703b6mr201830211cf.3.1779113392898; Mon, 18 May 2026 07:09:52 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-516456888f6sm139477401cf.3.2026.05.18.07.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 07:09:52 -0700 (PDT) From: Michael Bommarito To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Nilesh Javali , Himanshu Madhani , Shyam Sundar , James Smart , Hannes Reinecke , John Meneghini , Bryan Gurney , Justin Tee , Christoph Hellwig , Keith Busch , Kees Cook , linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: scsi_transport_fc: widen FPIN pname walker counter to u32 Date: Mon, 18 May 2026 10:09:45 -0400 Message-ID: <20260518140945.2751273-2-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260518140945.2751273-1-michael.bommarito@gmail.com> References: <20260518140945.2751273-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit drivers/scsi/scsi_transport_fc.c::fc_fpin_li_stats_update() and fc_fpin_peer_congn_stats_update() walked the on-wire pname_list[] with a u8 loop counter against the 32-bit __be32 pname_count field, and never bounded pname_count by the descriptor body the TLV walker already validated. A fabric-side FPIN sender (the elected fabric controller, a co-tenant N_Port that spoofs S_ID 0xFFFFFD after FLOGI, or a compromised switch supervisor) could hang the FC ELS receive thread of an lpfc or qla2xxx initiator indefinitely by emitting one FPIN ELS frame whose Link-Integrity or Peer-Congestion descriptor sets pname_count to 256, because the u8 counter rolls over and the loop condition i < pname_count stays true for every value i can take. Widen the loop counter to u32 in both walkers and clamp pname_count against the per-descriptor available bytes (desc_len minus the fixed body that precedes pname_list[]) before iterating. A malformed descriptor that claims more entries than its TLV body can hold is rejected by the clamp. Fixes: 3dcfe0de5a97 ("scsi: fc: Parse FPIN packets and update statistics") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito --- drivers/scsi/scsi_transport_fc.c | 81 ++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c index dce95e361daf0..cef0c85693fd4 100644 --- a/drivers/scsi/scsi_transport_fc.c +++ b/drivers/scsi/scsi_transport_fc.c @@ -747,7 +747,7 @@ fc_cn_stats_update(u16 event_type, struct fc_fpin_stats *stats) static void fc_fpin_li_stats_update(struct Scsi_Host *shost, struct fc_tlv_desc *tlv) { - u8 i; + u32 i, pname_count, max_count, desc_len; struct fc_rport *rport = NULL; struct fc_rport *attach_rport = NULL; struct fc_host_attrs *fc_host = shost_to_fc_host(shost); @@ -764,20 +764,34 @@ fc_fpin_li_stats_update(struct Scsi_Host *shost, struct fc_tlv_desc *tlv) fc_li_stats_update(event_type, &attach_rport->fpin_stats); } - if (be32_to_cpu(li_desc->pname_count) > 0) { - for (i = 0; - i < be32_to_cpu(li_desc->pname_count); - i++) { - wwpn = be64_to_cpu(li_desc->pname_list[i]); - rport = fc_find_rport_by_wwpn(shost, wwpn); - if (rport && - (rport->roles & FC_PORT_ROLE_FCP_TARGET || - rport->roles & FC_PORT_ROLE_NVME_TARGET)) { - if (rport == attach_rport) - continue; - fc_li_stats_update(event_type, - &rport->fpin_stats); - } + /* + * Clamp pname_count to the number of pname_list entries + * the descriptor body can actually hold. desc_len + * excludes the desc_tag/desc_len header (FC_TLV_DESC_HDR_SZ), + * so the bytes available for pname_list[] are + * desc_len - sizeof(fixed fields before pname_list[]). + */ + pname_count = be32_to_cpu(li_desc->pname_count); + desc_len = be32_to_cpu(li_desc->desc_len); + if (desc_len < sizeof(*li_desc) - FC_TLV_DESC_HDR_SZ) + max_count = 0; + else + max_count = (desc_len - + (sizeof(*li_desc) - FC_TLV_DESC_HDR_SZ)) / + sizeof(li_desc->pname_list[0]); + if (pname_count > max_count) + pname_count = max_count; + + for (i = 0; i < pname_count; i++) { + wwpn = be64_to_cpu(li_desc->pname_list[i]); + rport = fc_find_rport_by_wwpn(shost, wwpn); + if (rport && + (rport->roles & FC_PORT_ROLE_FCP_TARGET || + rport->roles & FC_PORT_ROLE_NVME_TARGET)) { + if (rport == attach_rport) + continue; + fc_li_stats_update(event_type, + &rport->fpin_stats); } } @@ -827,7 +841,7 @@ static void fc_fpin_peer_congn_stats_update(struct Scsi_Host *shost, struct fc_tlv_desc *tlv) { - u8 i; + u32 i, pname_count, max_count, desc_len; struct fc_rport *rport = NULL; struct fc_rport *attach_rport = NULL; struct fc_fn_peer_congn_desc *pc_desc = @@ -844,20 +858,27 @@ fc_fpin_peer_congn_stats_update(struct Scsi_Host *shost, fc_cn_stats_update(event_type, &attach_rport->fpin_stats); } - if (be32_to_cpu(pc_desc->pname_count) > 0) { - for (i = 0; - i < be32_to_cpu(pc_desc->pname_count); - i++) { - wwpn = be64_to_cpu(pc_desc->pname_list[i]); - rport = fc_find_rport_by_wwpn(shost, wwpn); - if (rport && - (rport->roles & FC_PORT_ROLE_FCP_TARGET || - rport->roles & FC_PORT_ROLE_NVME_TARGET)) { - if (rport == attach_rport) - continue; - fc_cn_stats_update(event_type, - &rport->fpin_stats); - } + pname_count = be32_to_cpu(pc_desc->pname_count); + desc_len = be32_to_cpu(pc_desc->desc_len); + if (desc_len < sizeof(*pc_desc) - FC_TLV_DESC_HDR_SZ) + max_count = 0; + else + max_count = (desc_len - + (sizeof(*pc_desc) - FC_TLV_DESC_HDR_SZ)) / + sizeof(pc_desc->pname_list[0]); + if (pname_count > max_count) + pname_count = max_count; + + for (i = 0; i < pname_count; i++) { + wwpn = be64_to_cpu(pc_desc->pname_list[i]); + rport = fc_find_rport_by_wwpn(shost, wwpn); + if (rport && + (rport->roles & FC_PORT_ROLE_FCP_TARGET || + rport->roles & FC_PORT_ROLE_NVME_TARGET)) { + if (rport == attach_rport) + continue; + fc_cn_stats_update(event_type, + &rport->fpin_stats); } } } -- 2.53.0