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 CDFD27FA for ; Mon, 24 Jul 2023 01:32:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECB8DC433D9; Mon, 24 Jul 2023 01:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162330; bh=VWn7I8aeOGGxbqba3PmdYM9O7ZKxNndmWAI4lNJd0nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hwPBp819TecWumj6uZkymau1WW2ikZymIXJzT4mvo3ofHWIk+UoJY9SkZDFNawKuA QijjltEbGmz0VVQVoW2LVz+rRyKLs5xzappYu0LRTldhIRa0UldzELDFLPYUhacs0Y DLCEVWhWNZWn9Wb4CqK6dVxymUZJe0M6YStrn3EjDzQaeS7EigQqJJuJvgdrOfguLU EIBtPTadQDDQQRk84b4ghxPtlFR4icoUJHmXImvVNneMiJ5mCB3uUi3CRRDyEdvCE9 IG9X9V2Pp65qig15MrwM9As2xD310E47pgKyqsDcwk0Fufo0JIFJYRLSF/8fhiZDK0 4WCefD41aFAGg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhengping Jiang , Luiz Augusto von Dentz , Jakub Kicinski , Sasha Levin , marcel@holtmann.org, gustavo@padovan.org, johan.hedberg@gmail.com, davem@davemloft.net, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.4 21/40] Bluetooth: L2CAP: Fix use-after-free Date: Sun, 23 Jul 2023 21:31:21 -0400 Message-Id: <20230724013140.2327815-21-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013140.2327815-1-sashal@kernel.org> References: <20230724013140.2327815-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.5 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 c5e8798e297ca..17ca13e8c044c 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -6374,9 +6374,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.39.2