Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3CE9A3B52FB for ; Mon, 10 Aug 2026 23:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786405892; cv=none; b=o/ZVroAM1q3cGY4wAN48PGHhhoHyWBwJjBjIYHXgCpDqlq8QoNbhclh253glNdb6J4vmeVB/GyNWkH3mfj3DdRlRDp65h4y7Wq1MsOTNkjiMvNUkc+j8XBjE+IlAQw8LFkPMFghLH5x416DZtZR66e/DfHjWtFoKazoVk87OCiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786405892; c=relaxed/simple; bh=9z+NbXTzM0E/jUOmbbNuYVaKgXNEhKKUJBUwRUCpxNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y2gdr04VR+47w/vwFmHQvSs69bbafi7m9RfWvnj95UcDAQ4vOWcYWn3tfEAcmfERkU5o0zg5/SkbebD5+c+r78cHkgUA97E4Mf53IDTdScxs0/g+EJqMW2LyJml/LhvYJYL9y7GXtaFxC8NYY1fu1QbS+uT5w8v6EqsJtZL6oxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gmFOfgMZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gmFOfgMZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88A361F00A3D; Mon, 10 Aug 2026 23:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786405891; bh=F3DzMJ3JInX7NXKx9KI22Fe2essJZdQbMhd5FLVlqM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gmFOfgMZ0yCiPD9xY924CWGRDHvbAmCvW/Axy0Gqo8oB5+1jfmtGaUSEXE2otlHVI 3fw5B/nysXa8qzaE3aqBnoWicRiJGwNgjfm79wrwHW6qGghQDpnaCnL9POQYqrIZ5a hTQwnS3hg1SOIRnjVwonQbzccafuC2KqGYWy7llous4t2piPHRTkiCiNMaor57stA4 wXZqZ1oFZ+djT9CZAsPzPhClEk08m5B27mtnn1jj+1FbOfQGtAeAo1wmDTmiMYZKru xTg5EglR/J76+05Khh9dyxp8XAJDNOIhfoebH2dc8umQ6wKFQWvS52lbFm7SPcoS2w wClZmXs3eJiPg== From: Sasha Levin To: stable@vger.kernel.org Cc: Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.6.y 6/7] Bluetooth: eir: Fix possible crashes on eir_create_adv_data Date: Mon, 10 Aug 2026 19:51:23 -0400 Message-ID: <20260810235124.3217231-6-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260810235124.3217231-1-sashal@kernel.org> References: <2026080500-repeater-crust-fca2@gregkh> <20260810235124.3217231-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz [ Upstream commit 47c03902269aff377f959dc3fd94a9733aa31d6e ] eir_create_adv_data may attempt to add EIR_FLAGS and EIR_TX_POWER without checking if that would fit. Link: https://github.com/bluez/bluez/issues/1117#issuecomment-2958244066 Fixes: 01ce70b0a274 ("Bluetooth: eir: Move EIR/Adv Data functions to its own file") Signed-off-by: Luiz Augusto von Dentz Stable-dep-of: cdc36db204ff ("Bluetooth: hci_sync: Fix advertising data UAFs") Signed-off-by: Sasha Levin --- net/bluetooth/eir.c | 7 ++++--- net/bluetooth/eir.h | 2 +- net/bluetooth/hci_sync.c | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/eir.c b/net/bluetooth/eir.c index 3e1713673ecc9..3f72111ba651f 100644 --- a/net/bluetooth/eir.c +++ b/net/bluetooth/eir.c @@ -242,7 +242,7 @@ u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) return ad_len; } -u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) +u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr, u8 size) { struct adv_info *adv = NULL; u8 ad_len = 0, flags = 0; @@ -286,7 +286,7 @@ u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) /* If flags would still be empty, then there is no need to * include the "Flags" AD field". */ - if (flags) { + if (flags && (ad_len + eir_precalc_len(1) <= size)) { ptr[0] = 0x02; ptr[1] = EIR_FLAGS; ptr[2] = flags; @@ -316,7 +316,8 @@ u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) } /* Provide Tx Power only if we can provide a valid value for it */ - if (adv_tx_power != HCI_TX_POWER_INVALID) { + if (adv_tx_power != HCI_TX_POWER_INVALID && + (ad_len + eir_precalc_len(1) <= size)) { ptr[0] = 0x02; ptr[1] = EIR_TX_POWER; ptr[2] = (u8)adv_tx_power; diff --git a/net/bluetooth/eir.h b/net/bluetooth/eir.h index 0df19f2f4af94..4497f8fd5fefb 100644 --- a/net/bluetooth/eir.h +++ b/net/bluetooth/eir.h @@ -9,7 +9,7 @@ void eir_create(struct hci_dev *hdev, u8 *data); -u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr); +u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr, u8 size); u8 eir_create_scan_rsp(struct hci_dev *hdev, u8 instance, u8 *ptr); u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr); diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 57756cd615acf..a947738ed50df 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1308,7 +1308,8 @@ static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) return 0; } - len = eir_create_adv_data(hdev, instance, pdu->data); + len = eir_create_adv_data(hdev, instance, pdu->data, + HCI_MAX_EXT_AD_LENGTH); pdu->length = len; pdu->handle = adv ? adv->handle : instance; @@ -1339,7 +1340,7 @@ static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance) memset(&cp, 0, sizeof(cp)); - len = eir_create_adv_data(hdev, instance, cp.data); + len = eir_create_adv_data(hdev, instance, cp.data, sizeof(cp.data)); /* There's nothing to do if the data hasn't changed */ if (hdev->adv_data_len == len && -- 2.53.0