Skip to content

Commit 89c22d8

Browse files
herbertxdavem330
authored andcommitted
net: Fix skb csum races when peeking
When we calculate the checksum on the recv path, we store the result in the skb as an optimisation in case we need the checksum again down the line. This is in fact bogus for the MSG_PEEK case as this is done without any locking. So multiple threads can peek and then store the result to the same skb, potentially resulting in bogus skb states. This patch fixes this by only storing the result if the skb is not shared. This preserves the optimisations for the few cases where it can be done safely due to locking or other reasons, e.g., SIOCINQ. Signed-off-by: Herbert Xu <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c9805b9 commit 89c22d8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

net/core/datagram.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len)
657657
!skb->csum_complete_sw)
658658
netdev_rx_csum_fault(skb->dev);
659659
}
660-
skb->csum_valid = !sum;
660+
if (!skb_shared(skb))
661+
skb->csum_valid = !sum;
661662
return sum;
662663
}
663664
EXPORT_SYMBOL(__skb_checksum_complete_head);
@@ -677,11 +678,13 @@ __sum16 __skb_checksum_complete(struct sk_buff *skb)
677678
netdev_rx_csum_fault(skb->dev);
678679
}
679680

680-
/* Save full packet checksum */
681-
skb->csum = csum;
682-
skb->ip_summed = CHECKSUM_COMPLETE;
683-
skb->csum_complete_sw = 1;
684-
skb->csum_valid = !sum;
681+
if (!skb_shared(skb)) {
682+
/* Save full packet checksum */
683+
skb->csum = csum;
684+
skb->ip_summed = CHECKSUM_COMPLETE;
685+
skb->csum_complete_sw = 1;
686+
skb->csum_valid = !sum;
687+
}
685688

686689
return sum;
687690
}

0 commit comments

Comments
 (0)