Skip to content

Commit 7162fb2

Browse files
edumazetdavem330
authored andcommitted
tcp: do not underestimate skb->truesize in tcp_trim_head()
Andrey found a way to trigger the WARN_ON_ONCE(delta < len) in skb_try_coalesce() using syzkaller and a filter attached to a TCP socket over loopback interface. I believe one issue with looped skbs is that tcp_trim_head() can end up producing skb with under estimated truesize. It hardly matters for normal conditions, since packets sent over loopback are never truncated. Bytes trimmed from skb->head should not change skb truesize, since skb->head is not reallocated. Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Andrey Konovalov <[email protected]> Tested-by: Andrey Konovalov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 19cdead commit 7162fb2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

net/ipv4/tcp_output.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
12671267
* eventually). The difference is that pulled data not copied, but
12681268
* immediately discarded.
12691269
*/
1270-
static void __pskb_trim_head(struct sk_buff *skb, int len)
1270+
static int __pskb_trim_head(struct sk_buff *skb, int len)
12711271
{
12721272
struct skb_shared_info *shinfo;
12731273
int i, k, eat;
@@ -1277,7 +1277,7 @@ static void __pskb_trim_head(struct sk_buff *skb, int len)
12771277
__skb_pull(skb, eat);
12781278
len -= eat;
12791279
if (!len)
1280-
return;
1280+
return 0;
12811281
}
12821282
eat = len;
12831283
k = 0;
@@ -1303,23 +1303,28 @@ static void __pskb_trim_head(struct sk_buff *skb, int len)
13031303
skb_reset_tail_pointer(skb);
13041304
skb->data_len -= len;
13051305
skb->len = skb->data_len;
1306+
return len;
13061307
}
13071308

13081309
/* Remove acked data from a packet in the transmit queue. */
13091310
int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
13101311
{
1312+
u32 delta_truesize;
1313+
13111314
if (skb_unclone(skb, GFP_ATOMIC))
13121315
return -ENOMEM;
13131316

1314-
__pskb_trim_head(skb, len);
1317+
delta_truesize = __pskb_trim_head(skb, len);
13151318

13161319
TCP_SKB_CB(skb)->seq += len;
13171320
skb->ip_summed = CHECKSUM_PARTIAL;
13181321

1319-
skb->truesize -= len;
1320-
sk->sk_wmem_queued -= len;
1321-
sk_mem_uncharge(sk, len);
1322-
sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
1322+
if (delta_truesize) {
1323+
skb->truesize -= delta_truesize;
1324+
sk->sk_wmem_queued -= delta_truesize;
1325+
sk_mem_uncharge(sk, delta_truesize);
1326+
sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
1327+
}
13231328

13241329
/* Any change of skb->len requires recalculation of tso factor. */
13251330
if (tcp_skb_pcount(skb) > 1)

0 commit comments

Comments
 (0)