From patchwork Tue Feb 6 11:22:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 770681 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE43312DDBF for ; Tue, 6 Feb 2024 11:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218593; cv=none; b=VW1GaJNBArYkEkOFWQseamtrKibH9G43DF81Kfgj7feq7NFakZC+ei98ddRaNpmSJKs1N+01amdZbNcx0aKV8Xa9lzaAxACkwlR/qs13i27KVLLP7wlgA4lJ9nXVaGzV0qrQKIK7mYTYueGqgWetOmRSKQ5DSiMNFsx3QRLcWLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218593; c=relaxed/simple; bh=6rFVdGR+WN09ktXqbKSf6W23yNl7aba+/4WTYm61AyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j0gLcqVVDlAu0Tyl/uVNUlUCBLTk9Qu6aYZUy0oWIITmP2hAvBPYhk7uu7ukxAnOfj+oBOspJp9ingHCXuu43Gt9wlmZMrm630gkGBto6Dk4bl219xW8ewPYfdkxCOvkraDfz8pmkUX96fvs/Gyjw4x4AfNwQg28HAs6X1QmjJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl; spf=pass smtp.mailfrom=v0yd.nl; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TTgpg5sS8z9t4P; Tue, 6 Feb 2024 12:23:07 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= Subject: [PATCH BlueZ v2 1/4] mgmt-tester: Add a 0-entry to expect_hci_list lists Date: Tue, 6 Feb 2024 12:22:50 +0100 Message-ID: <20240206112253.76446-2-verdre@v0yd.nl> In-Reply-To: <20240206112253.76446-1-verdre@v0yd.nl> References: <20240206112253.76446-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4TTgpg5sS8z9t4P In add_expect_hci_list() we iterate through the entries of the expect_hci_list as long as there is an opcode, which means currently this relies on overflowing the buffer to detect the end of the list. This is not great and when running with address sanitizer, the out-of-bounds read gets detected and mgmt-tester aborts. Fix it by adding a trailing zero-entry to all those lists. --- tools/mgmt-tester.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index 7dfd1b0c7..7d884bbf6 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -8798,6 +8798,7 @@ static const struct hci_cmd_data multi_ext_adv_add_second_hci_cmds[] = { .len = sizeof(le_set_ext_adv_enable_inst_2), .param = le_set_ext_adv_enable_inst_2, }, + {}, }; static const struct generic_data multi_ext_advertising_add_second_2 = { @@ -8845,6 +8846,7 @@ static const struct hci_cmd_data multi_ext_adv_remove_adv_hci_cmds[] = { .len = sizeof(advertising_instance1_param), .param = advertising_instance1_param, }, + {}, }; static const struct generic_data multi_ext_advertising_remove = { @@ -8877,6 +8879,7 @@ static const struct hci_cmd_data multi_ext_adv_remove_all_adv_hci_cmds[] = { { .opcode = BT_HCI_CMD_LE_CLEAR_ADV_SETS, }, + {}, }; static const struct generic_data multi_ext_advertising_remove_all = { @@ -8913,6 +8916,7 @@ static const struct hci_cmd_data multi_ext_adv_add_2_advs_hci_cmds[] = { .len = sizeof(set_ext_adv_data_test1), .param = set_ext_adv_data_test1, }, + {}, }; static const struct generic_data multi_ext_advertising_add_no_power = { @@ -10378,6 +10382,7 @@ static const struct hci_cmd_data ll_privacy_add_device_3_hci_list[] = { .param = set_resolv_on_param, .len = sizeof(set_resolv_on_param), }, + {}, }; static const struct generic_data ll_privacy_add_device_3 = { @@ -10495,6 +10500,7 @@ static const struct hci_cmd_data ll_privacy_add_device_9_hci_list[] = { .len = sizeof(le_add_to_resolv_list_param), .param = le_add_to_resolv_list_param }, + {}, }; static const struct generic_data ll_privacy_add_device_9 = { @@ -10823,6 +10829,7 @@ static const struct hci_cmd_data ll_privacy_set_device_flags_1_hci_list[] = { .param = set_resolv_on_param, .len = sizeof(set_resolv_on_param), }, + {}, }; static const uint8_t device_flags_changed_params_1[] = { From patchwork Tue Feb 6 11:22:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jonas_Dre=C3=9Fler?= X-Patchwork-Id: 770680 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C3EA12DDBF for ; Tue, 6 Feb 2024 11:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218595; cv=none; b=KgW7d3jvGtC4HQtjz3BmrIrLr7O4dG4Q+SW0zH2ZWcroWKuNaHxGZHQmgxGKi+aIyifBtTN5o0Fe8nsVTyXQ8NsN/UpzURzI9xxb5fnA50S+UU9FJUIH5Ee8o2cWWnI8lauXP/BB8Dhw3ryMX4URdFORNC9B/P/TljbJUh+7tes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218595; c=relaxed/simple; bh=Sc8PWzUi9/KlVw/GmVTp9nSfoCrASQlbge540XJSr9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=du7FcE9WmlxWb9qoh12S03+1Y/7uoByblgCKHGjUKRvNftV+Ce7jga98zGuSFwB48x/eKVz5FpmnEzNTzLUy7cR7lgUkPfvxdH7yDQhJzPY7RP6xhBbCIL5DLOBODa9nn+GbDl+hAQhasx/47rM72DwaxK0bJvc2YWYZte0SA6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl; spf=pass smtp.mailfrom=v0yd.nl; arc=none smtp.client-ip=80.241.56.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TTgpk27q4z9ssx; Tue, 6 Feb 2024 12:23:10 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= To: linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= Subject: [PATCH BlueZ v2 3/4] emulator/btdev: Send page timeout after 5.12 secs delay Date: Tue, 6 Feb 2024 12:22:52 +0100 Message-ID: <20240206112253.76446-4-verdre@v0yd.nl> In-Reply-To: <20240206112253.76446-1-verdre@v0yd.nl> References: <20240206112253.76446-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Real bluetooth adapters wouldn't send the page timeout immediately when trying to page a device, instead it would take a few seconds. Try to behave more realistically in the emulator and send the page timeout after 5.12 seconds, which is the default page timeout. --- emulator/btdev.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 7b67e9430..6bf0f442b 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -1281,6 +1281,27 @@ static void conn_complete(struct btdev *btdev, send_event(btdev, BT_HCI_EVT_CONN_COMPLETE, &cc, sizeof(cc)); } +struct page_timeout_data { + struct btdev *btdev; + uint8_t bdaddr[6]; + unsigned int timeout_id; +}; + +static bool page_timeout(void *user_data) +{ + struct page_timeout_data *pt_data = user_data; + struct btdev *btdev = pt_data->btdev; + const uint8_t *bdaddr = pt_data->bdaddr; + + timeout_remove(pt_data->timeout_id); + pt_data->timeout_id = 0; + + conn_complete(btdev, bdaddr, BT_HCI_ERR_PAGE_TIMEOUT); + + free(pt_data); + return false; +} + static int cmd_create_conn_complete(struct btdev *dev, const void *data, uint8_t len) { @@ -1298,7 +1319,16 @@ static int cmd_create_conn_complete(struct btdev *dev, const void *data, send_event(remote, BT_HCI_EVT_CONN_REQUEST, &cr, sizeof(cr)); } else { - conn_complete(dev, cmd->bdaddr, BT_HCI_ERR_PAGE_TIMEOUT); + struct page_timeout_data *pt_data = + new0(struct page_timeout_data, 1); + + pt_data->btdev = dev; + memcpy(pt_data->bdaddr, cmd->bdaddr, 6); + + /* Send page timeout after 5.12 seconds to emulate real paging */ + pt_data->timeout_id = timeout_add(5120, + page_timeout, + pt_data, NULL); } return 0;