From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC525C43457 for ; Fri, 16 Oct 2020 09:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 526D820878 for ; Fri, 16 Oct 2020 09:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839367; bh=vOdKTAWst7QDZJoO5L0YX6rbYMZ22uuei9AycgASwPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GH2loz+WQ9UtEzm3ssYzTo7m4uf/hwwg3XcQDhYhf6qypaiMH0dvVlte4TOeBVPIB 7IkkrbfCJOLe/NG1eqXS1qV3Lh1JIa9nX+302aDGD/5K7eZZjpTqB7WqNjpRr29T2I Y8SGnsGuzrG52LyxwL0EAKpVZKctoPf4EMK1qJ7Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405022AbgJPJJ0 (ORCPT ); Fri, 16 Oct 2020 05:09:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:38034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394765AbgJPJJW (ORCPT ); Fri, 16 Oct 2020 05:09:22 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D874020FC3; Fri, 16 Oct 2020 09:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839361; bh=vOdKTAWst7QDZJoO5L0YX6rbYMZ22uuei9AycgASwPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D+fQ/28BYpAjHbE7SSO8cwOH97HfwCEinhpObiHTpenC+kiGzkHdYBSHhiqzlpAcH 2rW39zQydF0UhI4rMepwgMqKECeg+skZ40VpWQeByf+GeGLZARaNJ0DHflowwixZMZ H9IKRZVQAUX+isXV6j4fvRgInsXq091ofhevEUWo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann Subject: [PATCH 4.19 06/21] Bluetooth: L2CAP: Fix calling sk_filter on non-socket based channel Date: Fri, 16 Oct 2020 11:07:25 +0200 Message-Id: <20201016090437.617583992@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.301376476@linuxfoundation.org> References: <20201016090437.301376476@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Luiz Augusto von Dentz commit f19425641cb2572a33cb074d5e30283720bd4d22 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 Signed-off-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- include/net/bluetooth/l2cap.h | 2 ++ net/bluetooth/l2cap_core.c | 7 ++++--- net/bluetooth/l2cap_sock.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -619,6 +619,8 @@ struct l2cap_ops { struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, unsigned long hdr_len, unsigned long len, int nb); + int (*filter) (struct l2cap_chan * chan, + struct sk_buff *skb); }; struct l2cap_conn { --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -6683,9 +6683,10 @@ static int l2cap_data_rcv(struct l2cap_c goto drop; } - if ((chan->mode == L2CAP_MODE_ERTM || - chan->mode == L2CAP_MODE_STREAMING) && sk_filter(chan->data, skb)) - goto drop; + if (chan->ops->filter) { + if (chan->ops->filter(chan, skb)) + goto drop; + } if (!control->sframe) { int err; --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1476,6 +1476,19 @@ static void l2cap_sock_suspend_cb(struct sk->sk_state_change(sk); } +static int l2cap_sock_filter(struct l2cap_chan *chan, struct sk_buff *skb) +{ + struct sock *sk = chan->data; + + switch (chan->mode) { + case L2CAP_MODE_ERTM: + case L2CAP_MODE_STREAMING: + return sk_filter(sk, skb); + } + + return 0; +} + static const struct l2cap_ops l2cap_chan_ops = { .name = "L2CAP Socket Interface", .new_connection = l2cap_sock_new_connection_cb, @@ -1490,6 +1503,7 @@ static const struct l2cap_ops l2cap_chan .set_shutdown = l2cap_sock_set_shutdown_cb, .get_sndtimeo = l2cap_sock_get_sndtimeo_cb, .alloc_skb = l2cap_sock_alloc_skb_cb, + .filter = l2cap_sock_filter, }; static void l2cap_sock_destruct(struct sock *sk)