Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp571099ioo; Thu, 26 May 2022 09:38:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVGQjNJTOdSR51NVaEI35dQyLzlPQf86OIkZWW7yar8vP1om0tW/iOXJhyDJ4snexgrrqW X-Received: by 2002:a17:902:cec6:b0:162:50b1:b40a with SMTP id d6-20020a170902cec600b0016250b1b40amr12209222plg.107.1653583097297; Thu, 26 May 2022 09:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653583097; cv=none; d=google.com; s=arc-20160816; b=O2ucCZimJ3bion11spfVjpXHd5H7BfcudbSJEhESodAdiiyxxTicCt6g0+FJGOMWRV QKyiQrFO1XTWdd9azh/vbsUWWMqgXLbmruJFEAB/jYsJaOY1Fx5wFijN/1+vAYbn8qrw 4fJQopQqRPCZTEorwCgMLsYzLVIpzY0bSKPPN209vLb2u9PL2WF/8wSGXIIoztlZwXne 7onjSKpI4rHgxANl/qHqhpSNYMMMopK/YNoLLq9RulRZO481huya0Bs8UzzdAiFXk/Ps Jl/LAK5Zl3Zuo4MQKq2xoKZlAwk/xyPuEh3Z9vHpH8nn0RZ09vqRf1AvJavUBFXyN1xS Oh2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=rHAlnYokbPDm5sHzersK7AiNCY1b15v1iGws20Njocw=; b=dYuCdLl5GNeFf1lA8t2T3oAE6NUt+LgaeiU2d9vQGqiPR1ptpoN7iRfPyzTOYZyoB8 qo/QYbVc2V+YEEzmW2P7YBh8jb2vUV/hPa4E6KpwR3G9KDynF2flKrJvpmKDm8ohhYBS h4vBhVHvxibhuyxUR2cgPIE30O6JKJGic/mDB+Y8eQv8YuUP8eBP1SOXVBAS7PW3lEyB FBIy/DLDRj4LQr6UwNJZFudGBv47r+ZkPhjYmKcFvRjZArmyvdhEBxLDL8k5xQRNdG4N sjHaG3DjESRXKJ+fm3dCcW8JNGtqugk4j0yCDjYchLK/n4aZ6XPlwwqZzthKIdXxrVQz tjcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aVDAczMq; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp7-20020a17090b4a8700b001decaeaf1easi3037751pjb.6.2022.05.26.09.37.26; Thu, 26 May 2022 09:38:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aVDAczMq; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347141AbiEZLYn (ORCPT + 99 others); Thu, 26 May 2022 07:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347150AbiEZLYj (ORCPT ); Thu, 26 May 2022 07:24:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E9DCF95499 for ; Thu, 26 May 2022 04:24:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653564276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rHAlnYokbPDm5sHzersK7AiNCY1b15v1iGws20Njocw=; b=aVDAczMq9nRxOLYbwWDuqmBJIhqvC17XLoLFl1CkE3VEE3BJ+xxYYh6N41BkkwAUaJT+O5 ur2j0bsELLMONzNNoVW8fpr3WKOEroC7aywhjT/SZIRieJ79i+45soj29BOW3i4FJZlOLv 3TaNxFZODJP+3YUKr/jwGkuspAGVaug= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-493-W2UxU_LAP52rw9nuGWyLsw-1; Thu, 26 May 2022 07:24:35 -0400 X-MC-Unique: W2UxU_LAP52rw9nuGWyLsw-1 Received: by mail-wr1-f72.google.com with SMTP id m8-20020adfc588000000b0020c4edd8a57so220405wrg.10 for ; Thu, 26 May 2022 04:24:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=rHAlnYokbPDm5sHzersK7AiNCY1b15v1iGws20Njocw=; b=bViDKKBnyBMZXGQZE5No8baEaCWgVRSmuLmyOMclB2/MrJ87S/CMZBHv4huV+G/ksa JX5EMCSLTxLcJ/W2nF/MxvwAshcYT0aNGBqeMK6zWpfTmlsw3RUbwFsKvnbCstkrNNan lmcLYIRKRZ0tfVTjPGELssLYyYUqREkvQxF6VtomdEesiKr6BbIKBV+3oJToGR9BdDZS /2QhbKaGcY7tunpg1/lm8U5iHFHLxDZ0rW5XUvHYnJxFhql+ka5cIgdYKEgY6S6XATx3 QqyABRGhxM/xR4UJw/V3bDON7vgRF+liAi4NR3Acr/gQl3lOm3lgnJsT/3UxckmGBhs0 GJnw== X-Gm-Message-State: AOAM530PwU3Zc7VN92mTgRnZ8YX9QSee/s4nSEDHRa8KfkYjGRjXCYkF F0ulJOA9myJhsUeFjsVtKeUKsBEaudEgXce+sQc6BgROOC0OCecL8Y2lhOdBCMG+PZ1sPxnJ0v0 0Vmuj7iuoEQnIMQuDdxCnBe9kNMsx X-Received: by 2002:adf:d1c6:0:b0:20f:c7dc:8466 with SMTP id b6-20020adfd1c6000000b0020fc7dc8466mr20941655wrd.43.1653564274207; Thu, 26 May 2022 04:24:34 -0700 (PDT) X-Received: by 2002:adf:d1c6:0:b0:20f:c7dc:8466 with SMTP id b6-20020adfd1c6000000b0020fc7dc8466mr20941635wrd.43.1653564274009; Thu, 26 May 2022 04:24:34 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-112-184.dyn.eolo.it. [146.241.112.184]) by smtp.gmail.com with ESMTPSA id z24-20020a7bc7d8000000b003974ba5cacdsm1570171wmk.35.2022.05.26.04.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:24:33 -0700 (PDT) Message-ID: <081b216e6496e8cc2284df191dcc2d8b604d04f7.camel@redhat.com> Subject: Re: [PATCH] Bluetooth: hci_conn: fix potential double free in le_scan_cleanup() From: Paolo Abeni To: Jianglei Nie , marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 26 May 2022 13:24:32 +0200 In-Reply-To: <20220526094918.482971-1-niejianglei2021@163.com> References: <20220526094918.482971-1-niejianglei2021@163.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Thu, 2022-05-26 at 17:49 +0800, Jianglei Nie wrote: > When "c == conn" is true, hci_conn_cleanup() is called. The > hci_conn_cleanup() calls hci_dev_put() and hci_conn_put() in > its function implementation. hci_dev_put() and hci_conn_put() > will free the relevant resource if the reference count reaches > zero, which may lead to a double free when hci_dev_put() and > hci_conn_put() are called again. > > We should add a return to this function after hci_conn_cleanup() > is called. > > Signed-off-by: Jianglei Nie > --- > net/bluetooth/hci_conn.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > index fe803bee419a..7b3e91eb9fa3 100644 > --- a/net/bluetooth/hci_conn.c > +++ b/net/bluetooth/hci_conn.c > @@ -166,6 +166,7 @@ static void le_scan_cleanup(struct work_struct *work) > if (c == conn) { > hci_connect_le_scan_cleanup(conn); > hci_conn_cleanup(conn); > + return; This looks not correct. At very least you should release the hci_dev_lock. Cheers, Paolo