Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5931628pxv; Thu, 29 Jul 2021 01:58:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLBU8o22dg2MRM4o8Zo0Zi81nPiD6UNoBr6D2cb3ERViQ3nxBFZQj1Cs/BDe5biPA0ht8/ X-Received: by 2002:a92:7f0f:: with SMTP id a15mr2938412ild.245.1627549117122; Thu, 29 Jul 2021 01:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627549117; cv=none; d=google.com; s=arc-20160816; b=O7xo8VO66ORLayMqzHD+gIMofXospu0kfdq1fP4pnbdQfnLd+9sEa1bC8+jgO970Ic VDRB9RxAb43CaeoPi9PfQOz5/uXeCKx2i44KTVUMZzsW8DR/3NB284m2SdDBBepz/xLN 9/mnp1uXXVvRMUzF5qV8uWx9FXxx+5QTtx6yGauCcq+kJl7B/U4kwx2rJhj67jSXPpGu MhNzlPIjxdYc3USSfRdU6+2dZ9k6tEWhRXf9DRp+nH+wMHgzl9L/zR/ZzuZDWGpLn37R oVBsEnudLZ/SbaF89fcpAEWEnzPUTYdNcYDXun/mv5JxOyzhQRt7rbltZc5VKqiAh3b7 zwFg== 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=L6lNNaSX6qQORZqT2VoBUMM9LUS7LaDIzlSN+vZ3p6I=; b=WQ5n/Z99Q81UnEmFQY4OI64F0zwQmJkRZyIxic+HdzVl/Dja2jILsbg5Q4GqbWSrTM g8BOHi41AdYdCf8mbP5iWwmQo+69Y3ISYRBtAxHkfUGYdWsCwcd2NYjDHrsf9wk5fErm bXThy/fa4e/4YuKZxbzaZ7GHeWY6Qo+XpBdtph7kyuhNkRRIHYM6fZgRiV+eo++4h1qK jqsoxq1sHXAJ5FSLCo1bfWDlUdR+nHZCpLZ9lyS/DrFDTAaxEuA8+PUk0SesX/XblAln 4tdlJwbA5s9z0Iv0rtpcX9BBTG/Iq6lWQs5VPNOjQQDfHhDAmbW4V8JDaTJuQLwIS5/E S/EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=c73T+KCV; 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 m1si3357677ilu.13.2021.07.29.01.58.06; Thu, 29 Jul 2021 01:58:37 -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=c73T+KCV; 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 S235124AbhG2I5W (ORCPT + 99 others); Thu, 29 Jul 2021 04:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235244AbhG2I5V (ORCPT ); Thu, 29 Jul 2021 04:57:21 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047A4C061757 for ; Thu, 29 Jul 2021 01:57:19 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id i15-20020a05620a150fb02903b960837cbfso3409415qkk.10 for ; Thu, 29 Jul 2021 01:57:18 -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=L6lNNaSX6qQORZqT2VoBUMM9LUS7LaDIzlSN+vZ3p6I=; b=c73T+KCVvuO348nhl1ZSt2/M1lCRZ8yIF2Ercba12KugbybD+4G1jn4sfxf9hAMgeU Ws+zf0wo2VHbdoZdJm0XrVLKlEbsjLbQ3ZaTvlZEjjHYEKL5BzipGPYds0N6eO+j8cPg /L4KI7EL7PsfgxFRIRF3DFIpHCHl8An/yHx9YEGtHkfvnVLaB9mcwUwVULs2hAeVpQ3y I0rC0JkXsWcUICD54b9Q0jDOWoUmcm+HocJ5d5R0zBeXu3Om8kvQPiFH7a55pSpBl+Xo u51BxWvMSVmhEek6T0OKerWg/swkOHWfAyG5cZMV74RLF83qTfqDaTRIJ4VxPiTvZGV2 I6KA== 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=L6lNNaSX6qQORZqT2VoBUMM9LUS7LaDIzlSN+vZ3p6I=; b=Z/apjt+tSO6rkDsRsUy5NMsd5GlJ0T1XuPLvlzSzG/zfpiJHXOj6oJ9uv1Dv5zlwtY LDCNAoEWL9Kq5XBblJKqX0+A9t4XNEtgDX8ePTw3Nl51tSDIDNUiZ+yDgk/C/zrHPCGr 1TAk0pehvUKVQWvX4Pa+66MXEpQfmDwatCB+WE35xXKIRNfwvjyzz++hS0e3RN55cId4 C8CIOPOctArL8ZwLlZQfbYAgQYSGKw69HLzYJxA6DLuIvMi6HoFr08TwL7o7Jm3j3mAw g+80Bq0tDLNv2mqj97t3f8xarjG5k9MzAExAH9NPfOb/b7Bxy8BwFxGkixxLwuL5iuro aeDQ== X-Gm-Message-State: AOAM531aAI+6fjFJxgu3DTONMdJOJQM9o/SSIRzvjRR9eI/Lh1P/8VRh 8C/sseuga13DSHujB/GVYwZRXnoYRrxX11qbSOcLjXqU2ymgrM9EYWfAt9E1gDYNFxBBecJcywF /LZm0e9QTDXAJ2PjUyGxzNoLeckGNOCoqhHZik7fX9ihNfaagiEM/qqDhMw/SyjWAU6hVfPbW4v QJ9eqcQhOo0SA= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ff72:1420:4502:fdaf]) (user=howardchung job=sendgmr) by 2002:a05:6214:178d:: with SMTP id ct13mr3945724qvb.22.1627549038116; Thu, 29 Jul 2021 01:57:18 -0700 (PDT) Date: Thu, 29 Jul 2021 16:56:42 +0800 In-Reply-To: <20210729085651.3600926-1-howardchung@google.com> Message-Id: <20210729165211.Bluez.v5.4.Ia4dc489979e4bf7ffa3421199b1b9fd8d7f00bbc@changeid> Mime-Version: 1.0 References: <20210729085651.3600926-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v5 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 | 11 +++++++++++ 2 files changed, 16 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..e1bebf1ee19c 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,11 @@ static void ext_direct_connect(GIOChannel *io, GError *err, gpointer user_data) return; } + 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; -- 2.32.0.554.ge1b32706d8-goog