Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp2020lqj; Thu, 11 Apr 2024 08:20:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIhdy6dL0BKXhiCRxZ/nTr2iCgHiS6sM/F5lfzXqRkUn89Zek9SfoOZykKrL6itDVcQYfxRN9GhK0M9K/2Eksa167i5IO+r8tNk9s6ug== X-Google-Smtp-Source: AGHT+IFronSIbhilmw2CbVVERXIDrFgJtXbFLaPZmAvj5NhrLqD4kMCxC0gRno8g2xQWQnAaQl28 X-Received: by 2002:a05:620a:4606:b0:78e:c66d:a2cf with SMTP id br6-20020a05620a460600b0078ec66da2cfmr1419302qkb.76.1712848821035; Thu, 11 Apr 2024 08:20:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712848821; cv=pass; d=google.com; s=arc-20160816; b=dkFcIh3Ds5Bwqa3G7NYxoH0nTUx/Ud6VnlQkyCTWPrJ0FA37oAzCEu/K5Jdj1jxm2A miiyUN4AidzO8Pur2OvPeaufiD1p2trJjnBJacGEuOTgXw8/RGeT1z63eAALV7UwEUxr OxD0VzXaAOXFxiH7OOQr1K+DC/kvxyx3hz3VEsGzcExnhGFslVaAumdtSmcCCd40Z6tM R48Xp09D9QnB4h6x6Qp1QxtotRWS/iK8ijjDw3EWHkOyZoP4qjKcj7BWFf2MbYiWJBDY RX8oUFW+m3IaW2VVRcbCoPUFhNDyuhbJcUPLidFkH06w7ysnIgj6TxtS9OBpF2ia+jZ6 84Ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=r5Vcyr9jp6fOfofolcqIQDGT8gfPJ7NuQph8YGAK0W4=; fh=MRjJ7i1k8P4Ay2whq8CFG/8PhbbbZaupVlyKoaRKnIc=; b=dsZIetb7Nz24rB3boss9tjsAe5mjfh58bz8jVSRkRZ5kR64DKjPr4Mc+fNcL7HWzsO JuLt2KlgV+sZaZ5k4ofZN+yoNJm7DFvPWjrMYaxxbVSvnOLuL33I1g2WW5yMcmXpGfRR FANWW06BMIuFjOlzu/6lMIUzbhZ+Yz83YYBgf84lqS7rQEFX3pcjjcW63LvDniU23puB AokX+mVyTcZjE2Qw2qjBwAd/oqNjNBiFdTSK0nFr+9kC9MW5rbBDUq/yvTKT80AZWYVX 3rP70VzvCFuwnpAFVgJnv53QXQWkWtNLOmhEE17gx9ZGng7Wm6D3fg6MihOA8pDDANqK MXkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=altlinux.org); spf=pass (google.com: domain of linux-bluetooth+bounces-3482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3482-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i21-20020a05620a405500b0078d64741b2esi1918143qko.374.2024.04.11.08.20.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 08:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-3482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=altlinux.org); spf=pass (google.com: domain of linux-bluetooth+bounces-3482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3482-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C00F61C20F06 for ; Thu, 11 Apr 2024 15:20:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDC2114A83; Thu, 11 Apr 2024 15:19:40 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from air.basealt.ru (air.basealt.ru [194.107.17.39]) (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 D383914005; Thu, 11 Apr 2024 15:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.39 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712848780; cv=none; b=gh1BPYN6MhSCGCvbDIv/kDzwoWxmq6jVLvXqbnt5nxSS/GnT0VlOkhKHL89263D8D3/2R9YMfzwNrFV8NSGtJE+r38oetctc0z+rUSUP7yt9dSoVzsgmTGeUXcKLSa04HzZk0RTE99qp7PWWjFcQbCnDQOaB+VzCUterJKExW9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712848780; c=relaxed/simple; bh=7KQj8Ij5Bz+/jmiRyKCdBwrOjqQu8Ro0c+7Db6XxeZk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=s+1L0rviCQggdpGB4TRz8ZlA1HTWxBEHliO0BfGbBo/2gexL8WloIKFsQLtw2fRaHu3z+l0yll+xU1+ZhaxxADt2tsFqc0Nuqxd/1qAUuNbhowBZ0w2SWM9hRpnUjD1kStv0fiM9xgNS/dd57qyb8VmopzDo0uTBXwR5P4tO8JU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.39 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: by air.basealt.ru (Postfix, from userid 490) id 3DFF42F2023F; Thu, 11 Apr 2024 15:19:36 +0000 (UTC) X-Spam-Level: Received: from altlinux.malta.altlinux.ru (obninsk.basealt.ru [217.15.195.17]) by air.basealt.ru (Postfix) with ESMTPSA id C29D82F20238; Thu, 11 Apr 2024 15:19:34 +0000 (UTC) From: kovalev@altlinux.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kovalev@altlinux.org, stable@vger.kernel.org Subject: [PATCH net] Bluetooth: hci_event: fix possible multiple drops by marked conn->state after hci_disconnect() Date: Thu, 11 Apr 2024 18:19:29 +0300 Message-Id: <20240411151929.403263-1-kovalev@altlinux.org> X-Mailer: git-send-email 2.33.8 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Vasiliy Kovalev When returning from the hci_disconnect() function, the conn->state continues to be set to BT_CONNECTED and hci_conn_drop() is executed, which decrements the conn->refcnt. Syzkaller has generated a reproducer that results in multiple calls to hci_encrypt_change_evt() of the same conn object. -- hci_encrypt_change_evt(){ // conn->state == BT_CONNECTED hci_disconnect(){ hci_abort_conn(); } hci_conn_drop(); // conn->state == BT_CONNECTED } -- This behavior can cause the conn->refcnt to go far into negative values and cause problems. To get around this, you need to change the conn->state, namely to BT_DISCONN, as it was before. Fixes: a13f316e90fd ("Bluetooth: hci_conn: Consolidate code for aborting connections") Cc: stable@vger.kernel.org Signed-off-by: Vasiliy Kovalev --- net/bluetooth/hci_event.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 64477e1bde7cec..e0477021183f9b 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2989,6 +2989,7 @@ static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_conn_drop(conn); + conn->state = BT_DISCONN; unlock: hci_dev_unlock(hdev); @@ -3654,6 +3655,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, hci_encrypt_cfm(conn, ev->status); hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_conn_drop(conn); + conn->state = BT_DISCONN; goto unlock; } @@ -5248,6 +5250,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data, if (ev->status && conn->state == BT_CONNECTED) { hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_conn_drop(conn); + conn->state = BT_DISCONN; goto unlock; } -- 2.33.8