Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4480932pxv; Tue, 20 Jul 2021 04:53:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrSJxM4lRuxa+48IgmYYoeGiMd5w8y8YqhnERSmBA2qGc3B+9ryrrNteu61H8jNKwQfw/g X-Received: by 2002:a02:9f8e:: with SMTP id a14mr26094605jam.55.1626782033823; Tue, 20 Jul 2021 04:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626782033; cv=none; d=google.com; s=arc-20160816; b=KZgNOFsk5qwLqHFWbnP6Zk8anPXx5T+4ykrYyQPEPh+RrknMumD3A9eX2evr44zzC/ 3mdzxJyE4gohSn/JVtaY9YTsk7J6BdFV+qK4OtBoUVomdxZECa4OqLl/bkfT/fuTCeUl uhLf1nQhNpbYnkaMDpvQkAu6Aufb+KoEgjidBSQT3E4LIQvKt2+fyO3CcDoveUY/RYTN FDyHeIv1wsS7E5I7AT4yNyDfJImTbeRSxEdR36V7MfOZni0SV1OAPdRvYxBrkKIEADCB x3lacX45t+RxsCPv042PLi2LQkfH4reZRDImRp4rKuyDyvmReTeDyO7UlEkXEgMlHHML ks1g== 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:mime-version:message-id:date :dkim-signature; bh=NM/Gq6o1W+zLvEmjAneDTgb5xEyVBdslvhpbgIMsBHM=; b=AoSTmCSwKLjmJVKgLvjRQ6GdPboINzB9qciTtewA/OEDwuYkuswhmEJrRYfvFZBmHx FsmaEc/EmB5i5nH2kGziprJQmRwNbHgqk9zEFxDWa9mXL5myh9UALcey0bXevGgoEk4K u+igIhcnjmj/Y6hP8S0S+Ztm+tWW77vF352Fcom3dL9Am1qCw47+5oF14K0zXuxGrL9d mMALkKpqAOF5Hs+3gk4cp37GGfifiLeQqmdAbxjmyEnk5ElJNiyPVyoGnmliCHG5l0Hx fTr0oZOv8cGwpNpDYfQhehvtk/cQnYzK+/+zzsxJQ8PwkYVY/egqetz4czJxmyQ8rFmg 4+2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IhN9rRZo; 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 x3si24061832ion.71.2021.07.20.04.53.23; Tue, 20 Jul 2021 04:53:53 -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=IhN9rRZo; 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 S238004AbhGTLLa (ORCPT + 99 others); Tue, 20 Jul 2021 07:11:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237340AbhGTLLE (ORCPT ); Tue, 20 Jul 2021 07:11:04 -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 9DD78C061762 for ; Tue, 20 Jul 2021 04:51:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id q10-20020a056902150ab02905592911c932so30137743ybu.15 for ; Tue, 20 Jul 2021 04:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=NM/Gq6o1W+zLvEmjAneDTgb5xEyVBdslvhpbgIMsBHM=; b=IhN9rRZohQwAYAtkrUmARIx2FgvxUkhPNgNK3uogThD/bEAoNouJ8c+Uui3I9JKxqH s3R044IM6e3qEmunY9ClB7gfwaGsEZ5zCQlHAWB6ArIG6M4Uxxs7XKzx/9cHwCsu788H CVTw0/ZUl0pTVyXpVtj9c9+1le39358Met3Z5KXLDOlQhOOehKX7Rx4vTR7xu+rtzlsu yVl9x4i914mXJ/hFvfxIw0jt+wwyad14Ptp6oDgdvLJCDQGEENVcf/x1pHYnlmR9eAln xSkoXOC/MoXLdS7t+QgCgeFaOJnAegkYg3SS7gxGqkohVU370+UOc+Oya0dV8KzVmaC+ TVrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=NM/Gq6o1W+zLvEmjAneDTgb5xEyVBdslvhpbgIMsBHM=; b=sqPTzyWDPZT2g9hXh09Wvv6GMK29J0Ql7UpbuCSu3UdmarN+l3T0NdZXDUCJ0fNfj6 EDjdPp5ElXTmzYJZ+y0CbF5sjCtiCgRkcJWGn2KmZLssKpoyY0bRdMZSMqUcJlybgGab AfwjCIOdN/0oyCSVznso/uGXd/N22DP+WSo2iVV1smqP3BKHlejKBhHpgkxBQyi2WoaM Al7L9wEVyR9fGThYDNdxgzc14H1Qu0JupEWzFAxmC/8ALN2JmLe+3pqj8Xrau5d20jDA Ax80mUIcw4N7qLy9SemQNmIoVuu8bjf3EYK/WwWkyxQOCUyZH0TP6v5C9wCc3xocXaTT ZjdA== X-Gm-Message-State: AOAM530ekZUAGVYS5rxvsLMn1ebozRHGR868WiYkiW5boKF1Joc/C5TY doU06L+FKgMNmGwnK6FaHHxaRDMMTZl2/JlsTKDfJOnq6BdCbKxP0jPGDcf60nfgQxBabZDthZ2 +g5LF5KAopscEeJPEiEQtMj335Mk4LQgYTq50XkTnnA21rLoyx7/FqPfmD1g7wy1dxN9SdckDaO 4fsSe4gFEKU7Y= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:fefc:42bc:f2d9:7140]) (user=howardchung job=sendgmr) by 2002:a25:ba0f:: with SMTP id t15mr36588174ybg.15.1626781901756; Tue, 20 Jul 2021 04:51:41 -0700 (PDT) Date: Tue, 20 Jul 2021 19:51:37 +0800 Message-Id: <20210720195130.Bluez.v1.1.Ib24a67a8a849f311d5213f83eaac3cfbc54b7b58@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog Subject: [Bluez PATCH v1] core: fix a possible crash when removing devices 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 In probe_service, if the service already exists in device->services, it returns the service. This might cause dev_probe and device_probe_profile to add a duplicate service into device->services. When removing the device, a double-free error might occur. This patch changes the logic of probe_service so that the same service will not be added to a device. --- Hi maintainers, This was originally found by removing/reprobing profiles in admin_policy plugin. Since we are going to adopt the other way to block incoming connection, this patch is no longer causing any issue, but I think it is still nice to have to prevent potential crashes. Thanks, Howard src/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index faf07ba22270..b29aa195d19b 100644 --- a/src/device.c +++ b/src/device.c @@ -4624,8 +4624,11 @@ static struct btd_service *probe_service(struct btd_device *device, return NULL; l = find_service_with_profile(device->services, profile); + /* If the service already exists, return NULL so that it won't be added + * to the device->services. + */ if (l) - return l->data; + return NULL; service = service_create(device, profile); -- 2.32.0.402.g57bb445576-goog