Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: lapb: Copy the skb before sending a packet

When sending a packet, we will prepend it with an LAPB header.
This modifies the shared parts of a cloned skb, so we should copy the
skb rather than just clone it, before we prepend the header.

In "Documentation/networking/driver.rst" (the 2nd point), it states
that drivers shouldn't modify the shared parts of a cloned skb when
transmitting.

The "dev_queue_xmit_nit" function in "net/core/dev.c", which is called
when an skb is being sent, clones the skb and sents the clone to
AF_PACKET sockets. Because the LAPB drivers first remove a 1-byte
pseudo-header before handing over the skb to us, if we don't copy the
skb before prepending the LAPB header, the first byte of the packets
received on AF_PACKET sockets can be corrupted.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Xie He <xie.he.0141@gmail.com>
Acked-by: Martin Schiller <ms@dev.tdt.de>
Link: https://lore.kernel.org/r/20210201055706.415842-1-xie.he.0141@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Xie He and committed by
Jakub Kicinski
88c7a9fd f418bad6

+2 -1
+2 -1
net/lapb/lapb_out.c
··· 82 82 skb = skb_dequeue(&lapb->write_queue); 83 83 84 84 do { 85 - if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) { 85 + skbn = skb_copy(skb, GFP_ATOMIC); 86 + if (!skbn) { 86 87 skb_queue_head(&lapb->write_queue, skb); 87 88 break; 88 89 }