Skip to content

Commit

Permalink
Bluetooth: Fix wrong set of skb fragments
Browse files Browse the repository at this point in the history
If alloc() fails we let the frags linked list with garbage value (the
err ptr value) in its last element.

Reported-by: Mat Martineau <mathewm@codeaurora.org>
Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
Gustavo Padovan authored and Gustavo Padovan committed May 16, 2012
1 parent 08e6d90 commit fbe0070
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions net/bluetooth/l2cap_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,13 +1836,17 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
/* Continuation fragments (no L2CAP header) */
frag = &skb_shinfo(skb)->frag_list;
while (len) {
struct sk_buff *tmp;

count = min_t(unsigned int, conn->mtu, len);

*frag = chan->ops->alloc_skb(chan, count,
msg->msg_flags & MSG_DONTWAIT);
tmp = chan->ops->alloc_skb(chan, count,
msg->msg_flags & MSG_DONTWAIT);
if (IS_ERR(tmp))
return PTR_ERR(tmp);

*frag = tmp;

if (IS_ERR(*frag))
return PTR_ERR(*frag);
if (memcpy_fromiovec(skb_put(*frag, count), msg->msg_iov, count))
return -EFAULT;

Expand Down

0 comments on commit fbe0070

Please sign in to comment.