Skip to content

Commit 8754e13

Browse files
Xie Hedavem330
authored andcommitted
drivers/net/wan: lapb: Corrected the usage of skb_cow
This patch fixed 2 issues with the usage of skb_cow in LAPB drivers "lapbether" and "hdlc_x25": 1) After skb_cow fails, kfree_skb should be called to drop a reference to the skb. But in both drivers, kfree_skb is not called. 2) skb_cow should be called before skb_push so that is can ensure the safety of skb_push. But in "lapbether", it is incorrectly called after skb_push. More details about these 2 issues: 1) The behavior of calling kfree_skb on failure is also the behavior of netif_rx, which is called by this function with "return netif_rx(skb);". So this function should follow this behavior, too. 2) In "lapbether", skb_cow is called after skb_push. This results in 2 logical issues: a) skb_push is not protected by skb_cow; b) An extra headroom of 1 byte is ensured after skb_push. This extra headroom has no use in this function. It also has no use in the upper-layer function that this function passes the skb to (x25_lapb_receive_frame in net/x25/x25_dev.c). So logically skb_cow should instead be called before skb_push. Cc: Eric Dumazet <[email protected]> Cc: Martin Schiller <[email protected]> Signed-off-by: Xie He <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7df5cb7 commit 8754e13

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

drivers/net/wan/hdlc_x25.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ static int x25_data_indication(struct net_device *dev, struct sk_buff *skb)
7171
{
7272
unsigned char *ptr;
7373

74-
if (skb_cow(skb, 1))
74+
if (skb_cow(skb, 1)) {
75+
kfree_skb(skb);
7576
return NET_RX_DROP;
77+
}
7678

7779
skb_push(skb, 1);
7880
skb_reset_network_header(skb);

drivers/net/wan/lapbether.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ static int lapbeth_data_indication(struct net_device *dev, struct sk_buff *skb)
128128
{
129129
unsigned char *ptr;
130130

131-
skb_push(skb, 1);
132-
133-
if (skb_cow(skb, 1))
131+
if (skb_cow(skb, 1)) {
132+
kfree_skb(skb);
134133
return NET_RX_DROP;
134+
}
135+
136+
skb_push(skb, 1);
135137

136138
ptr = skb->data;
137139
*ptr = X25_IFACE_DATA;

0 commit comments

Comments
 (0)