Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp228991pxb; Thu, 13 Jan 2022 05:40:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjVvlYVBovroZocZBg7B+ADRXab3nYRCJ9APBgNAWUmBsKg6ebvkDgyPu3QCKKGsxBYDBd X-Received: by 2002:a17:907:7da5:: with SMTP id oz37mr3446469ejc.682.1642081208745; Thu, 13 Jan 2022 05:40:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642081208; cv=none; d=google.com; s=arc-20160816; b=vNAgnkK+n4cMOKLj49yhMRuIcN1SSeQn4H8AyQtPgDIZlLwgRClH83MPSl5kFB7Dq/ KG45P3TPex+o1t9EMaxDMGumfu8XRF6FwsVIVbdsOMCfsHvQEXLIrPZlBUgmSpesdAt6 yk4pYYvIWkTepkyynyB5oxcS9hpWHngP0Pjd5q5Ls+dppBsgCgS66S+nWv04pPrJVvMg NorHaAfk36s0woQLnuYUQDKAK8D/e5NZVPprPtJdBhMGqcLMqw4wE5BLleIizsaVIjBH 8SZbsQSMFSlrAb2XgWT2FT2TYM3EHl0/2wyOoqiyavWyEajI4whjqhUTWNHI4dS13NTr HAbg== 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 :message-id:date:subject:cc:to:from; bh=ZZVK/DOtDcj6mbwou1EEtcvS/ZNqYZWNLAHUpgOFKq4=; b=UAv4kJlXaebLqaDwX8qioIQiHEYHZaRmMlUh1h8uHsdk5Mbo8QG32qqUQQEEBzJOiB za79qPBAJJSYOjGiczyIHz5O0yj9lzREfqI3LeSOHBdlbVm93asUF/NFRWOzdV7qt/7b rb1LgqNs64HWBG/1+xqPUHeazWD0TtzyjUHorIAXptLnpEo3AeSeJpf7Byj6BK3gI2s0 uGeBJvtBqMI5lVBGuzvYzgbBHR+MdcIhzbaR1f69Pub/2sm5X81iXCHSgV0iCa68blta L5h7nv8gLgyeQ19yU/QkSUjJo2WYk0nbC5JK1GvlmoUpONt8xch3p7pnoY0MqtJ4ZdN2 yLvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp17si530658ejc.570.2022.01.13.05.39.26; Thu, 13 Jan 2022 05:40:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232289AbiAMJGH (ORCPT + 99 others); Thu, 13 Jan 2022 04:06:07 -0500 Received: from giacobini.uberspace.de ([185.26.156.129]:44602 "EHLO giacobini.uberspace.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232193AbiAMJGG (ORCPT ); Thu, 13 Jan 2022 04:06:06 -0500 Received: (qmail 1960 invoked by uid 990); 13 Jan 2022 09:06:04 -0000 Authentication-Results: giacobini.uberspace.de; auth=pass (plain) From: Soenke Huster To: me@eknoes.de, Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski Cc: Soenke Huster , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: fix null ptr deref on hci_sync_conn_complete_evt Date: Thu, 13 Jan 2022 10:05:52 +0100 Message-Id: <20220113090553.40362-1-soenke.huster@eknoes.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Bar: ++ X-Rspamd-Report: BAYES_HAM(-0.044325) R_MISSING_CHARSET(0.5) MIME_GOOD(-0.1) MID_CONTAINS_FROM(1) SUSPICIOUS_RECIPS(1.5) X-Rspamd-Score: 2.855674 Received: from unknown (HELO unkown) (::1) by giacobini.uberspace.de (Haraka/2.8.28) with ESMTPSA; Thu, 13 Jan 2022 10:06:04 +0100 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This event is specified just for SCO and eSCO link types. On the reception of a HCI_Synchronous_Connection_Complete for a BDADDR of an existing LE connection, LE link type and a status that triggers the second case of the packet processing a NULL pointer dereference happens, as conn->link is NULL. Signed-off-by: Soenke Huster --- I found this null pointer dereference while fuzzing bluetooth-next. On the described behaviour, a null ptr deref in line 4723 happens, as conn->link is NULL. According to the Core spec, Link_Type must be SCO or eSCO, all other values are reserved for future use. Checking that mitigates a null pointer dereference. net/bluetooth/hci_event.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index fc30f4c03d29..fc3f29d195d2 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4661,6 +4661,11 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data, struct hci_ev_sync_conn_complete *ev = data; struct hci_conn *conn; + if (ev->link_type != SCO_LINK || ev->link_type != ESCO_LINK) { + bt_dev_err(hdev, "Ignoring connect complete event for invalid link type"); + return; + } + bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); hci_dev_lock(hdev); -- 2.34.1