From patchwork Sat Feb 12 23:14:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niels Dossche X-Patchwork-Id: 542611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A102C433EF for ; Sat, 12 Feb 2022 23:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232416AbiBLXOk (ORCPT ); Sat, 12 Feb 2022 18:14:40 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232399AbiBLXOj (ORCPT ); Sat, 12 Feb 2022 18:14:39 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70094.outbound.protection.outlook.com [40.107.7.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49FF95F8CF; Sat, 12 Feb 2022 15:14:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mDFOIjR2O7DEYj3qzOdhF6mYeuHrCKWxKkFU0h4UWgDEK1WTVbHNlJW8km3b7O2NyHcNIH2cS5Uy+B82T7gQBfozEDZMlSEnikJGad0ivfwZp4Xx8u1YrP07dhUzzY6ZkzXMJmQxZQkFvX9jBOiQWc/Ig9GZXZd1y6THCHeC5s9GhZ/TP7DHRD4x/zSQZMHDE3esSv8Ie7KzwJg7vFbsxO8oKGydodnb9u25ZCjR/9p231jIfK05263M6KvZV5cw2WOk26phJzDjpKwm9GP3eLPUhIALYTT3O65dUCap/Dw+ad1NnkGvBhtJyXrOtflRwQ/CZGMu9wAUTiLh96NKdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iRi1MF4CZjlLaJIVvAuNydkH/V+l9HuJ6juhL0I8kQE=; b=Q/0mje9ldCF1VtW+DSiuEvQAe0y8elgbFedlDKPTS2XnUeKz1Zpp9SxX4dVpjbqaKUbnax2Cw3EExwiQZNXkGOna1Tfr6ToDHvKEp9vKDEW4w4Genb1E0Bgq4jPehsFgByBfQ5vILz8eaZiAaoYC3nHCWxgT/rpkQHeeQBa2883Uk+9WqKnPomV9q+LBrEwhzWgM+K9gfv6mR2mKs2W6ZILvgtmHpoEwu4x2+B/1+Il1nztvxsaF+hJsm0xdmMxQ5Es8s1BlIKw0i8Erf+jPViVvmzDLSMhW3zCZFbH8Bmtmb39U+6k5IQqB8+TMe/t2WaxjMQFIk0X8f6wK3NFIDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ugent.be; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iRi1MF4CZjlLaJIVvAuNydkH/V+l9HuJ6juhL0I8kQE=; b=CZxPJfOeGPVZJS4GCRz0HT+hmBX5chaJcAV07PHZ9mU/nt9UoRdGNxANT4PHpZo4wp14kyKY3jkaBFRb6WXRNFvifW4wJJw5Gix7/DscjriZNNacnZ97nFUPSG1vpx9RaIvZxa+rTI+H0hIzn4dDyZHo9PvTJeWHSlwcMIHiAYI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=ugent.be; Received: from AM0PR09MB2324.eurprd09.prod.outlook.com (2603:10a6:208:d9::26) by VI1PR0901MB1440.eurprd09.prod.outlook.com (2603:10a6:800:8d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Sat, 12 Feb 2022 23:14:31 +0000 Received: from AM0PR09MB2324.eurprd09.prod.outlook.com ([fe80::b115:2e4e:1623:f624]) by AM0PR09MB2324.eurprd09.prod.outlook.com ([fe80::b115:2e4e:1623:f624%3]) with mapi id 15.20.4975.014; Sat, 12 Feb 2022 23:14:31 +0000 Message-ID: Date: Sun, 13 Feb 2022 00:14:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org From: Niels Dossche Subject: [PATCH] Bluetooth: move adv_instance_cnt read within the device lock X-ClientProxiedBy: AM4PR0701CA0029.eurprd07.prod.outlook.com (2603:10a6:200:42::39) To AM0PR09MB2324.eurprd09.prod.outlook.com (2603:10a6:208:d9::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f5471ec-d5a0-4644-f7a0-08d9ee7d6cc5 X-MS-TrafficTypeDiagnostic: VI1PR0901MB1440:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aM4FfqXtVJRHte7Fh0+ZOgKNy5w+UvJjN43V39+CuncNOiCfbb5oiw82krWtPVSUCkk4ruNdPTHibvzUByp2fjU/p5IG9BDg9wvnipFawDHdnZOwzfKzcz7zTVR4A7CyUDxYS8FwNLgK8L6imtPmQ8Vw5050w9zK7pmUGhNBepsWc2RiZnBiMNPKljpQMV2wXABc+XFeGV+8PQbbTkOU/aHZotTv3eTr65g/8dMza35ENfmBf2VHUDEHeSqcTQyB+Iy06MwXbsSEA5tplPMkCpMclbfMO6QGnWrll5FY5O8OzkswBwvJmHJVB7KyflcyjXV3YsfBc8/+leeQlXn3iJ8Qeh0TQQBDbgvInHZAXOiiq7xmALuZJzGShiqXkWmqZwGEVuPgVFAYxUU9ktDWYw30DRBzOUo+prvEd4BVOr8MjLNOMPHcDklnrjBY0+nxkxrQB7TQHC82VowNwV7VES6qRtCuIul3rcnYeVqcsbZ8rF9IUiJdDlPbyr650PJNaIe2FOIakrMcd2XLRJtG5Z4S2eXSahBaTcbmIafMgp+ly4mr4/8Dg5s9MamaaO4VRqkaqrk94UQUDH7cyBka9J/x94XlUqtqfWWiLR/L+D5Kd1zSh3Jwft3MHyTl6MGB/Iq764+8NLzJ14dYaCWADa6AuoodniYjacMDuiUCZ0NCNsaL54/ja1au2BQNDyHQzCfoiuhM/ik53dhAgECI0mGk36vh7AhbkXfoyzV/d/E= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR09MB2324.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(4326008)(66556008)(31696002)(66946007)(6512007)(8936002)(2616005)(66476007)(86362001)(2906002)(83380400001)(508600001)(186003)(8676002)(5660300002)(6506007)(38100700002)(6486002)(786003)(316002)(36756003)(31686004)(44832011)(110136005)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?0yKtK01XcyWJP1W4PukAyP/pjTwN?= =?utf-8?q?ZyaaI6dgkH3o6tIhnWqaG8b6la0WT3d0iUK8+Oo6oU6qchOcQKU4Wraol6iKyIvJX?= =?utf-8?q?HXdPHBB4qYXdzdBIXubDh/vwVmtAYXjr0bSxalDJTnUufbnp/Nh6FNBcmHmtN4Pby?= =?utf-8?q?vpTk8INjFQkVd/gMkB3Agl24Nx999NN+5uYWhend0a1n2hVGnY2FOP/22hRbhzqO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XlAUz16Pe33gOywO?= =?utf-8?q?Gj2IJR6/C1Uahp41kZHU0TeQGmeA/pkPiyUlEx/TTzJkDPzKDfPQ+F0ev4VnHXp4Y?= =?utf-8?q?HYFFrSNg3/V+ynK1T5WXxpBbeJPFib9GeZEdLV1Y8bt9DMEXKlZ+r75keDYimC6my?= =?utf-8?q?a7wKuf+2suiAGYkhhfa/oljDWuAdfRfK88w49a9O9XjKjAkYdrP9d37HuAiGBwcNF?= =?utf-8?q?iBC8L4TLs7qkzdIqdLuXdO9fNhTgcE0X62/5BEBy5SKZgMKKbpOY/vH835Kq0KTYQ?= =?utf-8?q?Qp8bivmn2jaD2HtJ4Yiuc/YEFYZWal29e1Q2AgLicgnPm8xNzMuHbscHwfl249Mjz?= =?utf-8?q?am7W2r8IS4ZdqRG+Age6iXDuwd05Z57R9xS07V2LbElr9sk0XvYrkmpOaN0Wbyxwb?= =?utf-8?q?eAwG6ZBVwQs9zGpIAF4ry2dse8lurK05WdXIcovmmn3IZxdurgBA7G8PPwUrxUadD?= =?utf-8?q?iFgsa6hvB7BFxW6OAFG8RwBiX38V1edBs1iTDkYnh16o4wCbr6jM6yynmhflk44WU?= =?utf-8?q?9HdGTjmbJcQ8QyD8P8Mi9ZJ8IQXs/1TJKkpGqivuah/zlE/KkkszQY=3D?= X-OriginatorOrg: ugent.be X-MS-Exchange-CrossTenant-Network-Message-Id: 0f5471ec-d5a0-4644-f7a0-08d9ee7d6cc5 X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB2324.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2022 23:14:31.4434 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d7811cde-ecef-496c-8f91-a1786241b99c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: COGr7kDS1zCLIrVB0+xm6a7tQyxixCgBp+RcIuyACHslLgLizMOAmRYkTz5aDJI+gzD8+obxNYsoBHDqOzoiTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0901MB1440 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The field adv_instance_cnt is always accessed within a device lock, except in the function add_advertising. A concurrent remove of an advertisement with adding another one could result in the if check "if a new instance was actually added" to not trigger, resulting in not triggering the "advertising added event". Signed-off-by: Niels Dossche --- net/bluetooth/mgmt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 37087cf7dc5a..e0dc72f147b4 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -8046,7 +8046,7 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, u32 flags; u8 status; u16 timeout, duration; - unsigned int prev_instance_cnt = hdev->adv_instance_cnt; + unsigned int prev_instance_cnt; u8 schedule_instance = 0; struct adv_info *next_instance; int err; @@ -8097,6 +8097,8 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, goto unlock; } + prev_instance_cnt = hdev->adv_instance_cnt; + err = hci_add_adv_instance(hdev, cp->instance, flags, cp->adv_data_len, cp->data, cp->scan_rsp_len,