From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2AE9125AE for ; Thu, 24 Aug 2023 14:59:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37CF8C433C8; Thu, 24 Aug 2023 14:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1692889153; bh=3K7DmQgLp+34c6FKhZYLaydjAXccA5YSzHgcxyMpof4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DWS76LHrWnweh9My6pIK/K4p/qZ/46wSWqcGWE1ojbaii9rIuSaozNz+BG3wHU280 GkjmCN+HbUVpbbsYY2D/7uosw4xGa8/Bp/+UENCyehK5aMNTR/YMFkrCveKzKbHoTj Izgip1dYx2QYx4ALksORO34rDrlfZJwl2GDyoOdI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhengping Jiang , Luiz Augusto von Dentz , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 034/135] Bluetooth: L2CAP: Fix use-after-free Date: Thu, 24 Aug 2023 16:49:37 +0200 Message-ID: <20230824145028.397316871@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230824145027.008282920@linuxfoundation.org> References: <20230824145027.008282920@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Zhengping Jiang [ Upstream commit f752a0b334bb95fe9b42ecb511e0864e2768046f ] Fix potential use-after-free in l2cap_le_command_rej. Signed-off-by: Zhengping Jiang Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 568f0f072b3df..7b40e4737a2bb 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -6370,9 +6370,14 @@ static inline int l2cap_le_command_rej(struct l2cap_conn *conn, if (!chan) goto done; + chan = l2cap_chan_hold_unless_zero(chan); + if (!chan) + goto done; + l2cap_chan_lock(chan); l2cap_chan_del(chan, ECONNREFUSED); l2cap_chan_unlock(chan); + l2cap_chan_put(chan); done: mutex_unlock(&conn->chan_lock); -- 2.40.1