Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9184936pxu; Mon, 28 Dec 2020 08:42:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3FfBp2mKjFpamtokgIzI4j4v65xxfZdwgp2n+RLSvK8LWXS8wYBn2RTH2j4nkKqgNGH8N X-Received: by 2002:a17:907:204b:: with SMTP id pg11mr43648000ejb.192.1609173747060; Mon, 28 Dec 2020 08:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173747; cv=none; d=google.com; s=arc-20160816; b=gv5eN0jbmqiShTmlsku5DFGFg8injzS9vdxFNXR+jXrEg+LMY1Mk72VXGDEFIbFvmz WRpPerNQDTHV4Zb/a0D1XE3rmaKDC6c+858mTGcIBY++WF+ST/peErZQ1i89UVIogKvH fVFoljPW7F2/PxcZ/6d4JbGUTsHJK81OIfMcX628RSfzBpgRqT4PnrbB7mTUBD1omI/y k10G72SOgxoTWs1zYfi8Cb0eLGGJztZ9XLvzO/W0l1b6jxDPkk3dhaPsrOlr8uOkEcK9 zg0NMLBp1/469OB7AmVPYIepumm9/YKRFsmoeMpxphJi2juw6so65oR+Rqi1m2oHr0tV rL3Q== 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=RbUSH2dthjWXNp/AAEFqvEXlV4hYeJ9mMki920+UeaY=; b=AqKvX4zbhv2ZuhJYGWeo9WKCtEeVxYc5j1gqpDCuh9Zt54DAeLWC1uJeYniSGEDiVw 70/A8fDF4r5mH8Xf/LRBM6xElYk7SBSpk++MqJu6Z610kWUOwBRvoGEZwyJmjWnUPU/2 qzUrFGhcRK+rTuxs65g7gt5Fif3X8qaLSVzazPSctV+LpoByXORm8fiB9/GmxgvFOyaP vIf3Apwp/vKkDNVP7UB432LkX4eNv3x2AaSXiDZet/4D2A7e1BuP/xaiJXJDkFRSm2Zn R7zKEJQmhYU4lhiRKHcR7NN432f9Dtuh+lLQ1VaZNymdpoiu6ONN55prfDzfAJOVdKIh as5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YCCzoVPK; 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 r2si20849761eds.180.2020.12.28.08.42.04; Mon, 28 Dec 2020 08:42:27 -0800 (PST) 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=YCCzoVPK; 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 S1730340AbgL1Qiq (ORCPT + 99 others); Mon, 28 Dec 2020 11:38:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:57586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729743AbgL1NBN (ORCPT ); Mon, 28 Dec 2020 08:01:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6267122A84; Mon, 28 Dec 2020 13:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160433; bh=jWWecCvtWSloin1KklTI0i6RRAy8XgIXFUC1cw82+x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YCCzoVPKgcyb8ftO2AT8zeNUqnOkr7gP8nJbx8RPrGynuBkEOxmJbZ+YUT1z2CIPM VTJ5qYh8VLNROxpTY+UTiAocASBDPcsKFnpWV16C22Cur/Y7a4WBUgDwr0lSM7XWBe DOkKJsJVsPkXzNLgQiMYiwHEesGFVTyY4aFRwxcM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peilin Ye , Marcel Holtmann , syzbot+24ebd650e20bd263ca01@syzkaller.appspotmail.com Subject: [PATCH 4.9 049/175] Bluetooth: Fix slab-out-of-bounds read in hci_le_direct_adv_report_evt() Date: Mon, 28 Dec 2020 13:48:22 +0100 Message-Id: <20201228124855.632869877@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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: Peilin Ye commit f7e0e8b2f1b0a09b527885babda3e912ba820798 upstream. `num_reports` is not being properly checked. A malformed event packet with a large `num_reports` number makes hci_le_direct_adv_report_evt() read out of bounds. Fix it. Cc: stable@vger.kernel.org Fixes: 2f010b55884e ("Bluetooth: Add support for handling LE Direct Advertising Report events") Reported-and-tested-by: syzbot+24ebd650e20bd263ca01@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=24ebd650e20bd263ca01 Signed-off-by: Peilin Ye Signed-off-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/hci_event.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -5141,20 +5141,18 @@ static void hci_le_direct_adv_report_evt struct sk_buff *skb) { u8 num_reports = skb->data[0]; - void *ptr = &skb->data[1]; + struct hci_ev_le_direct_adv_info *ev = (void *)&skb->data[1]; - hci_dev_lock(hdev); + if (!num_reports || skb->len < num_reports * sizeof(*ev) + 1) + return; - while (num_reports--) { - struct hci_ev_le_direct_adv_info *ev = ptr; + hci_dev_lock(hdev); + for (; num_reports; num_reports--, ev++) process_adv_report(hdev, ev->evt_type, &ev->bdaddr, ev->bdaddr_type, &ev->direct_addr, ev->direct_addr_type, ev->rssi, NULL, 0); - ptr += sizeof(*ev); - } - hci_dev_unlock(hdev); }