From nobody Mon Jun 8 05:25:29 2026 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0713F44CB for ; Tue, 2 Jun 2026 17:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780420001; cv=none; b=RbVnaF1T2DR/K90CZEqW9pPV/oj++OQaRl+QlvFD2/J+Mpt1bQjUumiJXhpV4cFZhQ0eWQDm+U3k/vUKemdPC61YgoQWv8oO2PTVOKxWV3Runc95sj7NPQTWq9tT51b6M8sKGa2QgT/q6OsIWj4BqWLe26B6cne8c3ynt1vGvZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780420001; c=relaxed/simple; bh=Bl3uE87V4+Vf8cpIROkGPVGhCj5LvqUs/uEkG8IUj6M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SHRsgru3mFa39Q8LZ4xQudlSfHoSNSIf84Ofx3bJasJNGGz6CLFxsmxMAxOJbT92Fh4vAqQSFprtV24ljdOE1bCOWaru/v1wgelvyH3ANtjIdEOPZo7UlmRJkZHCTiK7FMxrfrxcr/aolti3QvZGO96yaUUxvuZdzkjFvKIf6Fo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NAFoBobu; arc=none smtp.client-ip=74.125.82.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NAFoBobu" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-137dd3af345so2608212c88.0 for ; Tue, 02 Jun 2026 10:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780419999; x=1781024799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YfY3gW1bToFTm6OdfmLQuzmiuL3/uQdYF//iDFnkcOo=; b=NAFoBobuQtgopFK5GaDSl+gw/r8ku1tG8x89qbjqRwmHAY1JqKUAT6tUnIIO3HRb0+ WjF7T8gKE9/DCBZZs3oEsLO6IMMvXZUIKkyMQNKkVqZ9R7iHB8/ROee/1OvAD96PGl8o bktBanho0/L2RyHnc7OReEL09LooX3WOGe2RIK4SEMtpmWiFL1CAtb9PwdhgiG89IdnF scH0BwPq24Nsy88SKK5ySkMEcuTQtn0M1i4hmv8CUYwNN6tDHSaVsOOcFrtxlcVqC2/l o/7p+7jx9P5zrTbtuTwIhcdTOZeKdg7jXrT8SJiXIlGM/gagfMAvCKUPdmclo1LnFFSd XWgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780419999; x=1781024799; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YfY3gW1bToFTm6OdfmLQuzmiuL3/uQdYF//iDFnkcOo=; b=JILf5KWq2NxqMV40SudlXxPVeSUCUxth61tz5+rfF0jJjRMrzR7yF7AT2N6wuJg9i7 iYEOK+57Dp10CisqvtvXJXHDeXh7Z2LyK9g5tE5yAjCcmlXV//bkZ4xiLkfIauDp/Np3 C4ucHyp1JDNnjlhJKm4ED1JNVrcd2q4tffYFe+0mqrGLHjz6XqRixqImoEtoKhvO2CZp 1X/kL/LYF3yIIkkYxwPI2CtuStR1kqxFZyPEcddHeu+1/IITiqvZyngomiyXFQ1I1v/H ghs3quDrCxD9AJ6PGGFAxkNBORWc1/r4KO5hQDgqIWAwGQnrWsR/+/veJ9uGIeYkVmuq KdYA== X-Forwarded-Encrypted: i=1; AFNElJ81v+t0COwED2rZUT4p7ChFRPYXNsKhienr90mMFO3TCFWObrBtfybSJ3J6VtM4fCTfRTbKXGoZGEAdhMY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+8p0DRBh0msCf1kAPQ6BRH91NnYZIyOvqL0GGMAUPaG7JeHa8 wkJdouj3veoQlRT+IquG1wrbfQSupX1uSh0QWS23/wIqE5uuZjKIjjMr X-Gm-Gg: Acq92OHpLxi6ywC/Mlr05XeDYqUYIY/DQbfYtjJ93bcRvOYj0aMrdwVOM9cN1wauqES xE0mBONAf3V1LDUfRZ6GA6Jrs5EBHnBS7y7+0z8zC7kHec7gFguUa1aOZT/GFAAVP4Fzn/gFH5k MtBas9kUjYEi2U3OwE5yDEhXWnnzDNfxLxr2LDQUJBDSmgcCDzKm0pY46ao1JP3xIXGBpYA4kG8 oSu47Vf/i4fOAfA6mz8nn/y7XD2vcxehYBIaEON8ncqPDMRVHAfiH/6VxlvJy07ixLFtf+cvjUH 5LzxVx2H9bqjKB9OFn4rqvXRrgn2ETF9lQJzkj/bmnspXc+jkLQLH29MtHeF6aD/JGtdaf46jwG 9YYR6rmRrk8eXiXdpvx++YRTlb4QkqIEImKZIaNrrlxXJH0jJEp2Eern9CWD8WHutRwTCHw3nvy rN1Yj0C3LNjhW3ohlo7FFAnciPVSyZ9dvmWAnYeTeJMz6pEWCtFR5hB5pS/iAF9kk2o73zB4w4h yVpVENqdejjct9wskJsH7U= X-Received: by 2002:a05:7022:ec88:b0:12d:de3f:d84e with SMTP id a92af1059eb24-137d42c2977mr7409925c88.39.1780419999005; Tue, 02 Jun 2026 10:06:39 -0700 (PDT) Received: from SLSGDTSWING002.tail0ac356.ts.net ([129.126.109.177]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-137f53f06c4sm264969c88.0.2026.06.02.10.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 10:06:38 -0700 (PDT) From: Weiming Shi To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Arman Uguray , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Xiang Mei , Weiming Shi Subject: [PATCH v2] Bluetooth: eir: Fix stack OOB write when prepending the Flags AD Date: Wed, 3 Jun 2026 01:06:21 +0800 Message-ID: <20260602170621.1454711-2-bestswngs@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" eir_create_adv_data() builds the advertising data into a fixed-size buffer ("size", 31 for the legacy path). It may prepend a 3-byte "Flags" AD structure (LE_AD_NO_BREDR on an LE-only controller) and then copies the per-instance data without checking that it still fits: memcpy(ptr, adv->adv_data, adv->adv_data_len); tlv_data_max_len() only reserves those 3 bytes when the user-supplied flags carry a managed-flags bit, so an instance added with flags =3D=3D 0 is accepted with adv_data_len up to the full buffer. At advertise time the flags are still prepended, and the memcpy() writes 3 + adv_data_len bytes into the size-byte buffer: BUG: KASAN: stack-out-of-bounds in eir_create_adv_data (net/bluetooth/eir= .c:301) Write of size 31 at addr ffff88800a547bdc by task kworker/u9:0/65 Workqueue: hci0 hci_cmd_sync_work __asan_memcpy (mm/kasan/shadow.c:106) eir_create_adv_data (net/bluetooth/eir.c:301) hci_update_adv_data_sync (net/bluetooth/hci_sync.c:1310) hci_schedule_adv_instance_sync (net/bluetooth/hci_sync.c:1817) hci_cmd_sync_work (net/bluetooth/hci_sync.c:332) This frame has 1 object: [32, 64) 'cp' The "Flags" structure is added by the kernel, not requested by userspace, so only prepend it when it fits together with the instance advertising data; when there is no room for both, drop the flags rather than the user-provided data. Reachable by a local user with CAP_NET_ADMIN owning an LE-only controller on the legacy advertising path. Fixes: b44133ff03be ("Bluetooth: Support the "discoverable" adv flag") Reported-by: Xiang Mei Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Weiming Shi --- v2: drop the kernel-added "Flags" AD when it does not fit with the instance= data, instead of dropping the user data . net/bluetooth/eir.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/eir.c b/net/bluetooth/eir.c index 3f72111ba651..1de5f9df6eec 100644 --- a/net/bluetooth/eir.c +++ b/net/bluetooth/eir.c @@ -283,10 +283,12 @@ u8 eir_create_adv_data(struct hci_dev *hdev, u8 insta= nce, u8 *ptr, u8 size) if (!flags) flags |=3D mgmt_get_adv_discov_flags(hdev); =20 - /* If flags would still be empty, then there is no need to - * include the "Flags" AD field". + /* Only add the "Flags" if it fits together with the instance + * advertising data; drop it rather than overflow the buffer. */ - if (flags && (ad_len + eir_precalc_len(1) <=3D size)) { + if (flags && + (ad_len + eir_precalc_len(1) + + (adv ? adv->adv_data_len : 0) <=3D size)) { ptr[0] =3D 0x02; ptr[1] =3D EIR_FLAGS; ptr[2] =3D flags; --=20 2.43.0