From patchwork Mon Oct 24 11:31:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp437140wru; Mon, 24 Oct 2022 05:59:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60g2REYfO73E4EgB7lhLI0MXl4OEu0Z7ZQ8MVeBVbFmM2M5qOzxET5xT3fjrYe3AYdWcjy X-Received: by 2002:a17:90a:4311:b0:20b:e232:5920 with SMTP id q17-20020a17090a431100b0020be2325920mr38795000pjg.190.1666616341144; Mon, 24 Oct 2022 05:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616341; cv=none; d=google.com; s=arc-20160816; b=Hfdgm0hYK1lopTqp8zmCy7b7CbAChV+e37hrErFMDhqivPnAeYIxEoJ1ymN3SPgC+L nEbEZm2jV8a+0RoJ5FoCY/LxNoL4n20RL27ma7QH9D6ok1KBbeMBCd+lVU/s7KEPDhrm nLZwM3j8zz0nf2OyypaMFKoXs7T1ZV0bu0WCgHno481C+IkBLS1Arst3PHAunBSgc5LO iL84taeQL/xhSa4WzY3t5STHwWXyKBkJPywz3LjRuRvvSMkzb4JWYnosKrPg+yyyXiZq i1S2pRgUP/tMum91SouTMbH6pWP6J9H9ywoiBqHozPlDiBE0zdMV/jJ/75XXqodMit3/ X3pA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=xB+Pkg0BpTVZ3oxEFCJQxCzPE0EgDsalp749Czr4PDU=; b=0dfhugBDiGTuRCOdEScxbJ5iRC5VBUKZ3htGNbK7aQbMhUvjbG2ewjm1r1C8jn3Pbz 1s06DjeEcU78NAvD/F10WnjbtPrMwKsB9GT+3G0pCss+9/Z/PJ/uttyMkLFePeVrbugE 4ltRQ6qNfACnEiOnriqQ0Llh88/L+/ya8coEctMbUsStq7l6knQSOCfX0vK0CXBih/ml w9yPgvV0dtRnyXA2ID+KXPpj6asp8brPYJsEoqagRchGmclFtnutVM9aC9B1waTCEEpn gVlH0YWrSvzAt7hlecPNHwD1Jo3tL93Z9l7woi2S6P+NpJqQ//pU4VI6grVp3M+agoRR bW/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z3U3kpma; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 68-20020a630147000000b004632044b838si36373497pgb.650.2022.10.24.05.58.43; Mon, 24 Oct 2022 05:59:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=Z3U3kpma; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234889AbiJXM6a (ORCPT + 99 others); Mon, 24 Oct 2022 08:58:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234834AbiJXM5k (ORCPT ); Mon, 24 Oct 2022 08:57:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACA8397D63; Mon, 24 Oct 2022 05:16:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9D4C66131A; Mon, 24 Oct 2022 12:13:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF092C433D6; Mon, 24 Oct 2022 12:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613627; bh=maJ8fNNyCcC99rqyWAvsYKYOT4uvsH7Am3h5FOC+4NU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z3U3kpmaW/P/JB1ExNpfCjsy4CZ9RZWRgrqW7GpWjABOvmIigqiinl7jwSMV46qc5 onA8/F0hN5six1PGWLR4I6Oau5BV9jh7KHyOwVjv4CKQk3XGZWcPCtyEIosPAucgdl MCAmO5eM1WHQvnLAW9BZbe53+8EJ7Pdimm6QQ2r0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Sungwoo Kim , Sasha Levin Subject: [PATCH 5.4 208/255] Bluetooth: L2CAP: Fix user-after-free Date: Mon, 24 Oct 2022 13:31:58 +0200 Message-Id: <20221024113009.958321735@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747573896444776231?= X-GMAIL-MSGID: =?utf-8?q?1747573896444776231?= From: Luiz Augusto von Dentz [ Upstream commit 35fcbc4243aad7e7d020b7c1dfb14bb888b20a4f ] This uses l2cap_chan_hold_unless_zero() after calling __l2cap_get_chan_blah() to prevent the following trace: Bluetooth: l2cap_core.c:static void l2cap_chan_destroy(struct kref *kref) Bluetooth: chan 0000000023c4974d Bluetooth: parent 00000000ae861c08 ================================================================== BUG: KASAN: use-after-free in __mutex_waiter_is_first kernel/locking/mutex.c:191 [inline] BUG: KASAN: use-after-free in __mutex_lock_common kernel/locking/mutex.c:671 [inline] BUG: KASAN: use-after-free in __mutex_lock+0x278/0x400 kernel/locking/mutex.c:729 Read of size 8 at addr ffff888006a49b08 by task kworker/u3:2/389 Link: https://lore.kernel.org/lkml/20220622082716.478486-1-lee.jones@linaro.org Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sungwoo Kim Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 442432f89be1..2d28b4e49b7a 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4066,6 +4066,12 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, } } + chan = l2cap_chan_hold_unless_zero(chan); + if (!chan) { + err = -EBADSLT; + goto unlock; + } + err = 0; l2cap_chan_lock(chan); @@ -4095,6 +4101,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, } l2cap_chan_unlock(chan); + l2cap_chan_put(chan); unlock: mutex_unlock(&conn->chan_lock);