Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1441119rdb; Wed, 20 Sep 2023 09:09:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4TZDn25qEHw9XClAQVI5dMtMvz1KP646SQjY9pVQGKCHYh3o5q83NXMH4ma6vX+tguiY2 X-Received: by 2002:a05:6a00:1995:b0:68f:c9df:2ccb with SMTP id d21-20020a056a00199500b0068fc9df2ccbmr3212169pfl.1.1695226188136; Wed, 20 Sep 2023 09:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695226188; cv=none; d=google.com; s=arc-20160816; b=hZMXfealSgCa0gUOR1ewjFQk7daEfTdQ/leOxfAtuQnEMG65Gt19/1fXvb6p8rDlWl GZX5BavWwwrg6FSv9dzefDVxVkxmy9znKUYlbDIWNc+wNBvlQXEvw5h+QHHqEkDZdxGt I3obDXcnLgwK/3tRqXsYlQ7Ds5Kp6yxGSZ/F3SGDb6MTvgzyyOhc9alpTO/GO14FoB78 44Yt0lirX/GNwL+3ok3ZocHL671IC6AeDu5d9ojYFsdI8cc8zeg5jWVSs5LrT3rFgphV CT/D9lzq4d2h20UeHoVUMq0AKtJ5DNeJiEJagsns5VZ4BMibfiuK4nLaZLDR5W6p1/DJ B10Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7wjjHWWK7erfyG5RmuxsB6SmlZaf6G7QituWFcBP0dg=; fh=cDb+OBRfnjRhAYAfA7aQFYWAFNWpmB7foPz5Xhgj4Gc=; b=m2a/d9354JAY3iq0f5HII0jk18E33AAJHTfAtJQMBe48v6CvPXQ3jkvve9zgQ3VmZ3 FPPVzb99YcvD6QomByWfZKAJw35i+5w4e4ajRDRujS+Ms7da50Iun8Nb/Hv7u8SXIHSx yCEG+Y0dn65sbLyUzZf4gMzbfWzKex5cqVYSAu8InQhjabhUXNjPylCwAijOi9UMXkZd pEx47N1RicGgvrHoqWzQjXMGbvv1hVtGAhe/EjzjwSfdT4HdctewONg5BG2AL5So2DDf ulCzWuwaLmKvdfOTG8yF0OgJwAYZSH8R4AQOFA5TIG9kpz2GarQShqcm0fOi2m1YB58N gomA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cz7PiaX6; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ch13-20020a056a00288d00b00689f1186cfdsi12075442pfb.29.2023.09.20.09.09.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 09:09:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cz7PiaX6; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0CCB1824630D; Wed, 20 Sep 2023 08:32:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234792AbjITPcM (ORCPT + 99 others); Wed, 20 Sep 2023 11:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236593AbjITPcL (ORCPT ); Wed, 20 Sep 2023 11:32:11 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A61ACF for ; Wed, 20 Sep 2023 08:32:05 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-403012f276dso75515475e9.0 for ; Wed, 20 Sep 2023 08:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695223923; x=1695828723; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7wjjHWWK7erfyG5RmuxsB6SmlZaf6G7QituWFcBP0dg=; b=cz7PiaX6gtTpTjrVmSzKB17W53eZyefkAHbqeOFDiwWnKoNt8Kg36D6DaGrBzCAh3S uh6jvK/qY3k398Os25xPHMu8mrQKm8yNtXBF/GdARofhCa9HJ3sZxsEQYZbH6cm6xRkS aK5d/qlER0LUdXaCrZpBVyKI+rl7MArJUNotgEFvNZOxs7Y2vNx88dWmzU5wJk1wZNDK MLawSPguoJySgj2o3sy+MN7BNAAIIkWcalanA2KuGGsct1FTHfUHhAa8xktgwNSbIOQ4 xfu9m+IT7Ln06JV2pT1TdTl0jNalXQLCzQxHqj5qAHXcxnAoWHG8AOkMdRoD1Rul1FuI ZFmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695223923; x=1695828723; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7wjjHWWK7erfyG5RmuxsB6SmlZaf6G7QituWFcBP0dg=; b=qQdbwQn6Vz3Es/OPFW4ivRYxIY+QnRQ3zE1tmX5SESjp35YgWl3YTimvdgNcR/hNuH y9MvGHV1eC+EJyXddDnbMlj/fRvxXEUb40MlYwoe6GE/StEOo0tJzo4PSZn1HqoVbqTr Tmuqpnc09Vg9K5Cf3ezJc+Wu++xpHE6NpOcvoF/ZBs7PAT58H/m70dE+05rknsgFqO6u rB+/7Ejqtkwb3UM0EayaTIV8/KEvxA9zPJdX8MJWezxvEpRDqFCVcb/Jx2gLgDd/nlyT EreGuOdlqezMAO+Js49ak6bOrghsXXEZIb9tLBmDF8im/YqYpM+f1au4z4PPpjKbUJHV kfIQ== X-Gm-Message-State: AOJu0YzAlSjnEisgFzhoE37sZnYi0Qr0sERpoOEG2OZcKHkRrUtWCNq0 FiKwqOSAn1/N6YrMm4/Lbh18OKYVM18= X-Received: by 2002:a7b:ce18:0:b0:400:f6f2:66b9 with SMTP id m24-20020a7bce18000000b00400f6f266b9mr2770937wmc.12.1695223923201; Wed, 20 Sep 2023 08:32:03 -0700 (PDT) Received: from localhost.localdomain (46.205.192.105.nat.ftth.dynamic.t-mobile.pl. [46.205.192.105]) by smtp.gmail.com with ESMTPSA id k22-20020a05600c0b5600b003fe601a7d46sm2268133wmr.45.2023.09.20.08.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:31:49 -0700 (PDT) From: Arkadiusz Bokowy To: linux-bluetooth@vger.kernel.org Cc: Arkadiusz Bokowy Subject: [PATCH BlueZ] vhci: Check whether vhci open setup succeeded Date: Wed, 20 Sep 2023 17:30:08 +0200 Message-Id: <20230920153008.967330-2-arkadiusz.bokowy@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230920153008.967330-1-arkadiusz.bokowy@gmail.com> References: <20230920153008.967330-1-arkadiusz.bokowy@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 20 Sep 2023 08:32:08 -0700 (PDT) Due to race condition in the vhci kernel driver, we might read not a vendor response packet, but a HCI reset command. This extra check will ensure that kernel driver behaves correctly. Otherwise, the HCI setup process will fail, because our controller will not respond to "missing" HCI reset command. In result the virtual HCI will be DOWN and without initialized Bluetooth address, e.g: > hciconfig hci2: Type: Primary Bus: Virtual BD Address: 00:AA:01:01:00:02 ACL MTU: 192:1 SCO MTU: 0:0 UP RUNNING RX bytes:0 acl:0 sco:0 events:66 errors:0 TX bytes:3086 acl:0 sco:0 commands:66 errors:0 hci1: Type: Primary Bus: Virtual BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0 DOWN RX bytes:0 acl:0 sco:0 events:0 errors:0 TX bytes:8 acl:0 sco:0 commands:1 errors:0 > dmesg [1754256.640122] Bluetooth: MGMT ver 1.22 [1754263.023806] Bluetooth: MGMT ver 1.22 [1754265.043775] Bluetooth: hci1: Opcode 0x c03 failed: -110 --- emulator/hciemu.c | 2 +- emulator/vhci.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/emulator/hciemu.c b/emulator/hciemu.c index 25874ded5..e53fec0a2 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -313,7 +313,7 @@ static struct hciemu_client *hciemu_client_new(struct hciemu *hciemu, if (!client) return NULL; - client->dev = btdev_create(hciemu->btdev_type, id++); + client->dev = btdev_create(hciemu->btdev_type, id); if (!client->dev) { free(client); return NULL; diff --git a/emulator/vhci.c b/emulator/vhci.c index 7b363009a..80e1825f3 100644 --- a/emulator/vhci.c +++ b/emulator/vhci.c @@ -122,14 +122,15 @@ struct vhci *vhci_open(uint8_t type) break; } - if (write(fd, &req, sizeof(req)) < 0) { + if (write(fd, &req, sizeof(req)) != sizeof(req)) { close(fd); return NULL; } memset(&rsp, 0, sizeof(rsp)); - if (read(fd, &rsp, sizeof(rsp)) < 0) { + if (read(fd, &rsp, sizeof(rsp)) != sizeof(rsp) || + !(rsp.pkt_type == HCI_VENDOR_PKT && rsp.opcode == req.opcode)) { close(fd); return NULL; } -- 2.39.2