Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5764504pxv; Wed, 28 Jul 2021 20:14:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywbuk4DIjic6yC9+tqEREk093IlRF45U9nWTsrhelhi4IRKatUtLsG7TtNKd4tAO8Ei2Wr X-Received: by 2002:a05:6638:378b:: with SMTP id w11mr8873jal.31.1627528475153; Wed, 28 Jul 2021 20:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627528475; cv=none; d=google.com; s=arc-20160816; b=RpN9IQa5YqK6M32abhR7P1UBjo7iBKlsa6qQ+IasJHPyHZPRThu7O8rEMRkgOElNBC Q315AXTYhVpeR6sXv77+V2i1FLoBiOsa3GYAC6RWvzlfAwwz//arjIdYmqbA1mycrz6g JiEoUifwB8qKgDwTkbAufL8blEtwvf06ZB2tg32nnpdq3t8MGOXUGTQqGosSzNPLDqH3 oMlt0z+6T9yvS4kGvoQcCy+0mDLE2mfLCwYYWVwJepWx3ioMmg96+LI3x0S3oU8xrCOA yBF/jlkiywHQsPElMTZkZ8j4Wv38qufocdvVwWWHUdjSJrBr1TUsZpdMNqfBNXX1QmK5 +rYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=G5IamTG342V1nmPJafUnZ8zf6U37HSJ+F3rr7RIrFY8=; b=LMX6odOfhVj2ez1+TIbJYZ56CKyN1kQGaxmfo6c5tu6lY+5k2ctNDOFpBgE1S1ePr8 5G5ewWHIPrXhLLevoLUXGRxHdU6T01G+7bTTanVceodOBFC1+6YandDm1EYKG9WWvPMs de+YfogjORX3BLqwkvMe1M5/kNcdyxK4N06oRmVb+KwWMwEWV5g/dAzZBnV/+tqjcrNK lMC2M0mb9WsksrZCy0HLwL/rux4eJZGC+AT+1xlglVUUnrHTzzw9xjEdGK9vIam7g7d/ pakxeXnGSUlRS+qStRt/5fTzSTYtlrXrKoXcKPhyyLxcjI/cNvI7fEAcwCX7GhaK2tIR +C5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="TZ3q/cgA"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si2003559jaj.89.2021.07.28.20.14.24; Wed, 28 Jul 2021 20:14:35 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b="TZ3q/cgA"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233559AbhG2DNy (ORCPT + 99 others); Wed, 28 Jul 2021 23:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233586AbhG2DNt (ORCPT ); Wed, 28 Jul 2021 23:13:49 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24D02C0613C1 for ; Wed, 28 Jul 2021 20:13:45 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id g11-20020a25ae4b0000b02905792fb55b0bso5361914ybe.9 for ; Wed, 28 Jul 2021 20:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=G5IamTG342V1nmPJafUnZ8zf6U37HSJ+F3rr7RIrFY8=; b=TZ3q/cgA8wCUkrUtapDLp0xgmERoagirdoL3gCKQ/dbfYK1xEzzKy1SpW5gemKkyPe nPKL2y8JfUIbfJep4QXwAzjZuO3MWbQRios0Ww9EQaTf34xwtuX1llahDNwp8+tWF8e7 rQnOde9lOGBmNY7vP6ig2llNoxr5ujbICAVf22ggXIm1k6XT9BBDfuH3TOzwysmRFkZV QwUk242GFb1OIYwQOJ4hWPO3FzP53Cp7aSCSUij78Ifin2TXiPHOwT7mNI6bxmKWbIZl zo6AdPTWPrHBLLkzVl9oWqBGUX/FwPg0FRZTlmjTwUiOD6E7rMl861Z6PalX719i2a+P d4QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=G5IamTG342V1nmPJafUnZ8zf6U37HSJ+F3rr7RIrFY8=; b=rXbvJV/y9h8hpAYM6HwwH2qX4xdbuHmUQQOIc5eapsK2xq/0GF9oUG10Auqh49aAuV o11toHa37o+ebJSoicydbbT0q3L3TkJWcLN9Lo3unKwlZLXYS0vkf2Fvjw/EKulfa/Oq +0fS/mFeIoDir1Vdrw51oX52pSZDHOJzHAQQcW3ycVBnyNi7SScjllcfwz17//NPgq7x lzFXpdB9AfMXRQ4dAbTXnpN7t2Q2jRSoJXjVuXxjMYnyqZ0+5SLv0P98rylp7XhyqrQl ulh2frXoYj9vZ4Dhbddo3cBSzh5ms1rs83Bdv4d1/pJcbb1aeQcGSfL7oQoKDYiwCCUD Z7Ew== X-Gm-Message-State: AOAM532Gw9lXYvz2e3zVFIrQpD1vdMvmkyG3selGnJrHplYJH74ge9AD SHJOUQgFzYYnsPzK3FNczXXizTKj6Z+QivlPazgHeU1h/EVIdx6qGYZDE5FeJbvqzz/YROo3nNb sGRdpUYrFpXIJAX8tvzomSW+PSAuZKnB5ci6saOkvVG5RpEA/e4ukoPFWj1M0CMVQ7te9tyTJid +YU4UHZ/wGJmE= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ff72:1420:4502:fdaf]) (user=howardchung job=sendgmr) by 2002:a25:28a:: with SMTP id 132mr4147120ybc.458.1627528424277; Wed, 28 Jul 2021 20:13:44 -0700 (PDT) Date: Thu, 29 Jul 2021 11:12:50 +0800 In-Reply-To: <20210729031258.3391756-1-howardchung@google.com> Message-Id: <20210729110956.Bluez.v4.4.Ia4dc489979e4bf7ffa3421199b1b9fd8d7f00bbc@changeid> Mime-Version: 1.0 References: <20210729031258.3391756-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v4 04/13] core: block not allowed UUID connect in auth From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Yun-Hao Chung Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung This ensures any incoming profile connection will be blocked if its UUID is not allowed by the following assumption: 1. Each system profile asks adapter authorization when seeing a incoming connection. 2. Each external profile checks if its UUID is allowed by adapter when seeing a incoming connection. --- The following test steps were performed after enabling admin plugin: 1. Set ServiceAllowList to ["1234"]. 2. Turn on a paired classic keyboard. Verify it can not be connected. 3. Set ServiceAllowList to ["1800","1801","180A","180F","1812"] 4. Turn off and turn on the keyboard. Verift it can be connected. (no changes since v1) src/adapter.c | 5 +++++ src/profile.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index c7fe27d19a5d..6c8096147bdd 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -7118,6 +7118,11 @@ static gboolean process_auth_queue(gpointer user_data) if (auth->svc_id > 0) return FALSE; + if (!btd_adapter_is_uuid_allowed(adapter, auth->uuid)) { + auth->cb(&err, auth->user_data); + goto next; + } + if (device_is_trusted(device) == TRUE) { auth->cb(NULL, auth->user_data); goto next; diff --git a/src/profile.c b/src/profile.c index 60d17b6ae657..58500c74746d 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1249,6 +1249,11 @@ static void ext_confirm(GIOChannel *io, gpointer user_data) DBG("incoming connect from %s", addr); + if (btd_adapter_is_uuid_allowed(adapter_find(&src), uuid)) { + info("UUID %s is not allowed. Igoring the connection", uuid); + return; + } + conn = create_conn(server, io, &src, &dst); if (conn == NULL) return; @@ -1272,6 +1277,7 @@ static void ext_direct_connect(GIOChannel *io, GError *err, gpointer user_data) struct ext_profile *ext = server->ext; GError *gerr = NULL; struct ext_io *conn; + const char *uuid = ext->service ? ext->service : ext->uuid; bdaddr_t src, dst; bt_io_get(io, &gerr, @@ -1285,6 +1291,12 @@ static void ext_direct_connect(GIOChannel *io, GError *err, gpointer user_data) return; } + if (btd_adapter_is_uuid_allowed(adapter_find(&src), ext->uuid)) { + info("UUID %s is not allowed. Igoring the connection", + ext->uuid); + return; + } + conn = create_conn(server, io, &src, &dst); if (conn == NULL) return; -- 2.32.0.554.ge1b32706d8-goog