From patchwork Mon Oct 24 11:32:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp458141wru; Mon, 24 Oct 2022 06:37:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70vaS6veKxhfN1N/WDXULtXaVPshVx63KnWK48CBsZYzkypk0aoQXe1J1jUIILisNvLp4O X-Received: by 2002:a17:907:7294:b0:7a9:8a22:74d4 with SMTP id dt20-20020a170907729400b007a98a2274d4mr2819237ejc.139.1666618626633; Mon, 24 Oct 2022 06:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618626; cv=none; d=google.com; s=arc-20160816; b=DA1mPhPF0VhkGtb1I+BFt38wkZezUiO80tBRF/5qBzvFD7uC/ax2FrY70wKmIZUfDP 8fHN4NR2+JNg4BnPo/BBQbKiTbug0sw81GHWjljLaeGUMKfiK7/YWu7xrVQDoH/1HHB7 EszCY3BUuwmpjBrjrc71J71O0kzh0oi8SqpSSU4G5vef9x6aoL+BoY5XXy8rcVxPYgOe u/hYI5YnECpqZFLWWKLNU+cWuZhGBM2PA7r37u2ZuVBsjGTAtcDMbdZf2AMPcbKcbUHD +56XLPtYDkeE+nKB4p+0k2zEKzpFsvZVEcy1e8V+le8ss9ECBb+NdbDjRFpIZhfkXHAf OfLA== 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=+CAUdllp8De5S7kL94KxNmMiRjkP1aVzg8Xfo28htpA=; b=QnGUdWBXA6wXUfvefcOCvlo9wLR5w2ykqIlSOxSD9keYVQo+KaUzP4JwuGu6zs3/f4 z0JhFkd10uqq5BRx/Ci1Cb4aYBZT2LXB6MH22huv4K6c7yby/l+r7uMxQdC6g6Rt/ycK TN6fVFaiem2L4HkXkrlBfgnyNgq8Dert06R7eu7lT25FSFC7m42AkOAMzTeBRFKmXHC7 LUd0cP1mCPzvqs7dl6Cv97qqQwxk1VQ7KwflBmkZoTI4L2MjoOz+Cv2lWnLkg+68qs4t 91SW3rV4X0PR6tN6a24P14m3MZPIhkNMrnuzTTkhkh60w5z/RDWHA+ll8NFa8nzLbFo9 ZjCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rm+Jjzj7; 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 sz15-20020a1709078b0f00b007918f58458bsi16811169ejc.441.2022.10.24.06.36.32; Mon, 24 Oct 2022 06:37:06 -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=rm+Jjzj7; 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 S233475AbiJXNbe (ORCPT + 99 others); Mon, 24 Oct 2022 09:31:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231649AbiJXN2F (ORCPT ); Mon, 24 Oct 2022 09:28:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 592EBAA342; Mon, 24 Oct 2022 05:31:52 -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 02AFE612B2; Mon, 24 Oct 2022 12:31:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 187A2C433C1; Mon, 24 Oct 2022 12:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614683; bh=RjcwV9hFrPRXuhgEUhxyJ95z6UzuutUEERVXHOYHQnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rm+Jjzj7ii+MWy70Qbv3YCYOFnjitbtanAoktIYNatJ4OLX6aL4AZqXDOg+BikEbV GQymkgXDpR1P2oAxeaAmO8GZzkOyL1fi2lqvY6Id7j3Lv6E54YqvnOiUVpct267pmr zrU48Jha1Srk6lCiOdWwBrEjd4IQh3pbbqpcOlpQ= 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.10 323/390] Bluetooth: L2CAP: Fix user-after-free Date: Mon, 24 Oct 2022 13:32:00 +0200 Message-Id: <20221024113036.750158970@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747576293201495747?= X-GMAIL-MSGID: =?utf-8?q?1747576293201495747?= 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 8d5029c81ee7..83dd76e9196f 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4305,6 +4305,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); @@ -4334,6 +4340,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);