Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5229755pxv; Wed, 28 Jul 2021 06:17:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/ewuqKQdA/zvirxrrGjiHktpGUzhT3k2BjxZ3+tYpelV+hsvAm3JYJpWpjGis0YKZL39s X-Received: by 2002:a05:6638:33a6:: with SMTP id h38mr26516661jav.130.1627478268265; Wed, 28 Jul 2021 06:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627478268; cv=none; d=google.com; s=arc-20160816; b=bKLJHLcPjzsCaAy0dIJgsTQo7IEeXIrekZggvZUu2hPtI2xJaqtLXDhY2O6IA2loFs hT60EmUWmwbLKpFSTQO3ZFuF4hH0emcF1FTSgb8hEUj3EN+/x83pG2nC5Qknlo72PMk3 ck8tQ7VK1cXqiri9sHy9ufOIHbp1z/Ydx1OvyWPwn+697qhdCjk2EtNW8IvIUqiSzVIH AM0Zv6/YVEF1ePQDPKHM3rXcbA6TkqMd1fd8vdCFnYb1FrckbTTspAonMRW+tXS6DkOC ND1BDOW55rPPM7MravD1rDh63WxKYeTemepe2Sh4XjeEjwpZRkOMSBL/B2fHZ/DQrjdB xUGw== 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=DL2MaMzk+eOHtADn15C9fhPVEM1UNggN3rQz3EprNuo=; b=quRtrL9KBO4+iumom73usaV9yWhlMJzD1IV5fgupwMJZC61OWnRb5ADZF03/Qvgdrp fCEZ9Lfh8dhSUifS3PXxUJdAvCiwSymKKBS4Pd+SYHjvjn9O5KSVXHTGWFiPy3VLV9yS l3nfTl5Mv5PBwcGGX+ZpzMPH/sEb6AwWba7V+nTdVXjyw2MmQp2R8hQvVuUZOCrao1j8 TUYW8kx3WsoR+CdnLdOt3QS/KMUkt0Iti0Lx3dF0tPQaugnH1OEHF0NiyOAbJNjiiT9+ c1m6r7gteCmMNEDVVXVKi0JOHxysp9kWJbG0MWyGNQCBD19Acts/ae+Ph/eC0a52gQMS f6ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UvVwgLLG; 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 l6si6526690ilg.44.2021.07.28.06.17.13; Wed, 28 Jul 2021 06:17:48 -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=UvVwgLLG; 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 S235260AbhG1NPr (ORCPT + 99 others); Wed, 28 Jul 2021 09:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235204AbhG1NPq (ORCPT ); Wed, 28 Jul 2021 09:15:46 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84FC0C061757 for ; Wed, 28 Jul 2021 06:15:44 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id hf7-20020a0562140e87b02902dc988b8675so1935502qvb.3 for ; Wed, 28 Jul 2021 06:15:44 -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=DL2MaMzk+eOHtADn15C9fhPVEM1UNggN3rQz3EprNuo=; b=UvVwgLLGuSf8WTxOLfrzFlirzPZFI7kajuwabmBftKk2/oIIKT7PMRId1QkEB+TncW 0I190KLwUNdIlTYJkW+eSv3nujzIsWs4JxwGzMQdtSdiDGN8yIJCcYQ4MlKYmT4LLu9Z vRYiQRmF4s6hJCAftfpG0dGhGd4YfiL8qOqXEv4Pk0NP1KgUwYhRTdWiStVub2yGWDPi bKKxpVZVdtl8XY4YZzWEcenXz37LHr03lWz+IVvqSxEzUEY8OKCmS9Z/N7aeE6TkNsFh JKQLZsosMnQLXvCaLb83HgM4wiGeeG6pbXtFf05+DpqisxH7yvgabtYSJLM4DW/sKqlH glLw== 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=DL2MaMzk+eOHtADn15C9fhPVEM1UNggN3rQz3EprNuo=; b=jn/MzYoOyYvkiu3Hiy82b0yaEm7Qlc1UFgqlf3nIRDQXXnPZO4XYeIfw0hmFjZXqPL zLnTW7JZ0y5XXNYj/nFbSnbBMW2HCuDYZvrgtFzrkHCbJLPa3PhhZLQAQMkfNFJHA9pC RMgOTWrwraiI5LRsIIg55/PkN+s9MDV2X3cO5gE424pMk7zH8KFFNGVl5d7atwSTrP2Z O/2O5OBJjEBFUq8OT3+VJbVRB1tzjHcQmEjlW4zKW4Un9iSzEhIP4bQYmWFlDPTw3ada b5ISTjcsY7Knuqa+6086smxv9er1DxfUwEInKJrVby41SHcaJ3Sr6rSz+lk0inC4PC7y G3FQ== X-Gm-Message-State: AOAM530ScCVX0A135UVCo4fwl3o1Sv1LDjxSkdpMHVPqIFF69dVVtdBj H7ElBfKOq79AMq0MGf5SixkHGHkg1eDiDW99RejQ53OwrHpH+Iyl1NaK9lCjRx+XPTY9LwqdpXa hg7jFatg/L1PmpiaRvSTWqKq52b5/1Y07vzabsr8a645magbiiPNfqgwwjXJOybju0ksh1pXcHO Rv5JgWyFb5rPY= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:9b6a:9d1f:2f3e:45de]) (user=howardchung job=sendgmr) by 2002:a05:6214:dab:: with SMTP id h11mr2771808qvh.21.1627478143430; Wed, 28 Jul 2021 06:15:43 -0700 (PDT) Date: Wed, 28 Jul 2021 21:15:17 +0800 In-Reply-To: <20210728131529.3310558-1-howardchung@google.com> Message-Id: <20210728211405.Bluez.v3.1.Ic71b1ed97538a06d02425ba502690bdab1c5d836@changeid> Mime-Version: 1.0 References: <20210728131529.3310558-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [Bluez PATCH v3 01/13] core: add is_allowed property in btd_service From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Yun-Hao Chung , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung This adds is_allowed property in btd_service. When is_allowed is set to false, calling btd_service_connect and service_accept will fail and the existing service connection gets disconnected. Reviewed-by: Miao-chen Chou --- Changes in v3: - Rename plugins/admin_policy.c -> plugins/admin.c - Use device_added callback in btd_adapter_driver instead of listen for dbus - Add authorization method in profiles/health/mcap.c and block incoming connections in adapter authorization function. Changes in v2: - Move bt_uuid_hash and bt_uuid_equal functions to adapter.c. - Modify the criteria to say a device is `Affected` from any-of-uuid to any-of-auto-connect-profile. - Remove the code to remove/reprobe disallowed/allowed profiles, instead, check if the service is allowed in bt_io_accept connect_cb. - Fix a typo in emit_property_change in plugin/admin_policy.c:set_service_allowlist - Instead of using device_state_cb, utilize D-BUS client to watch device added/removed. - Add a document in doc/ src/service.c | 39 +++++++++++++++++++++++++++++++++++++++ src/service.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/src/service.c b/src/service.c index 21a52762e..929d6c136 100644 --- a/src/service.c +++ b/src/service.c @@ -41,6 +41,7 @@ struct btd_service { void *user_data; btd_service_state_t state; int err; + bool is_allowed; }; struct service_state_callback { @@ -133,6 +134,7 @@ struct btd_service *service_create(struct btd_device *device, service->device = device; /* Weak ref */ service->profile = profile; service->state = BTD_SERVICE_STATE_UNAVAILABLE; + service->is_allowed = true; return service; } @@ -186,6 +188,18 @@ int service_accept(struct btd_service *service) if (!service->profile->accept) return -ENOSYS; + if (!service->is_allowed) { + info("service %s is not allowed", + service->profile->remote_uuid); + return -ECONNABORTED; + } + + if (!service->is_allowed) { + info("service %s is not allowed", + service->profile->remote_uuid); + return -ECONNABORTED; + } + err = service->profile->accept(service); if (!err) goto done; @@ -245,6 +259,12 @@ int btd_service_connect(struct btd_service *service) return -EBUSY; } + if (!service->is_allowed) { + info("service %s is not allowed", + service->profile->remote_uuid); + return -ECONNABORTED; + } + err = profile->connect(service); if (err == 0) { change_state(service, BTD_SERVICE_STATE_CONNECTING, 0); @@ -361,6 +381,25 @@ bool btd_service_remove_state_cb(unsigned int id) return false; } +void btd_service_set_allowed(struct btd_service *service, bool allowed) +{ + if (allowed == service->is_allowed) + return; + + service->is_allowed = allowed; + + if (!allowed && (service->state == BTD_SERVICE_STATE_CONNECTING || + service->state == BTD_SERVICE_STATE_CONNECTED)) { + btd_service_disconnect(service); + return; + } +} + +bool btd_service_is_allowed(struct btd_service *service) +{ + return service->is_allowed; +} + void btd_service_connecting_complete(struct btd_service *service, int err) { if (service->state != BTD_SERVICE_STATE_DISCONNECTED && diff --git a/src/service.h b/src/service.h index 88530cc17..5a2a02447 100644 --- a/src/service.h +++ b/src/service.h @@ -51,6 +51,8 @@ int btd_service_get_error(const struct btd_service *service); unsigned int btd_service_add_state_cb(btd_service_state_cb cb, void *user_data); bool btd_service_remove_state_cb(unsigned int id); +void btd_service_set_allowed(struct btd_service *service, bool allowed); +bool btd_service_is_allowed(struct btd_service *service); /* Functions used by profile implementation */ void btd_service_connecting_complete(struct btd_service *service, int err); -- 2.32.0.432.gabb21c7263-goog