Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2481641pxa; Mon, 17 Aug 2020 10:38:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOxJgKSqY301iH5MFEzPekd3zvjXyqM5boUryoOrjiZrN7lj8UhPuM0NRJ3k9If4gRdIRn X-Received: by 2002:a05:6402:1a26:: with SMTP id be6mr15817208edb.162.1597685928344; Mon, 17 Aug 2020 10:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597685928; cv=none; d=google.com; s=arc-20160816; b=a4lxQEFmjhaYjpKuq6+7VhYGjI34laopSAcRO1jbMKczoT64IGRM0C1HfrIS85KiiT +CgWyCZMbjfIzeH+e80gfYalIoPk3xo/XXTbHy/rPKiaxMAW3lw1NXSyYPbooowRMJhl WEF6zwLkETgqf99TFd66NXG57zCQW9bcVdGtcotJ22Dga/Fju5o0fr0BrQOc+BXg+/Cn 5PRoGcVwBQodH7RbyeF83wSdavpDQAOiaBaobA2Zf/grSyjkV8QECfgGHdHTW+JY6G58 h2JD0s57mn1PXV7m3+yHpMIwmzA2afyY47yZieR5Q54U6ZUHOasa8XnAi/E9Yv8dVtZn H8mw== 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=7F2WR7ZiKtgV6Hbdw4w6WH+wyjdFEO/gsngLlaXW4JY=; b=pRIsl9eg9JV8bxn+1/LFsRubd+1ewsevo3vlr6tctkrNxoUf+Dq8JcLZs/AwyCoAwM 94rPkTLKAXG0teShH6w/8/abQ3U0hBBkzAUjD9w1ODi8jaDdSKVGhsWacpdkONRPGaAH BkJ+5ojL89pInzS+MPQOaQijaIv+tR8bc/MGCGO3Yj+t4DMqHIBfBc+0SyB6MNBOtbGs pWi0weBKy3WoVcf94aRwkpXwaBl1wXCDOCAJH97j06Uot9Tqo9MJzpozh/RP0PnUlbIi Vgo1I2fN1TmiIcuV8T47C991YBCp8cThjRTN/oXCSdilSx2KR86f33Ot48L+WXKyj1UI 4AWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="XRM/vWqp"; 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 ck8si11200680edb.82.2020.08.17.10.38.23; Mon, 17 Aug 2020 10:38: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=@gmail.com header.s=20161025 header.b="XRM/vWqp"; 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 S1730064AbgHQRfQ (ORCPT + 99 others); Mon, 17 Aug 2020 13:35:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730006AbgHQRfK (ORCPT ); Mon, 17 Aug 2020 13:35:10 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47936C061389 for ; Mon, 17 Aug 2020 10:35:09 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id k12so14091992otr.1 for ; Mon, 17 Aug 2020 10:35:09 -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=7F2WR7ZiKtgV6Hbdw4w6WH+wyjdFEO/gsngLlaXW4JY=; b=XRM/vWqpqTA4CCDPEqZlyxy7z/PUa113phRqL8bExZI7c32oenN0l/kRzs6Hn74QV/ Mze98FZsPg6js7Lmq2BLCLmuuG9kFk7jmoYRNQGKon3ZfPt85pxIR4D2uQ32SBDhRiWH kxFYzcw9Q+LZRwbI1sUnLO4wUoIHkv5cJrBUY31DB4FyCPK8GAFBQE/6fDAFy8bRE38J 2rN4+yljrR11nzSKmLT3frdOLKqQuoTCQv/Pbce66Z+dbrCIKG477dcwn8lH4106OEK5 wdyNeSU+XADxKdsxOc/5F4xfxMmig8dvCSnn1ytV2rX6uHIQPwLSN1SHTAf2StIcZCHI 9ZkQ== 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=7F2WR7ZiKtgV6Hbdw4w6WH+wyjdFEO/gsngLlaXW4JY=; b=cJoVIeZYaY44OOxJRmqjSKy4xmd6zBjuoijlkCvXls3KhI7+hSDDo0tY9KuJ825hDF Jppp6s9DQ5NjREIppup3SkyxrOBpcGUq5TGCnFKpPbyFFGp8bK806m0upRMySlgWb0UN 58SJ2PbueF9syOR/DQVWFTM5MrTL79CjXYm8uIU44pIGVhvUrdxCEVdcEGQWivoFF1rx Zg+buJBfvM9+j7DU9b4j+lIQALQjtDHV5RuMK05MWP5ElCfc6QFi5jWIKrLrboE13qvl 7YxUPAfoZ590Da01S/X/TVMrcI9fukGnTdUuhzCXYse8ES3/DTUAgMc1Jw/buBkgxAm9 Rh2A== X-Gm-Message-State: AOAM53104TNpSRjZiWuYQp/9OnG5vxwwu0AUf1MTCt3VZRxfQ4ocYuzp TP+Lk0ieQ7aZ0SmJPww/RPBre/XHn/92RgwjkFFUYnW1 X-Received: by 2002:a9d:6053:: with SMTP id v19mr11582739otj.362.1597685708584; Mon, 17 Aug 2020 10:35:08 -0700 (PDT) MIME-Version: 1.0 References: <20200814155807.Bluez.1.Ia90c97ad9ec0b51b7aaae1216864e8379c1470d5@changeid> In-Reply-To: <20200814155807.Bluez.1.Ia90c97ad9ec0b51b7aaae1216864e8379c1470d5@changeid> From: Luiz Augusto von Dentz Date: Mon, 17 Aug 2020 10:34:58 -0700 Message-ID: Subject: Re: [Bluez PATCH] advertising: Fix dbus response for over-advertising To: Daniel Winkler Cc: Simon Mikuda , "linux-bluetooth@vger.kernel.org" , ChromeOS Bluetooth Upstreaming , Sonny Sasaka 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 Daniel, On Fri, Aug 14, 2020 at 4:09 PM Daniel Winkler wrote: > > client_free would always send a dbus method_return to fix the case where > a request to Unregister occurred before the MGMT call returned. However, > in the code path where too many advertisements are registered, this > method_return prevents the failure from being sent properly. This patch > makes sure the reference to the register_advertisement DBusMessage is > not stored in the client structure until the end of > register_advertisement. This ensures that we only respond once, either > in register_advertisement or in client_free, not both. > > It also changes the dbus response in the fast unregister_advertisement > case from a method_return to a btd_error_failed, since the registration > was never allowed to complete, and thus was not successful. > > The patch was tested in the following ways: > > To verify it did not break the segfault fix in > caff2b48ca54bbc57b5da3f63317767489aa5b48, I repro'd the failure by > quickly unregistering after registering, and verified that the segfault > is still fixed with this change. > > Ran through our automated tests that register too many advertisements > and verify that the registration fails with the intended "Maximum > Advertisements Reached" error response. > > Reviewed-by: Sonny Sasaka > > --- > > src/advertising.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/src/advertising.c b/src/advertising.c > index 076d591b6..e5f25948d 100644 > --- a/src/advertising.c > +++ b/src/advertising.c > @@ -119,9 +119,13 @@ static void client_free(void *data) > } > > if (client->reg) { > - g_dbus_send_message(btd_get_dbus_connection(), > - dbus_message_new_method_return(client->reg)); > + DBusMessage *reply; > + > + reply = btd_error_failed(client->reg, > + "Failed to complete registration"); > + g_dbus_send_message(btd_get_dbus_connection(), reply); > dbus_message_unref(client->reg); > + client->reg = NULL; > } > > if (client->add_adv_id) > @@ -1152,8 +1156,6 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager, > g_dbus_client_set_proxy_handlers(client->client, client_proxy_added, > NULL, NULL, client); > > - client->reg = dbus_message_ref(msg); > - > client->data = bt_ad_new(); > if (!client->data) > goto fail; > @@ -1216,6 +1218,8 @@ static DBusMessage *register_advertisement(DBusConnection *conn, > > DBG("Registered advertisement at path %s", match.path); > > + client->reg = dbus_message_ref(msg); > + > queue_push_tail(manager->clients, client); > > return NULL; > -- > 2.28.0.220.ged08abb693-goog Applied, thanks. -- Luiz Augusto von Dentz