Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6818596rwi; Mon, 24 Oct 2022 06:32:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5euERNFH3fO5A6IOuieDpAtMIj9N+kt/QB+Ud77/xPHwSxcUpabpaQHyMzuAp+fNMjGFQL X-Received: by 2002:a05:6402:348b:b0:45c:b22b:c4a9 with SMTP id v11-20020a056402348b00b0045cb22bc4a9mr31644076edc.65.1666618345134; Mon, 24 Oct 2022 06:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618345; cv=none; d=google.com; s=arc-20160816; b=vMtnR1pbsE9gJFrb7kfyHbtKrvcmBpNgS2sIye5uFbemIkDce0SHRxkZJ/FormkJ8I dO5viNDeJ9P/nLqCxZXSRrw/OKWRR7oGs4ULQFXUYhGZHP8BO5N6723g8rwUESVF7Ruc 6ntlkhKGQQpQFhZb1515chWE/sA9TzJM9FBCNELOuOKetC4OnufGnFfdXo5yU/9ErbgN oeb9e3TPrp8Xlguy6gr0Me1hWBJvYY/7lOeYtu8zcAyg/VmSUkPkkdLD+N0E8H3yCzjS enid938SxtlLBkZ44QJCRw9lwlxDXCjfbUP87ZBhbWghAXvS0gIixJuZmJeYMynPTYWF A87g== 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=/YpQ7s4G/E1tLtWoceL1+Bh1rczCTw/qrCJmv6ax4bw=; b=BekuDwa1VJlf0UW8jbh1VA6rx8q6yZJWEwRbCvEQ+G7awwFPHDA+6ZAAW3zxeLqX8S J8TN1hsQt9tcMDAqhDEqZytFvKq5Sbr4xkYhKqSQ9Fs5CTvsBNYQVd3tiAQIYb5sP/Xj EzK0ceaUHmQLe7/M0EDsVLosQ7d++R55RRZVhtOPtdT5Tuo+4qSTn0mlMKp4ADGVuHhg Btmp7mq3BbgA+1apxCckDgV6Lz1WGHEm3i49rDlVTE0k/kQpaUGQJ/fdRQRU8em07Jrs IopHxzYpeR3X2UC9zGzXoAyzMEHmndYuuLHWO6EWjuQAEMRH8Fa910w/VUIgLBTeHMGe zPgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IBbSC5Rv; 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 q10-20020a1709066aca00b0078db8fe2834si25411688ejs.245.2022.10.24.06.31.59; Mon, 24 Oct 2022 06:32:25 -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=IBbSC5Rv; 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 S233444AbiJXMV4 (ORCPT + 99 others); Mon, 24 Oct 2022 08:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbiJXMTq (ORCPT ); Mon, 24 Oct 2022 08:19:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB40F753B9; Mon, 24 Oct 2022 04:58:34 -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 A71A461278; Mon, 24 Oct 2022 11:44:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6F60C433D6; Mon, 24 Oct 2022 11:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611852; bh=5Iqm60SwyyyRfJTCk22dEZia1Xh8h760FMFhJi50/Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IBbSC5Rv6funo+s+4ddbfw5c8SixcdkAs8OtTpaVZpQqaNWxdqIKkk4hHzvu0BLxL znLS0VBPeQiKOk7UhGgbOSw6zh0eoNcs+/p2WiRieJgCQvbP1j7lf7J56LnFhl78Wb tzrenB2p7VW6shm9RveEwP0h9Q2sce4rvdz2MM9o= 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.9 135/159] Bluetooth: L2CAP: Fix user-after-free Date: Mon, 24 Oct 2022 13:31:29 +0200 Message-Id: <20221024112954.396342352@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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 42df17fa7f16..ec04a7ea5537 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4039,6 +4039,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); @@ -4068,6 +4074,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