Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1707186pxb; Wed, 9 Feb 2022 02:45:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3gkJDbfcy/w33VwMYpsZI4i4nYbeS35sk9+yvbFlA8DgpDan+Bx2rKAA0k+2a6utsZHYL X-Received: by 2002:a05:6a00:8c5:: with SMTP id s5mr1668311pfu.18.1644403503705; Wed, 09 Feb 2022 02:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644403503; cv=none; d=google.com; s=arc-20160816; b=LaxjM1+GKZMgob1cKhO7Xyy4mQrTwJoObgj3jU8WrAHki+E5fc5p+4BA3n9+CJPu1c SD4bicbFOUe3qMb6np1g6bZanOUnXrTZA/fA74k+JisyxJ7FefgIzcp/Fu7GXPwEU+yp bYYuzbwcYa+RDc4gzCZgLVZmr7N3/5ilJDuUTGlsnooBHBqWMNq5kzgWGTYiEdtv9NF2 8xkJeGfTAiDcHcj2f0H5trft97u4b40UOPGZwvT7Ea0bxtFZ9SZoSB9s4aOAG9+DmNOy BwbAjSGsnJ+mFwWyUc/aGU3JJVbJqWy7pYajl2PGqHMbWgy+y1k8kjShinFrvRoG8icF soNw== 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=5Ih/YSjlJIuPnUC3+OhhB1mzR+xtUgus0oLJrhuEAoE=; b=us8G6gUZQN5jPvNSU+CbEWWCb7RqkdUEwFqpn8rAdMYKwkojzkdvYv3V3h74z99UJu Ws1ZMr6CMrHMnYhMEcPpwDIhU5fAU3LOXVB10r4uXjLyBo7I+uncC84enOngGlpBrKWl ej1PYFv4f3jZ0jQodp6Zy7ofYVnxq9zOpenHy9kT8cd8txCJWdT6KXNjjRFpNR+/+lve AsM0gR8J6i+NaGCcvApvXxDlsH50/0bwbeoPfBYZDeM50HGHgHq3fiz+A7RTdv34rJwo nb/zsO8ZwpCxsyaHhixeqTZG3P4Vr/LZWs8Cbq17R5NIULBWqefvvLqnBwVGc4mL8fMS CRfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nJKrZ4z0; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d5si14096996pll.108.2022.02.09.02.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:45:03 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nJKrZ4z0; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0010CE0B2A82; Wed, 9 Feb 2022 01:25:42 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382446AbiBGLTL (ORCPT + 99 others); Mon, 7 Feb 2022 06:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356892AbiBGLOB (ORCPT ); Mon, 7 Feb 2022 06:14:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 284A3C0401C3; Mon, 7 Feb 2022 03:13:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AF695B811B2; Mon, 7 Feb 2022 11:13:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 028A1C3410F; Mon, 7 Feb 2022 11:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232437; bh=yeDeXjpWppdu9/9dIEFujO4fJ+lWGcnNamhR4Qn4rls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJKrZ4z0bmGBvOYSch3Kpd/04Omi1kBNihXXbVK2yZYlOR9hbgJPIGovbGLTcualY NZNS1ZXw21kV12aLgMMVFB71bnUrYqmCxyRlAGwXT8P2yTErQh83doquVXsQPaqdfG kz0HWO1pS6zuLygu+ULUIoPSWXFOboXm03ZaDE8o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Gix , Marcel Holtmann , syphyr Subject: [PATCH 4.19 01/86] Bluetooth: refactor malicious adv data check Date: Mon, 7 Feb 2022 12:05:24 +0100 Message-Id: <20220207103757.599197143@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brian Gix commit 899663be5e75dc0174dc8bda0b5e6826edf0b29a upstream. Check for out-of-bound read was being performed at the end of while num_reports loop, and would fill journal with false positives. Added check to beginning of loop processing so that it doesn't get checked after ptr has been advanced. Signed-off-by: Brian Gix Signed-off-by: Marcel Holtmann Cc: syphyr Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/hci_event.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -5391,6 +5391,11 @@ static void hci_le_adv_report_evt(struct struct hci_ev_le_advertising_info *ev = ptr; s8 rssi; + if (ptr > (void *)skb_tail_pointer(skb) - sizeof(*ev)) { + bt_dev_err(hdev, "Malicious advertising data."); + break; + } + if (ev->length <= HCI_MAX_AD_LENGTH && ev->data + ev->length <= skb_tail_pointer(skb)) { rssi = ev->data[ev->length]; @@ -5402,11 +5407,6 @@ static void hci_le_adv_report_evt(struct } ptr += sizeof(*ev) + ev->length + 1; - - if (ptr > (void *) skb_tail_pointer(skb) - sizeof(*ev)) { - bt_dev_err(hdev, "Malicious advertising data. Stopping processing"); - break; - } } hci_dev_unlock(hdev);