Subject: Re: skb_try_coalesce bug?

From: Jon Maloy <[email-masked]>
Date: Tue, 22 Apr 2014 15:38:00 -0400

On 04/22/2014 09:11 AM, Eric Dumazet wrote:
> On Tue, 2014-04-22 at 14:01 +0200, Erik Hugne wrote:
>> It seems that if the head skb of a reassembly chain have enough tailroom
>> to hold the data of a received fragment, skb_try_coalesce() will append this
>> directly to the head, even if preceding fragments have been put on a frag list.
>> This will cause a corrupted buffer to be passed to userland when 
>> skb_copy_datagram_iovec() later copies the contents of head, and then each frag
>> one by one to the target iovec.
>>  
>> Is skb_try_coalesce() broken, or are we using it wrongly in tipc?
> 
> I am not sure how it could happen with the current implementation ?
> 
> static inline bool skb_is_nonlinear(const struct sk_buff *skb)
> {
> 	return skb->data_len;
> }
> 
> static inline int skb_tailroom(const struct sk_buff *skb)
> {
> 	return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
> }
> 
> /**
>  * skb_try_coalesce - try to merge skb to prior one
>  * @to: prior buffer
>  * @from: buffer to add
>  * @fragstolen: pointer to boolean
>  * @delta_truesize: how much more was allocated than was requested
>  */
> bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
>                       bool *fragstolen, int *delta_truesize)
> {
>         int i, delta, len = from->len;
> 
>         *fragstolen = false;
> 
>         if (skb_cloned(to))
>                 return false;
> 
>         if (len <= skb_tailroom(to)) {
>                 BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len));

In the case I encountered, our head buffer is linear (skb->data_len == 0),
so it is the real tailroom value that is returned. An alas, that one is big
enough to contain the last (small) fragment of the message.

///jon

> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to [email-masked]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>