From patchwork Wed Oct 19 08:33:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp224114wrs; Wed, 19 Oct 2022 02:39:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7OFm0fTzj0e48/FHKcyJypuDD/EUfPyr/JaQO4awq6mvxh/BBaM7N1T5gTCB3Taoeg5+mE X-Received: by 2002:a17:906:730e:b0:78d:94ab:77c2 with SMTP id di14-20020a170906730e00b0078d94ab77c2mr5972112ejc.639.1666172366220; Wed, 19 Oct 2022 02:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172366; cv=none; d=google.com; s=arc-20160816; b=PN+bCWnv6rk6DR+eMsCq4asAiTmQeZtZqOYeGaiwUlmSH1viwv+CEYLOnu4ijnYEdL ev46aaWLW04wPeEDnJllgcCFqkAPL2FFbqu1R+4C9obbnQL8ARpXevDs4QaZk4yNj9Oi Ua0ob+zPLB8UfrqCkmvidF7DU07U8VUK8r0pIH6YMqvdhWksaRnodEa2kPjichLBoDaq dtS+KSj/VTTGUCQkqzesFRKU+rY52RookDCibexcJXEUc0TPa+UinC2BoZ1tEgmjhfZ2 GIT041AP2+xngCgq2FeMmO4GlFONTGUCeSY0K8ChWnzMhrDveTnYTxjnkQ/x7zcMY8xe e6mA== 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=JYy/cfgJipBUWZK6N2+sye3/4gsGYkjBBSeohR2679I=; b=xRezGAzg1bF/glmHUbm7ObL3X1BeOrXTDQpFADz8k6FbeHkGyJpD4hh7KHCQlYfV5+ wms4LAarT1nfh6bIFzKfUvN2EzeKPRamngmXn7bsdeYBzbkcRknYYEpHrTIgbffPe/dt cGYMyefgXR/KzUW3KdyBdP8VmsfHyAEES3NcPTbfIfI1jRUpw18TLS9h/lhqOCm/xNfD WHXQ5ozG7J2b3SxJagm8fiGh5fl1u3YuB3BsqOe9MTHUrtu/MEx8PC+KVVd62M0gNX4q ANFovIpBetZMI/NKALsUOA+Lbji4hWMwhw4Q2Ef2YsC5UrM1Cb2KmTGxtdUqxi98SLbn yJoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JKIPBJO5; 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 w19-20020a1709062f9300b007803b5893f2si12565748eji.672.2022.10.19.02.39.01; Wed, 19 Oct 2022 02:39:26 -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=JKIPBJO5; 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 S233513AbiJSJ2r (ORCPT + 99 others); Wed, 19 Oct 2022 05:28:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233508AbiJSJ1O (ORCPT ); Wed, 19 Oct 2022 05:27:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01123C6962; Wed, 19 Oct 2022 02:12:10 -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 1595661840; Wed, 19 Oct 2022 09:10:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 257BBC43470; Wed, 19 Oct 2022 09:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170616; bh=a00U9GHBoFljlewPFnHrOgja+rsegUW3jaFRMRIvNCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JKIPBJO5kw5sqCwxmSEI6JNuDXVkKgyiJfjHlwFJn48remV6h3E+rlHDEFvg8rG4M uKunx1n+FlzRXfEISBd4j2rehRM4Dtmcc+/4FSx0P11V46F4pU+KuHZLLjZjEW7dH2 q+vOFjd2e57KmEJeV5GXi2HbnsDSTuvBRYrzrO2s= 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 6.0 723/862] Bluetooth: L2CAP: Fix user-after-free Date: Wed, 19 Oct 2022 10:33:30 +0200 Message-Id: <20221019083321.870305290@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747108354859481923?= X-GMAIL-MSGID: =?utf-8?q?1747108354859481923?= 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 770891f68703..1f34b82ca0ec 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4309,6 +4309,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); @@ -4338,6 +4344,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);