Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6834679rwi; Mon, 24 Oct 2022 06:43:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wTFjJY7WNajcfdYFFG3A9UJeDDx+FKDzrQgRgX7ufBA15i4voBfSrtTgTW4WJ1GO9wCqS X-Received: by 2002:aa7:d385:0:b0:461:8cd3:b38b with SMTP id x5-20020aa7d385000000b004618cd3b38bmr9999652edq.172.1666618992256; Mon, 24 Oct 2022 06:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618992; cv=none; d=google.com; s=arc-20160816; b=ifdHrf4BgE8af6Y0XO0QozJrwOeO7RXoSQ79a2URdM3O6Y04SsAwRLUbekyvJvUiVL Ery8LlJhIJnIgIS2cCOXow+XHPZ/P3xEj4s68sIxNOaDQe0gMxavrkAvTjuaGAOtK8Kv 7Oc/GmTcVJpiVDlKVniazBc6Bx38tZHUuL1vNEsFHURCMnkLrJ30QgK6XhYZDlMhbrWr ZqCsZYokreaLhT2T8fkOacLbrIrUMhKQGTAOyulsUNcovzHwiGnW6SSV4x3VPkGQBZqs qVY+NYWVlIAP7WcjejSYWStaZoFeP33QLrtmWXMbkkjYG0ytVYRwg8xERBkutFa4gVTT erDA== 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=USoZ+RROFmS4qPmQKOmmdod7T6s9t9PLBxbslQ1cr9s=; b=kyUojFv0yJN3jux09/mRPWZB2BxsloA8cudxiawAupBMUsSmbuBGL1B2SX/le7s/sk bZVJv6nD0GHx3xARS5YQP/kEEs/T71hn5Fqk03vIIwhO1G9Bn2AS7g1eQZUl32HTxfLw YQ2me8mWrB8QN6w0mJ3Qx3Fx9ms9KGhLLcYWZMLDeYPqjnsNZSKy5DiAmLyxBQL9OZKP +HMuUoBBpvUfTtgQ8jrbXrY/oBcFXGoyz3+8IHTY5ZTL+ddij5EBLSZ+lVwoRrpVGCnz GYd9UJ7BKULrD3BORizXAAuqS2++9P06mZk0uwkYhCYNs05WYyvoUzkGUQsLHlZnnr3y aTNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pcQjuQ/u"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11-20020a05640226cb00b0045d46f28533si28493018edd.377.2022.10.24.06.42.43; Mon, 24 Oct 2022 06:43:12 -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="pcQjuQ/u"; 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 S235953AbiJXNeJ (ORCPT + 99 others); Mon, 24 Oct 2022 09:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236190AbiJXN35 (ORCPT ); Mon, 24 Oct 2022 09:29:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FF2EAC4AC; Mon, 24 Oct 2022 05:33:17 -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 ams.source.kernel.org (Postfix) with ESMTPS id 9F3F7B811C1; Mon, 24 Oct 2022 12:04:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F145AC433D7; Mon, 24 Oct 2022 12:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613056; bh=QqpHLqiHJ8pQMZ2r9rm0Nz/ebpA/pgrtpSt7B2/lRsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pcQjuQ/uDiZ+SmDlzrAHufTcvWDHFv/03JNe2rS6wMhbi6OhqSnxHV8DZp5K0/vNj Av9oj9WmjHb3VLmBvaHeBeuQvOOBOpRvpj+J3/yA8h+CQtF5YCRGfuUTtPQHjJL/4U ImPObQ8av9NTYmcyW3XECNmJSruO6ctoT3sCm3gQ= 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 4.19 191/229] Bluetooth: L2CAP: Fix user-after-free Date: Mon, 24 Oct 2022 13:31:50 +0200 Message-Id: <20221024113005.308616466@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 7c280fcdcaa0..5c965f7b1709 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4049,6 +4049,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); @@ -4078,6 +4084,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); -- 2.35.1