Skip to content

Commit

Permalink
net: lapb: Copy the skb before sending a packet
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Martin Schiller <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Xie He authored and kuba-moo committed Feb 2, 2021
1 parent f418bad commit 88c7a9f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/lapb/lapb_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void lapb_kick(struct lapb_cb *lapb)
skb = skb_dequeue(&lapb->write_queue);

do {
if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
skbn = skb_copy(skb, GFP_ATOMIC);
if (!skbn) {
skb_queue_head(&lapb->write_queue, skb);
break;
}
Expand Down

0 comments on commit 88c7a9f

Please sign in to comment.