Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp185675rdh; Tue, 13 Feb 2024 13:33:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWQzqDCsfSkm5z+e0DCDWvvyOtp3eNMk0fkQ96208YzHgayyn+Gf5sD3M2x/Jc01l7Nqhp/7utfaVg4DXiMGq82FAz2rm48QW7EGcmrnw== X-Google-Smtp-Source: AGHT+IE+5B1JlbSfZ25fPlmTcID9K5lgHIc1ZV1KG1G1sGWuiDB9RxkOYQTaCJYTuDTwhd+2/r1l X-Received: by 2002:a17:906:d28d:b0:a35:e7a1:66ec with SMTP id ay13-20020a170906d28d00b00a35e7a166ecmr405007ejb.44.1707859983180; Tue, 13 Feb 2024 13:33:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707859983; cv=pass; d=google.com; s=arc-20160816; b=tBzDb5f3DEzX2Pp+Co+31TJq8PLbMtBIacLZluvRmvVGgmaMRartSN3XCFZm6IKqKH 4EGuTqPTuAZS+yWMPuenltbjrrUvZXrT4R5nqRS5d8A+SBzQ4PQJ++WHw3AXk7JNHPr7 eHP7WGCUdGyUvKSMcMBZvHUN0VnmE1+PXxV5jGpioCmcqzdktcxTYF/ZNyEqJiRuZ/YV gTRTg9kVkd/WOeEShjVkWh+HroDKW4PrikMsM2S1M12za6TsIwDm5bI+oj4H6VzIEWEv NV1/vB4alNB8GNm3jfki7XDxczFLyJvGfyaJ5ruq8Jv98IVro7oLSnvshPX87Dl97TOG 5gRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=AydVQatpc9+8to7jbO+jHh71eCWXPgIKPFgG/Q9U0U4=; fh=xrUG4/zeo0YJewYVaqEjB6DkPFfM0OOzSxAnRvODwwk=; b=V7CPgUQ+xi0VR4QttlOyJZ9Vtn2Bf9Z3FL5Vt2D64VuNjg93hj1AVvDAeUpDODEUZO PRzp/UNpU5Sw2SunUIzoDaqKRwmtqd+BaswTe9KImtPvrZkgqLZjB8YLU2Ahnsv7Wiqj lMN8G4XbYYPwjSo3umlRbMJreTqbnYNmkW6MSHu7OsFffQp9+5KoSAE/lBc9cauhIp5m uTdR938XeG4kxOmqkGVQvmZZhdKsKzd3MSrvCHO1nTwz/cnIOFsFL7Zov6/Z6wDC8WPd paNWHIQD6AbymbKJy/wAhyApOAHBic6TNPWS5iKQU5KGFEhoiwZM5e9bHabiTJ26DK/I ryQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YxIGJJ56; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1848-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCVJMAp9idSl77BhnGYSHzs79M6qw3rxZfOTUfdVNqY3wTkpHJNdY8qcMBL+2T1DWxcyjndZK/mN8rEkJEjMXb2+AqPpyYCKzwuxWSTZ/w== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c9-20020a170906340900b00a3c194b2273si1636227ejb.126.2024.02.13.13.33.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:33:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YxIGJJ56; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1848-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3537C1F2552B for ; Tue, 13 Feb 2024 21:31:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87F4D61674; Tue, 13 Feb 2024 21:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YxIGJJ56" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FB4F61672 for ; Tue, 13 Feb 2024 21:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707859889; cv=none; b=EvcqPZAEXWF0kdUNb8PLQlpErVrvKTZPer+fDmjiCJNs+SYQJLsomLoqGp2oH250xNofVOT9T5ld8YFU7NMa0E0a9eySkxcbg9mPR06iJath6uGNX8Epf8H6rEhtPC0bItXnQzsrkOTk8B8PPl9NDiE1op2NTPUflmhqK1RvHXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707859889; c=relaxed/simple; bh=Uzmy8pdwHrS1wMUJmvCHzDf9sFS7r+uY2DSU/7JrNPg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PDX+wBtkBOsX5T3ykupZCv1evPQHyN85yJWH0LyjNMW0bvbme+MNJpijerhcHAeUF3akXqulGivxDFHKFPN8uvyqJvu4FjFPSB+zsuoYmO6atjAutM9C2aQDtWnk6J9IgIm/MR5OTBr1sA21Oyq5qHjbNSYTTdyAnQYgJyA3Y/k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YxIGJJ56; arc=none smtp.client-ip=209.85.221.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f173.google.com with SMTP id 71dfb90a1353d-4c03beb85f4so1292811e0c.3 for ; Tue, 13 Feb 2024 13:31:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707859886; x=1708464686; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=AydVQatpc9+8to7jbO+jHh71eCWXPgIKPFgG/Q9U0U4=; b=YxIGJJ56li1VEoNCZ2NaLQgowqZd/FvANeC7XABQpvME2QD/AHFwldBdHU/oWX09q0 XBnjL/ru1A2BY8vB4SdFVzkDJUnOsBzWy7OsqlPgzP5gyD9+UTWlAzTLS1TRrFOuag6a K04qKmLS6Kuxi6HDNUjO4nhNCIJW8YKte1pQw6B7VZx3v1BeRJ3y00DHBd1mlOUiIorI FknjJknw1DQ62EJQzDpbA6czdG/0xjWMZSpVNkvd/xRN8/R4Zm2E+kPY24mqT0TyJBzd fOzrbjTj2jsK7Y9z2GJMMIfRAuR78blGXNRSricGeamVyWOEzYTts4wvivZ3iHgHvTCo nB0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707859886; x=1708464686; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AydVQatpc9+8to7jbO+jHh71eCWXPgIKPFgG/Q9U0U4=; b=JvSS5eA9upB6lC5KdS+x2z7jevKgKdzChN7/RAHhfpQX3QwUHvkC3sVub+VPuupTju qyyTMaP3IzrdWF/OtS57o7lt0q503VvtaZD3Ka2RjpTk23UY2U9ZsQnqL8ixeYyFCrkT bCPjDMCLu60WqOISmZqbpBML8AVuIw/Y9nk8YKaCj03pRI/vQ4V9ZhqJiklbPOtWUpDF kLDmfFmpybDj4wxlv7ZjmuN/iOYukVmtiZUZAdIv2BBRppZC7Piln+ofPKz1way2GiJz 7lu6wcW3bVtbg0No2hyI2SfIF7z+zYR6cFq671gUx0vO2ppj1FBDzuSeD4Ef327wXcte R27A== X-Gm-Message-State: AOJu0YwgYD3cKd6rmEWEzkyea2TliwILNg71ys6luM6G/17G5rUAOahe aERgYOuIJZL7AOGMGd5tQFClf6znIobz+E7AfcV22/f+4x58JTrC4YyKdcLc X-Received: by 2002:a1f:c847:0:b0:4c0:1937:d29d with SMTP id y68-20020a1fc847000000b004c01937d29dmr945178vkf.6.1707859885979; Tue, 13 Feb 2024 13:31:25 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id z8-20020a056122148800b004c0149262dcsm1049837vkp.4.2024.02.13.13.31.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:31:24 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/3] Bluetooth: hci_conn: Fix UAF Write in __hci_acl_create_connection_sync Date: Tue, 13 Feb 2024 16:31:21 -0500 Message-ID: <20240213213123.403654-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz This fixes the UAF on __hci_acl_create_connection_sync caused by connection abortion, it uses the same logic as to LE_LINK which uses hci_cmd_sync_cancel to prevent the callback to run if the connection is abort prematurely. Reported-by: syzbot+3f0a39be7a2035700868@syzkaller.appspotmail.com Fixes: 456561ba8e49 ("Bluetooth: hci_conn: Only do ACL connections sequentially") Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_sync.h | 3 +-- net/bluetooth/hci_conn.c | 3 ++- net/bluetooth/hci_sync.c | 16 ++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h index 824660f8f30d..ed334c253ebc 100644 --- a/include/net/bluetooth/hci_sync.h +++ b/include/net/bluetooth/hci_sync.h @@ -139,5 +139,4 @@ int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle); int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle); -int hci_acl_create_connection_sync(struct hci_dev *hdev, - struct hci_conn *conn); +int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 8164502234c5..587eb27f374c 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1645,7 +1645,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, acl->auth_type = auth_type; acl->conn_timeout = timeout; - err = hci_acl_create_connection_sync(hdev, acl); + err = hci_connect_acl_sync(hdev, acl); if (err) { hci_conn_del(acl); return ERR_PTR(err); @@ -2942,6 +2942,7 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason) */ if (conn->state == BT_CONNECT && hdev->req_status == HCI_REQ_PEND) { switch (hci_skb_event(hdev->sent_cmd)) { + case HCI_EV_CONN_COMPLETE: case HCI_EV_LE_CONN_COMPLETE: case HCI_EV_LE_ENHANCED_CONN_COMPLETE: case HCI_EVT_LE_CIS_ESTABLISHED: diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 788a889210d8..e1fdcb3c2706 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -6493,13 +6493,18 @@ int hci_update_adv_data(struct hci_dev *hdev, u8 instance) UINT_PTR(instance), NULL); } -static int __hci_acl_create_connection_sync(struct hci_dev *hdev, void *data) +static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data) { - struct hci_conn *conn = data; + struct hci_conn *conn; + u16 handle = PTR_UINT(data); struct inquiry_entry *ie; struct hci_cp_create_conn cp; int err; + conn = hci_conn_hash_lookup_handle(hdev, handle); + if (!conn) + return 0; + /* Many controllers disallow HCI Create Connection while it is doing * HCI Inquiry. So we cancel the Inquiry first before issuing HCI Create * Connection. This may cause the MGMT discovering state to become false @@ -6556,9 +6561,8 @@ static int __hci_acl_create_connection_sync(struct hci_dev *hdev, void *data) return err; } -int hci_acl_create_connection_sync(struct hci_dev *hdev, - struct hci_conn *conn) +int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn) { - return hci_cmd_sync_queue(hdev, __hci_acl_create_connection_sync, - conn, NULL); + return hci_cmd_sync_queue(hdev, hci_acl_create_conn_sync, + UINT_PTR(conn->handle), NULL); } -- 2.43.0