Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1045211pxu; Fri, 16 Oct 2020 02:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGBTT77pZi59uO22FCnZ+OAyXEZ4u4xdYYZffAxpvmvI+h0rP7dgeJNEA2VH44yitWeOjZ X-Received: by 2002:a17:906:6b89:: with SMTP id l9mr2590638ejr.297.1602840084530; Fri, 16 Oct 2020 02:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602840084; cv=none; d=google.com; s=arc-20160816; b=yTPYXdwMpfWla29k0NGCbMWdVaaW0cE3VPhp5hFATVom1FVfLkhJcPU/elnOaFUgPv 7sd0Gjq23uycZxaGX2aha7Qa6owrQOIBABsM3pUKxRqIjFJBnguAfPqmoVAq+TiUfO11 pl6dn00J+R7AdpvIM00/NhGpB1miBQHMs5LTRP5TMp+YMUhZqisAH0DB3Lal9/DRFsa4 2mzplz2062DGdIZ0QDbr6nEDEDxQA2F8sBW/rPxbMMgxTaIUNHY6c8CebO+OFFvnJwQ/ HclbjPcBT+jLdwZwjarD1Qc8osHdp3GtSyLY/y/bDJ0BFrPVdX7UV2uoeCqihyjE4SRI FL5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=blweLOVKtUQezqxbOgWox+zh5bjFI+rERCnAlu5y+E8=; b=L6Rlyd469/x8y+pOknZgRXT3mp3NlKyhZGLv1LUILmVNhZdrDbmQ0PZ0eygUPvDrc+ LvUltuWIzCNgeFsdWbegvWu+7ojMDZiZXaXZDMihXkqgX8E97+D/o/E6OMMlNL12A31j rJXGnBF5RtHnXr0Z606eWiFgs5szcv0tCS03vJ+gta5RYLmj/+37mNB11il4TTo9g6ln E0dGaKPBi4jZbrgIx26h4KTmi9VdB4yoD+2kK6XbIKJX4oLnVr2XHsnVX7y2VkFItFSO /Xqiifz1AsXte5rPgvliUTRrTlCSY6Ha7UbRuNpnURAdGNgFMHYkui2eem3fRCh3MttS OeXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vOPTC4lP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si1207153edq.345.2020.10.16.02.21.02; Fri, 16 Oct 2020 02:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vOPTC4lP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406363AbgJPJQ3 (ORCPT + 99 others); Fri, 16 Oct 2020 05:16:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:36930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405486AbgJPJI0 (ORCPT ); Fri, 16 Oct 2020 05:08:26 -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 D085120FC3; Fri, 16 Oct 2020 09:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839305; bh=OoE6l8w0bDZyAAAU5qeoh52s+dkn/QHzuvASvsuQ+z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vOPTC4lPHcuNHBGc015XKoulWg5D8RaBrxawM3UzugVj1TvZDb7sOs5/M1kyVOusC psyhIuL7vR/tVUWctRhSyamcMwj2GNFzilci9GMZU4PrRdWAb5J5G5Gfmb2t3p4Sww gJaz6c8JQk+gNxt0/C5ErFvtcyo++XJ8DZohmjOM= 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.14 03/18] Bluetooth: L2CAP: Fix calling sk_filter on non-socket based channel Date: Fri, 16 Oct 2020 11:07:13 +0200 Message-Id: <20201016090437.440034815@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.265805669@linuxfoundation.org> References: <20201016090437.265805669@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: linux-kernel@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 @@ -1477,6 +1477,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, @@ -1491,6 +1504,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)