Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp716856pxb; Fri, 14 Jan 2022 14:52:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWVrXJg14huq3ZoktN64ZUYsUTgTwTLkWfpctM4PbthJvXhOvrFfxB9MBJbKRm0P+Q9VQD X-Received: by 2002:a17:903:2451:b0:14a:8c5c:97fe with SMTP id l17-20020a170903245100b0014a8c5c97femr6813972pls.145.1642200772177; Fri, 14 Jan 2022 14:52:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642200772; cv=none; d=google.com; s=arc-20160816; b=r8vCBu6cOP92GIriveTL+FBNo1jV20Q0uTnGmeI+Ke6B74qabd8J3t2lWwQUIGPgTX dh7XK9GuJYOwDr0BrHxH0saDFGRIy6q2Xg/oOzfei9+xtm+2kw0dwYZ5nhKuXbxi32JA 4PLP389H0YUOJ3tcX1MX7VTBQRWfMIngF389+zzCgEM6H78S/INFYUUjU0nrrJp7V6pj MArxILQZymDe29FQ1O1UG/9zscO/Ct7cWg1K//DWONPlT2a5quSZEqM9HcX1sx22FbMX AP7VTvU1na0OY/M2l0ZJbfxiqgiHTYh3b0oTzd/4nwfnud3VYxWL9nTV1vdQ8ocWYKBd LzUg== 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=fiCkSY4NGiMiqOhJrxlmdzmoTadTB9Yx9a2FcjivUrI=; b=OpF9KUmamkVFx3rLI0oJXRi3Rti/knJXuXU62QvrPdNTmNnBmttFxZF4e5Oh7TrVrq f2lnUkoDX9nEZnh5Thgnz+8YJSrJFTDzbg99R3nYd7t31GEeVvPZHCWDAnScV7w4iDwv DHz9F1EHCkzvGHphEIRjkgK9YoDpJahvcV5gKwTacTdWzidrOFwCJN/I2bJwO7YjSQ2Q sJ5h415rn5jBlClz9mtiyoFh+2fUVYRQHZYCAF2PcVbj20CjI/g6PbeqSJBRarfJ+y/f GyKpRs9lY3SaHP5fPJEE4Z7SQmbat2h3swDR6eKHGfvE4uwD97RxbvahuLNj8jk4rWqh iz+A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si1705289pga.231.2022.01.14.14.52.40; Fri, 14 Jan 2022 14:52:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239445AbiANQoU (ORCPT + 99 others); Fri, 14 Jan 2022 11:44:20 -0500 Received: from giacobini.uberspace.de ([185.26.156.129]:52290 "EHLO giacobini.uberspace.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235625AbiANQoT (ORCPT ); Fri, 14 Jan 2022 11:44:19 -0500 Received: (qmail 16780 invoked by uid 990); 14 Jan 2022 16:44:17 -0000 Authentication-Results: giacobini.uberspace.de; auth=pass (plain) From: Soenke Huster To: 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 v3] Bluetooth: fix null ptr deref on hci_sync_conn_complete_evt Date: Fri, 14 Jan 2022 17:44:02 +0100 Message-Id: <20220114164401.330248-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(-3) R_MISSING_CHARSET(0.5) MIME_GOOD(-0.1) MID_CONTAINS_FROM(1) SUSPICIOUS_RECIPS(1.5) X-Rspamd-Score: -0.1 Received: from unknown (HELO unkown) (::1) by giacobini.uberspace.de (Haraka/2.8.28) with ESMTPSA; Fri, 14 Jan 2022 17:44:17 +0100 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This event is just specified 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 --- v3: Replace if with switch, reference spec 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index fc30f4c03d29..e47cde778b1c 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4661,6 +4661,19 @@ 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; + switch (ev->link_type) { + case SCO_LINK: + case ESCO_LINK: + break; + default: + /* As per Core 5.3 Vol 4 Part E 7.7.35 (p.2219), Link_Type + * for HCI_Synchronous_Connection_Complete is limited to + * either SCO or eSCO + */ + 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