Skip to content

Commit d9fbd02

Browse files
committed
Bluetooth: Use explicit header and body length for L2CAP SKB allocation
When allocating the L2CAP SKB for transmission, provide the upper layers with a clear distinction on what is the header and what is the body portion of the SKB. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent 0775899 commit d9fbd02

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎include/net/bluetooth/l2cap.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ struct l2cap_ops {
600600
void (*set_shutdown) (struct l2cap_chan *chan);
601601
long (*get_sndtimeo) (struct l2cap_chan *chan);
602602
struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
603+
unsigned long hdr_len,
603604
unsigned long len, int nb);
604605
};
605606

‎net/bluetooth/a2mp.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,12 @@ static void a2mp_chan_state_change_cb(struct l2cap_chan *chan, int state,
693693
}
694694

695695
static struct sk_buff *a2mp_chan_alloc_skb_cb(struct l2cap_chan *chan,
696+
unsigned long hdr_len,
696697
unsigned long len, int nb)
697698
{
698699
struct sk_buff *skb;
699700

700-
skb = bt_skb_alloc(len, GFP_KERNEL);
701+
skb = bt_skb_alloc(hdr_len + len, GFP_KERNEL);
701702
if (!skb)
702703
return ERR_PTR(-ENOMEM);
703704

‎net/bluetooth/l2cap_core.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
21312131

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

2134-
tmp = chan->ops->alloc_skb(chan, count,
2134+
tmp = chan->ops->alloc_skb(chan, 0, count,
21352135
msg->msg_flags & MSG_DONTWAIT);
21362136
if (IS_ERR(tmp))
21372137
return PTR_ERR(tmp);
@@ -2166,7 +2166,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan,
21662166

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

2169-
skb = chan->ops->alloc_skb(chan, count + hlen,
2169+
skb = chan->ops->alloc_skb(chan, hlen, count,
21702170
msg->msg_flags & MSG_DONTWAIT);
21712171
if (IS_ERR(skb))
21722172
return skb;
@@ -2197,7 +2197,7 @@ static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
21972197

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

2200-
skb = chan->ops->alloc_skb(chan, count + L2CAP_HDR_SIZE,
2200+
skb = chan->ops->alloc_skb(chan, L2CAP_HDR_SIZE, count,
22012201
msg->msg_flags & MSG_DONTWAIT);
22022202
if (IS_ERR(skb))
22032203
return skb;
@@ -2239,7 +2239,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
22392239

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

2242-
skb = chan->ops->alloc_skb(chan, count + hlen,
2242+
skb = chan->ops->alloc_skb(chan, hlen, count,
22432243
msg->msg_flags & MSG_DONTWAIT);
22442244
if (IS_ERR(skb))
22452245
return skb;
@@ -2360,7 +2360,7 @@ static struct sk_buff *l2cap_create_le_flowctl_pdu(struct l2cap_chan *chan,
23602360

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

2363-
skb = chan->ops->alloc_skb(chan, count + hlen,
2363+
skb = chan->ops->alloc_skb(chan, hlen, count,
23642364
msg->msg_flags & MSG_DONTWAIT);
23652365
if (IS_ERR(skb))
23662366
return skb;

‎net/bluetooth/l2cap_sock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,14 +1292,15 @@ static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state,
12921292
}
12931293

12941294
static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
1295+
unsigned long hdr_len,
12951296
unsigned long len, int nb)
12961297
{
12971298
struct sock *sk = chan->data;
12981299
struct sk_buff *skb;
12991300
int err;
13001301

13011302
l2cap_chan_unlock(chan);
1302-
skb = bt_skb_send_alloc(sk, len, nb, &err);
1303+
skb = bt_skb_send_alloc(sk, hdr_len + len, nb, &err);
13031304
l2cap_chan_lock(chan);
13041305

13051306
if (!skb)

0 commit comments

Comments
 (0)