From patchwork Sat Oct 22 07:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1107712wrr; Sat, 22 Oct 2022 01:41:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zlgES1B+tbpGLhmaeeF6opz7UGqWDkAO68cRqHe3XyX0B8FMJmEexZCOLpuYIYCSbq8kZ X-Received: by 2002:a17:907:6e9e:b0:78e:214b:e3c2 with SMTP id sh30-20020a1709076e9e00b0078e214be3c2mr18796826ejc.15.1666428110116; Sat, 22 Oct 2022 01:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428110; cv=none; d=google.com; s=arc-20160816; b=xZfi0ud8BG8Bs+6fqrfGqKTHA2EMiVpvyAkEdG8Jx+nr/8oO2EeEubeknzwRR4w8EK UVZN2vXSw8HPTsBUJxnG648d9k/L0p1Tn3idIhxqhzSRovx6ngBdCBc8dYUBtFDGQB5M oiWn1HFbP7/tEJ665AxeZ6jqY/MF5BRIB83ztqO48v8alJRMm0YhvFBF/iRGtkD5rEYk h8myTIoUbDzg25+nWop5SSlmaNtDY04ksURmj7UtsP+bFF/d/dYOpbdEwgeQQ+yqYka6 hURiXJhcoXf4dEFGLbz7OtjfBGF9fqYmMoVD2BAy18YdrGusIWeER5aqExmN951UyWVf loSg== 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=gQIX43JC2NEsOt1XeEc31mNSPitnl6+b/jcmjcU5Ju4=; b=eLpfTdajtV8BfuXzpG7XgWB+kBr7XsmUW0jEn9gxwtpjC9JYAVfxYtQeFq7T5Ztmh4 LDR6W2cw9JXyLm5Zb/WivpOB8P9wo5PIwDrt1P9Batdir1eKoYHTgh7lTFOZUJpd/LB3 kUzCKJfo/N2kGdUcvD7SabkBOqVMoP/G4su+9x2Iufjz+wG5mdwoJGFy55ZIS4iskBge IttY4pRdkIJiHy/lGQ2kYN/pV03svD+L5V4IhW24eUL+cgwThBZTvV/rk+KVAFvmlpEm R6jyg74AMpI1zwvdiKXSRBLYydOQo16ga+RK/+3LQk3ZPA/TpIyk1g+ieCDZ3AQFPKgX uucA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DEy9QpaM; 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 hs41-20020a1709073ea900b0077b6ecac099si22607416ejc.287.2022.10.22.01.41.23; Sat, 22 Oct 2022 01:41:50 -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=DEy9QpaM; 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 S234575AbiJVIjL (ORCPT + 99 others); Sat, 22 Oct 2022 04:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234422AbiJVIf1 (ORCPT ); Sat, 22 Oct 2022 04:35:27 -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 1EB7B31F82; Sat, 22 Oct 2022 01:04:31 -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 5B21E60AFA; Sat, 22 Oct 2022 08:03:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AC14C433D6; Sat, 22 Oct 2022 08:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425813; bh=x8/+lA1k8NbrcbGopMpHIBsbkpzGkwI75CILb2F9Tso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DEy9QpaMHPT39qPUX9qZ5GEX5ol6sepV/y+s5bZEXqlsLgJ745QhGB+uxj5K0ViAt 54B330iqEI7GydBCPz8nAFszQFl57231v3/KfpncFI1j6Lk+Gpmco5SjcFm8NBSZ9D TUvRC4qzvu64k+NyolIGxCyzOwFbtyb/BlFxnEMc= 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.19 595/717] Bluetooth: L2CAP: Fix user-after-free Date: Sat, 22 Oct 2022 09:27:54 +0200 Message-Id: <20221022072524.756450268@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747376521814673790?= X-GMAIL-MSGID: =?utf-8?q?1747376521814673790?= 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 a8835c8367af..0f98c5d8c4de 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4308,6 +4308,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); @@ -4337,6 +4343,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);