Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2711469pxv; Sun, 11 Jul 2021 23:29:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwONARl7s96ORcg3wI7NPhh+NuuKAhDce+qYTgi89H/bJOxwJ7o4UwNahPzHOjHjkaLlCDf X-Received: by 2002:a17:906:5399:: with SMTP id g25mr18018850ejo.418.1626071393368; Sun, 11 Jul 2021 23:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071393; cv=none; d=google.com; s=arc-20160816; b=b8kAe2J4MQGC7ErhebM2uTk3cPkIqpoHsk29ix4a+XOH1HzBsi5C0n6TuAaxVCAjDN 9bgr2SYpJjzpxKlKCaZW+4XYpnRsdhU1v99aNesElGUCY5Ffg/6wfdMvCmCXMbD+Vhs3 iCJPJdjYooewEzj06deoMoGLRAdEbY6SayFZM6Jf/6jd4Xm1ic18qJXgjbuGwvZxqYdw +w2x4cX9wxdDEgiBqBfZ0FGO+0XJ2f1RSLHqi37l3o9R/yAqzbO9x+NpP0Eji8cS6tF0 IYR0WTQbYnOChd5BATocyyG5V5oH7NXj5njRvrf/799GtKih6dqn8APM2MW5/3DY8/If 9trw== 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=48MEWetw/NbvcJmKvW2UoGMfMifpPi+ldOZAZG4Xd8o=; b=lBWQkGik0s/1uL1oZQf71UUVVjNidOnKera9cFMxg18h65a2LK7odAHKNfIInm2UcH L/jPPkBwltrZ+9utpSZJbBgaVxoRXDtKDwPiwLhm+WM0qaOctdFrpPff5jxCFAWZq5Rg 8g1GtxdKRdpYPlgTP9aKi2k9gMKEPc3eOPDHOHqsb/9svc3cD5SwAgXFZ1ZuRKDdFZIY DPeFun+eQwcYCOrSQw530cQGHZzCjEOT5/Ezj5VAsMw0cETUG3N1J9hwmcQ7RZyRET0B iUxFRIVvVLEpuUfp7uJkGLS1hlj2Q7pl2xnofWcGQiVQOjNAazxpu5rC2iJaRxoe/4sp PVWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2c4LhJiH; 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=pass (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 cw2si15697654ejc.730.2021.07.11.23.29.30; Sun, 11 Jul 2021 23:29:53 -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=@linuxfoundation.org header.s=korg header.b=2c4LhJiH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234782AbhGLGbS (ORCPT + 99 others); Mon, 12 Jul 2021 02:31:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:47906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235042AbhGLG1D (ORCPT ); Mon, 12 Jul 2021 02:27:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2BE446101E; Mon, 12 Jul 2021 06:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071027; bh=aMax2QxL36FMZKyKhmfeOHDAqkJTKNIaOl4iPz/PhRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2c4LhJiHDPbm/KK7rIKbApIeq4SEjIssFwKtg4kKfg0ZAUBJrYm2DkQmFgnWqbxwF F3WUX7lmlslff4IDt/NrJhOy3JppVBkvjluVKWUPWISXp0GXVMhpnN++MAwFOvbuPM Aw29Uoh99PZDj5PhvqqrR1pGjB0zGTqrHa34WrV8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.4 242/348] Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid Date: Mon, 12 Jul 2021 08:10:26 +0200 Message-Id: <20210712060734.612660521@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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 [ Upstream commit 799acb9347915bfe4eac0ff2345b468f0a1ca207 ] This fixes parsing of LTV entries when the length is 0. Found with: tools/mgmt-tester -s "Add Advertising - Success (ScRsp only)" Add Advertising - Success (ScRsp only) - run Sending Add Advertising (0x003e) Test condition added, total 1 [ 11.004577] ================================================================== [ 11.005292] BUG: KASAN: slab-out-of-bounds in tlv_data_is_valid+0x87/0xe0 [ 11.005984] Read of size 1 at addr ffff888002c695b0 by task mgmt-tester/87 [ 11.006711] [ 11.007176] [ 11.007429] Allocated by task 87: [ 11.008151] [ 11.008438] The buggy address belongs to the object at ffff888002c69580 [ 11.008438] which belongs to the cache kmalloc-64 of size 64 [ 11.010526] The buggy address is located 48 bytes inside of [ 11.010526] 64-byte region [ffff888002c69580, ffff888002c695c0) [ 11.012423] The buggy address belongs to the page: [ 11.013291] [ 11.013544] Memory state around the buggy address: [ 11.014359] ffff888002c69480: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc [ 11.015453] ffff888002c69500: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc [ 11.016232] >ffff888002c69580: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc [ 11.017010] ^ [ 11.017547] ffff888002c69600: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc [ 11.018296] ffff888002c69680: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc [ 11.019116] ================================================================== Fixes: 2bb36870e8cb2 ("Bluetooth: Unify advertising instance flags check") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/mgmt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 5fce559a61bf..db525321da1f 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -6461,6 +6461,9 @@ static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, for (i = 0, cur_len = 0; i < len; i += (cur_len + 1)) { cur_len = data[i]; + if (!cur_len) + continue; + if (data[i + 1] == EIR_FLAGS && (!is_adv_data || flags_managed(adv_flags))) return false; -- 2.30.2