Skip to content

Commit a9a3923

Browse files
mjbommarmartinkpetersen
authored andcommitted
scsi: scsi_transport_fc: Widen FPIN pname walker counter to u32
An adjacent Fibre Channel fabric actor that can deliver an FPIN ELS frame to an lpfc or qla2xxx Linux initiator can trigger a non-return in the generic FC transport. This is not a local userspace or IP network path; the attacker must be able to inject fabric traffic, for example as a compromised switch or fabric controller, or as a same-zone N_Port on a fabric that permits source spoofing. The Link-Integrity and Peer-Congestion FPIN walkers used a u8 loop counter against the 32-bit on-wire pname_count field, and did not bound pname_count by the descriptor body already validated by the TLV walker. A pname_count of 256 therefore wraps the counter and keeps the loop condition true indefinitely. Factor the shared pname_list[] walk into one helper, widen the counter to u32, and clamp pname_count against the entries that fit in the descriptor body before iterating. Fixes: 3dcfe0d ("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 <michael.bommarito@gmail.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: John Garry <john.g.garry@oracle.com> Link: https://patch.msgid.link/20260520133015.1018937-1-michael.bommarito@gmail.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent e4bb73b commit a9a3923

1 file changed

Lines changed: 41 additions & 36 deletions

File tree

drivers/scsi/scsi_transport_fc.c

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,37 @@ fc_cn_stats_update(u16 event_type, struct fc_fpin_stats *stats)
737737
}
738738
}
739739

740+
static void
741+
fc_fpin_pname_stats_update(struct Scsi_Host *shost,
742+
struct fc_rport *attach_rport, u16 event_type,
743+
u32 desc_len, u32 fixed_len, u32 pname_count,
744+
__be64 *pname_list,
745+
void (*stats_update)(u16 event_type,
746+
struct fc_fpin_stats *stats))
747+
{
748+
u32 i;
749+
struct fc_rport *rport;
750+
u64 wwpn;
751+
752+
if (desc_len < fixed_len)
753+
pname_count = 0;
754+
else
755+
pname_count = min(pname_count, (desc_len - fixed_len) /
756+
sizeof(pname_list[0]));
757+
758+
for (i = 0; i < pname_count; i++) {
759+
wwpn = be64_to_cpu(pname_list[i]);
760+
rport = fc_find_rport_by_wwpn(shost, wwpn);
761+
if (rport &&
762+
(rport->roles & FC_PORT_ROLE_FCP_TARGET ||
763+
rport->roles & FC_PORT_ROLE_NVME_TARGET)) {
764+
if (rport == attach_rport)
765+
continue;
766+
stats_update(event_type, &rport->fpin_stats);
767+
}
768+
}
769+
}
770+
740771
/*
741772
* fc_fpin_li_stats_update - routine to update Link Integrity
742773
* event statistics.
@@ -747,13 +778,11 @@ fc_cn_stats_update(u16 event_type, struct fc_fpin_stats *stats)
747778
static void
748779
fc_fpin_li_stats_update(struct Scsi_Host *shost, struct fc_tlv_desc *tlv)
749780
{
750-
u8 i;
751781
struct fc_rport *rport = NULL;
752782
struct fc_rport *attach_rport = NULL;
753783
struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
754784
struct fc_fn_li_desc *li_desc = (struct fc_fn_li_desc *)tlv;
755785
u16 event_type = be16_to_cpu(li_desc->event_type);
756-
u64 wwpn;
757786

758787
rport = fc_find_rport_by_wwpn(shost,
759788
be64_to_cpu(li_desc->attached_wwpn));
@@ -764,22 +793,11 @@ fc_fpin_li_stats_update(struct Scsi_Host *shost, struct fc_tlv_desc *tlv)
764793
fc_li_stats_update(event_type, &attach_rport->fpin_stats);
765794
}
766795

767-
if (be32_to_cpu(li_desc->pname_count) > 0) {
768-
for (i = 0;
769-
i < be32_to_cpu(li_desc->pname_count);
770-
i++) {
771-
wwpn = be64_to_cpu(li_desc->pname_list[i]);
772-
rport = fc_find_rport_by_wwpn(shost, wwpn);
773-
if (rport &&
774-
(rport->roles & FC_PORT_ROLE_FCP_TARGET ||
775-
rport->roles & FC_PORT_ROLE_NVME_TARGET)) {
776-
if (rport == attach_rport)
777-
continue;
778-
fc_li_stats_update(event_type,
779-
&rport->fpin_stats);
780-
}
781-
}
782-
}
796+
fc_fpin_pname_stats_update(shost, attach_rport, event_type,
797+
be32_to_cpu(li_desc->desc_len),
798+
FC_TLV_DESC_LENGTH_FROM_SZ(*li_desc),
799+
be32_to_cpu(li_desc->pname_count),
800+
li_desc->pname_list, fc_li_stats_update);
783801

784802
if (fc_host->port_name == be64_to_cpu(li_desc->attached_wwpn))
785803
fc_li_stats_update(event_type, &fc_host->fpin_stats);
@@ -827,13 +845,11 @@ static void
827845
fc_fpin_peer_congn_stats_update(struct Scsi_Host *shost,
828846
struct fc_tlv_desc *tlv)
829847
{
830-
u8 i;
831848
struct fc_rport *rport = NULL;
832849
struct fc_rport *attach_rport = NULL;
833850
struct fc_fn_peer_congn_desc *pc_desc =
834851
(struct fc_fn_peer_congn_desc *)tlv;
835852
u16 event_type = be16_to_cpu(pc_desc->event_type);
836-
u64 wwpn;
837853

838854
rport = fc_find_rport_by_wwpn(shost,
839855
be64_to_cpu(pc_desc->attached_wwpn));
@@ -844,22 +860,11 @@ fc_fpin_peer_congn_stats_update(struct Scsi_Host *shost,
844860
fc_cn_stats_update(event_type, &attach_rport->fpin_stats);
845861
}
846862

847-
if (be32_to_cpu(pc_desc->pname_count) > 0) {
848-
for (i = 0;
849-
i < be32_to_cpu(pc_desc->pname_count);
850-
i++) {
851-
wwpn = be64_to_cpu(pc_desc->pname_list[i]);
852-
rport = fc_find_rport_by_wwpn(shost, wwpn);
853-
if (rport &&
854-
(rport->roles & FC_PORT_ROLE_FCP_TARGET ||
855-
rport->roles & FC_PORT_ROLE_NVME_TARGET)) {
856-
if (rport == attach_rport)
857-
continue;
858-
fc_cn_stats_update(event_type,
859-
&rport->fpin_stats);
860-
}
861-
}
862-
}
863+
fc_fpin_pname_stats_update(shost, attach_rport, event_type,
864+
be32_to_cpu(pc_desc->desc_len),
865+
FC_TLV_DESC_LENGTH_FROM_SZ(*pc_desc),
866+
be32_to_cpu(pc_desc->pname_count),
867+
pc_desc->pname_list, fc_cn_stats_update);
863868
}
864869

865870
/*

0 commit comments

Comments
 (0)