Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp519980pxa; Fri, 21 Aug 2020 13:19:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJAWc1mLnuSoAG2zXGRaRKcMQN1/ZY9ByU7Qt8b2v7UtyMim6R+hkinwHKtIRQc5DV1OB+ X-Received: by 2002:a17:906:970e:: with SMTP id k14mr4227717ejx.417.1598041193577; Fri, 21 Aug 2020 13:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598041193; cv=none; d=google.com; s=arc-20160816; b=IQVFHODENLCs2pQGNA9RwpEV2On2QWsbYyTIGclzNuxivWLRh9tD1BDoLnCujK6L9J KKmql0YoIN98WtD63DANH+rdt78WuzI0oMVR9NyBDLxYvxq60h+b/czeR4P2lrvKSw2+ VTbjIreGq+VMfxvuvCKMApROwPUK2gBPXIWTx/ZQHNQ69bE1dWbFCCqpc6JlpVWn2JOH Pd6vyhJXqxVUaOrLNqP275YQtOG/SdxnP6U1Rpzubyk0fAo48wUemjkB7lxKI8NybbQO iDrer8KRViglie74wQGB2eRq6zIIOd56oQO6wlxr2J7E1u5rb8VbmCOyH0LxHt+wHwtb 2t+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oXHXAm4q+TYGHtxOfWBF8ZTfK3HEauWUVopzxyclBjk=; b=wvazs7zqxWEiM1zo0tooTxrzLRK+rjWLtjXh7001ulSXjkxKYzvwwi5d6MXmEiS4pB cLSK/O1XdjTHEFx+EHEEnsW8FfdIdZwS3m4gdo94ggH+3d2rzwRm8BHloMGFHiWxldXO dh/DCLEbxkCxKEe8iYoQxA0c0G04iNBYy61NFhRXXJCvFCieS6xxW8JsFxiD6CZaxZ48 yy1SSCfvyuNI7WCl1MND1QhTHn3ZhTeulr2r3jT6OhhQgo2pLCLfBQXMe+LXtBoFm4gB TI/ZkjY2OXuBwKeTo37WLEs6ywM/cp0HtedNQfMf7Ov4uT5uEP26D+JmpcxLrsko/ZWl 9z7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ofKZdUWG; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by29si1888015edb.452.2020.08.21.13.19.28; Fri, 21 Aug 2020 13:19: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=@gmail.com header.s=20161025 header.b=ofKZdUWG; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725804AbgHUUS4 (ORCPT + 99 others); Fri, 21 Aug 2020 16:18:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbgHUUSx (ORCPT ); Fri, 21 Aug 2020 16:18:53 -0400 Received: from mail-oo1-xc44.google.com (mail-oo1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AEEAC061574 for ; Fri, 21 Aug 2020 13:18:52 -0700 (PDT) Received: by mail-oo1-xc44.google.com with SMTP id z10so612155ooi.10 for ; Fri, 21 Aug 2020 13:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oXHXAm4q+TYGHtxOfWBF8ZTfK3HEauWUVopzxyclBjk=; b=ofKZdUWGys1UqhInXDEbybNl9qmjJ3EiTpl72sf9StQEA6gTwvEVJdkXUtZ62OVZ5i yYEfVTrhm6p5/z6EiRIWlJYbxnUylF4/NkfMuECEdOgXcv4VhtZHWIIq+gENmnlX3wV4 Q+0PZOCD6kBCJmFubuwz0+Njkh5QT4ixDKE4H4IQSm8eQowQHvFTW1CUoJeCk36RCyDR 9w9rzfc+6uKC+dDUyiq7RJrESjbdGp3lq2hBJT49xVdeMJEqCvYvioc3PUP5Jn1LoY47 lkpmcOwvnwtLzeTUSujA5iJDcfTcNIIlpMaz7ElHmVz/yGrxyH73h6nFlTs0U71S++r9 AHeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oXHXAm4q+TYGHtxOfWBF8ZTfK3HEauWUVopzxyclBjk=; b=IzDD2jBXRu0BlPq346BB+MEvAf1OQI2RPSXfNt4OzQFPXSc13SiO20FNbyCjYAWsqp uoQJ9Bfdc4NViEmLVOheH8RBEsYXmmb7fJ1s0mQj6PsKiIWI/Ep5Ftes5lB4E62Nj5fH KbJVW4GgiEd3kGIQ+tcqj97hQy5nKw5wZkazZwNnI+psKKtvg+NNSo/A+LaVVihmAQdR 0HmZNd9GkTUZfESTwJTxNgyUaC3BNCIQ4B12GPgIqFLY52cU/e/YmfD5nBKcRnVK8NiF b7JxotMOnqRLeeOJXNo4AI7JIJfoOEyv52d/AdDURQfw76EVPG76HsRajkcMnxRg0JEL U5cA== X-Gm-Message-State: AOAM533s9INyE8CcX8AD7egPwTEfqErR1qYgFoThMThddhlpMwLdNdBQ tCeAK3HxO82z+lOzvonkW4ap/eLrHA2/6X7CMwo= X-Received: by 2002:a4a:380b:: with SMTP id c11mr3392275ooa.17.1598041130670; Fri, 21 Aug 2020 13:18:50 -0700 (PDT) MIME-Version: 1.0 References: <20200821180106.21048-1-sonnysasaka@chromium.org> In-Reply-To: <20200821180106.21048-1-sonnysasaka@chromium.org> From: Luiz Augusto von Dentz Date: Fri, 21 Aug 2020 13:18:40 -0700 Message-ID: Subject: Re: [PATCH BlueZ v2] device: Fix race condition between device connection and disconnection To: Sonny Sasaka Cc: "linux-bluetooth@vger.kernel.org" , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Sonny, On Fri, Aug 21, 2020 at 11:04 AM Sonny Sasaka wrote: > > When Connect() is called and waiting for return, dev_disconnected may be > called due to MGMT_EV_DEVICE_DISCONNECTED event from kernel. In that > case reply to client that the connection failed otherwise the dbus > method will timeout because bluetoothd never replies. > > Tested with simulation of a lot of Connect() to bluetooth devices and > check that error is returned from bluetoothd rather than dbus timeout > when this race condition happens. > > Reviewed-by: Miao-chen Chou > > --- > src/device.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/src/device.c b/src/device.c > index 7b7808405..f59b6c1d0 100644 > --- a/src/device.c > +++ b/src/device.c > @@ -3006,6 +3006,7 @@ void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type) > void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) > { > struct bearer_state *state = get_state(device, bdaddr_type); > + DBusMessage *reply; > > if (!state->connected) > return; > @@ -3020,6 +3021,18 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) > device->disconn_timer = 0; > } > > + /* This could be executed while the client is waiting for Connect() but > + * att_connect_cb has not been invoked. > + * In that case reply the client that the connection failed. > + */ > + if (device->connect) { > + DBG("connection removed while Connect() is waiting reply"); > + reply = btd_error_failed(device->connect, "Disconnected early"); > + g_dbus_send_message(dbus_conn, reply); > + dbus_message_unref(device->connect); > + device->connect = NULL; > + } > + > while (device->disconnects) { > DBusMessage *msg = device->disconnects->data; > > -- > 2.26.2 > Applied, thanks. -- Luiz Augusto von Dentz