Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6989625rwr; Tue, 2 May 2023 08:06:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4aa0e1qgRH1kxunkHLniffx5o2XGG76qArg3iGLh0d2bCEcBK5cdWapnzgN/iiCPFRk/o5 X-Received: by 2002:a05:6a20:c70a:b0:ef:f558:b80 with SMTP id hi10-20020a056a20c70a00b000eff5580b80mr17637087pzb.58.1683039987419; Tue, 02 May 2023 08:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683039987; cv=none; d=google.com; s=arc-20160816; b=GRBK4jstdAUVolihNc8b4E121X7Gujenj7fp6drhQ3bm/VC00qPEJfo2nMMhLMLGVG 8aIsJJWAynVH0a7pfRHZ0DSYzbe36yTXToFvogppwv57HjCjiGRPV5pgTKwC/3TQOxi/ ElAkLp6gUIPuJTR6tunxnEC2pNqvi2ywPjmN9BolIm3V66HMk1/oWxr1/Uu90WGWUmQM cOI8lmMK2NHHMyD1WSjI3oxZhfdwIzIsZXtnQfuF2MFEiMa7LxiASMe+ICT/J0ktXxsZ nQ/UUChMsbah8UTh5SAVaHhwfhf9h8id9aiqPYjcJ7X3Hu3R44jvPWX5i2qGhZMIFcFs d19w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=avNJ51aScZutbdGQ55v1LNc39r1/FL5jKij8SkDff7k=; b=fM+eTkJA8wTORgmkUxviz0A5+MCkflyn/vavRi0Ii/XXbThNCIIq0q7XjkNtlKgP6c A0FOQFF3JcVFC/PEEVXSnDE1jcVbtuIEpwOAzAF/YrsjCFdKNmybFi7g92TSuazx2y4S gxgTuSQUj16Rj2XsMEIO+nQMrD6z82Nrv9YB+/SgDDYY5d7YdqMy8jjGXQT/47I3Iqcc bn6fAOMsYNldUoZh+8Y8GsdnQvrPf1jR12hrZ7lPs7K28XPZqwldRp9woPHOp0MudIpY OtsmKCW8EhYBTTmCPLlewWzoi5HZxuWl2MC9jHAGRWtimW64SndcRKex2hAbztpnmGEM pi0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@pku.edu.cn header.s=dkim header.b=qceQn9oU; 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=pku.edu.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a63fa49000000b00528d30e698bsi8859821pgk.734.2023.05.02.08.06.02; Tue, 02 May 2023 08:06:27 -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 (test mode) header.i=@pku.edu.cn header.s=dkim header.b=qceQn9oU; 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=pku.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234516AbjEBO6C (ORCPT + 99 others); Tue, 2 May 2023 10:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233981AbjEBO6B (ORCPT ); Tue, 2 May 2023 10:58:01 -0400 Received: from pku.edu.cn (mx18.pku.edu.cn [162.105.129.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6C4FD26BF for ; Tue, 2 May 2023 07:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pku.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=avNJ51aScZutbdGQ55v1LNc39r1/FL5jKi j8SkDff7k=; b=qceQn9oUNhzP03vjImu4OMXOYNPqf6B8DKaqOKZLqXu+T390eb 07oyCTclMcQ4a617IxSEGo8rwqO3qGUcIpNnnjQ1caW9JQF5xhLtSLKrNz0Xsf8i +8PNWVGwYsbjgttGffkx82PN2CcIEHtz/+cbCdckVcJqs4Gr5FDWIbuK8= Received: from localhost.localdomain (unknown [10.7.101.92]) by front01 (Coremail) with SMTP id 5oFpogBXX5fjJFFk6i5LAQ--.10226S4; Tue, 02 May 2023 22:57:47 +0800 (CST) From: Ruihan Li To: linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Ruihan Li Subject: [PATCH v3 2/6] Bluetooth: Refcnt drop must be placed last in hci_conn_unlink Date: Tue, 2 May 2023 22:57:33 +0800 Message-Id: <20230502145737.140856-3-lrh2000@pku.edu.cn> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230502145737.140856-1-lrh2000@pku.edu.cn> References: <20230502145737.140856-1-lrh2000@pku.edu.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: 5oFpogBXX5fjJFFk6i5LAQ--.10226S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr4fKr1ftrW5WFWUGF15urg_yoW8GFW8pa y5uay3AFWkJrn0vF1qy3WkWrykCF1kZFy29r1rAryrJa1rtr4jyr4rCF1UKw15ZrWkGF1f ZF4vqwn5KFWDGFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9j1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm -wCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26w4UJr1UMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvf C2KfnxnUUI43ZEXa7VU1c4S5UUUUU== X-CM-SenderInfo: yssqiiarrvmko6sn3hxhgxhubq/1tbiAgETBVPy77xtrgAAsk X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 If hci_conn_put(conn->parent) reduces conn->parent's reference count to zero, it can immediately deallocate conn->parent. At the same time, conn->link->list has its head in conn->parent, causing use-after-free problems in the latter list_del_rcu(&conn->link->list). This problem can be easily solved by reordering the two operations, i.e., first performing the list removal with list_del_rcu and then decreasing the refcnt with hci_conn_put. Reported-by: Luiz Augusto von Dentz Closes: https://lore.kernel.org/linux-bluetooth/CABBYNZ+1kce8_RJrLNOXd_8=Mdpb=2bx4Nto-hFORk=qiOkoCg@mail.gmail.com/ Fixes: 06149746e720 ("Bluetooth: hci_conn: Add support for linking multiple hcon") Signed-off-by: Ruihan Li --- net/bluetooth/hci_conn.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 70e1655a9..44d0643fc 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1102,12 +1102,12 @@ static void hci_conn_unlink(struct hci_conn *conn) if (!conn->link) return; - hci_conn_put(conn->parent); - conn->parent = NULL; - list_del_rcu(&conn->link->list); synchronize_rcu(); + hci_conn_put(conn->parent); + conn->parent = NULL; + kfree(conn->link); conn->link = NULL; } -- 2.40.0