Skip to content

Commit 3dede8e

Browse files
Vudentzgregkh
authored andcommitted
Bluetooth: L2CAP: Fix calling sk_filter on non-socket based channel
commit f194256 upstream. Only sockets will have the chan->data set to an actual sk, channels like A2MP would have its own data which would likely cause a crash when calling sk_filter, in order to fix this a new callback has been introduced so channels can implement their own filtering if necessary. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 122414e commit 3dede8e

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

include/net/bluetooth/l2cap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ struct l2cap_ops {
665665
struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
666666
unsigned long hdr_len,
667667
unsigned long len, int nb);
668+
int (*filter) (struct l2cap_chan * chan,
669+
struct sk_buff *skb);
668670
};
669671

670672
struct l2cap_conn {

net/bluetooth/l2cap_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7301,9 +7301,10 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
73017301
goto drop;
73027302
}
73037303

7304-
if ((chan->mode == L2CAP_MODE_ERTM ||
7305-
chan->mode == L2CAP_MODE_STREAMING) && sk_filter(chan->data, skb))
7306-
goto drop;
7304+
if (chan->ops->filter) {
7305+
if (chan->ops->filter(chan, skb))
7306+
goto drop;
7307+
}
73077308

73087309
if (!control->sframe) {
73097310
int err;

net/bluetooth/l2cap_sock.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,19 @@ static void l2cap_sock_suspend_cb(struct l2cap_chan *chan)
16631663
sk->sk_state_change(sk);
16641664
}
16651665

1666+
static int l2cap_sock_filter(struct l2cap_chan *chan, struct sk_buff *skb)
1667+
{
1668+
struct sock *sk = chan->data;
1669+
1670+
switch (chan->mode) {
1671+
case L2CAP_MODE_ERTM:
1672+
case L2CAP_MODE_STREAMING:
1673+
return sk_filter(sk, skb);
1674+
}
1675+
1676+
return 0;
1677+
}
1678+
16661679
static const struct l2cap_ops l2cap_chan_ops = {
16671680
.name = "L2CAP Socket Interface",
16681681
.new_connection = l2cap_sock_new_connection_cb,
@@ -1678,6 +1691,7 @@ static const struct l2cap_ops l2cap_chan_ops = {
16781691
.get_sndtimeo = l2cap_sock_get_sndtimeo_cb,
16791692
.get_peer_pid = l2cap_sock_get_peer_pid_cb,
16801693
.alloc_skb = l2cap_sock_alloc_skb_cb,
1694+
.filter = l2cap_sock_filter,
16811695
};
16821696

16831697
static void l2cap_sock_destruct(struct sock *sk)

0 commit comments

Comments
 (0)