scsi: fcoe: Fix use-after-free after pskb_may_pull() in fcoe_rcv()
Subsystems (3)
PATCH 1/1 scsi: fcoe: Fix use-after-free after pskb_may_pull() in fcoe_rcv()
In fcoe_rcv(), eh = eth_hdr(skb) is cached before pskb_may_pull(). If pskb_may_pull() reallocates skb->head, eh is left pointing to freed memory when validating eh->h_dest against the FC frame header.
Re-evaluate eh = eth_hdr(skb) after pskb_may_pull() succeeds.
---
I am trying out new Clang static analysis checks for kernel bug classes, and they flagged this code as possibly buggy. The findings were triaged/fixed and commit descriptions were drafted with help of AI, then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
drivers/scsi/fcoe/fcoe.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/fcoe/fcoe.c +2 -0
@@ -1365,6 +1365,8 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, !pskb_may_pull(skb, FCOE_HEADER_LEN))) goto err; + eh =eth_hdr (skb); +skb_set_transport_header (skb,sizeof (struct fcoe_hdr )); fh = (struct fc_frame_header *)skb_transport_header (skb);
Signature · 1 line
2.56.1.839.g22a8290db9-goog
Hannes Reinecke
maintainerQuoted 27 lines · Elkin Cruz
In
fcoe_rcv(), eh =eth_hdr(skb)is cached beforepskb_may_pull(). Ifpskb_may_pull()reallocatesskb->head, eh is left pointing to freed memory when validatingeh->h_destagainst the FC frame header.Re-evaluate eh =
eth_hdr(skb)afterpskb_may_pull()succeeds.Fixes 0ee31cb5df4b ("[SCSI] fcoe: Fix broken NPIV with correction to MAC validation")Signed-off-by Elkin Cruz <[email protected]>---
I am trying out new Clang static analysis checks for kernel bug classes, and they flagged this code as possibly buggy. The findings were triaged/fixed and commit descriptions were drafted with help of AI, then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkindrivers/scsi/fcoe/fcoe.c | 2 ++ 1 file changed, 2 insertions(+)drivers/scsi/fcoe/fcoe.c +0
-0
drivers/scsi/fcoe/fcoe.c static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, · line 1372
Quoted 8 lines
drivers/scsi/fcoe/fcoe.c +2
-0@@ -1365,6 +1365,8 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, !pskb_may_pull(skb, FCOE_HEADER_LEN))) goto err; + eh =eth_hdr (skb); +skb_set_transport_header (skb,sizeof (struct fcoe_hdr )); fh = (struct fc_frame_header *)skb_transport_header (skb);
Please move that two lines down, just before
if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id))
that'll make the patch easier to read. And please add a comment that the skb->head might have been reallocated.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich