Skip to content

[PW_SID:1104138] Bluetooth: eir: Fix stack OOB write in eir_create_adv_data()#269

Open
BluezTestBot wants to merge 1 commit into
workflowfrom
1104138
Open

[PW_SID:1104138] Bluetooth: eir: Fix stack OOB write in eir_create_adv_data()#269
BluezTestBot wants to merge 1 commit into
workflowfrom
1104138

Conversation

@BluezTestBot
Copy link
Copy Markdown

From: Weiming Shi bestswngs@gmail.com

eir_create_adv_data() builds the advertising data into a fixed-size
buffer of "size" bytes (31 for the legacy path in hci_set_adv_data_sync()).
It may prepend a 3-byte "Flags" AD structure, but the per-instance
advertising data is then copied without checking that it still fits:

skip_flags:
if (adv) {
memcpy(ptr, adv->adv_data, adv->adv_data_len);

The "Flags" structure is added whenever BR/EDR is disabled
(LE_AD_NO_BREDR), which is the normal state for an LE-only controller.
However, the mgmt length validator tlv_data_max_len() only reserves
those 3 bytes when the user-supplied adv_flags carries a managed-flags
bit (DISCOV / LIMITED_DISCOV / MANAGED_FLAGS). Adding an instance with
flags == 0 reserves nothing, so adv_data_len is accepted up to the full
buffer size. At advertise time the 3 flag bytes are still prepended,
and the subsequent memcpy() writes 3 + adv_data_len bytes into the
size-byte buffer, overflowing it by the attacker-controlled tail of
adv_data:

BUG: KASAN: stack-out-of-bounds in eir_create_adv_data (net/bluetooth/eir.c:302)
Write of size 31 at addr ffff88800b7e7bac by task kworker/u9:0/51
Workqueue: hci0 hci_cmd_sync_work
__asan_memcpy (mm/kasan/shadow.c:106)
eir_create_adv_data (net/bluetooth/eir.c:302)
hci_update_adv_data_sync (net/bluetooth/hci_sync.c:1689)
hci_schedule_adv_instance_sync (net/bluetooth/hci_sync.c:2015)
hci_cmd_sync_work (net/bluetooth/hci_sync.c:332)
This frame has 1 object:
[32, 64) 'cp'

The inconsistency dates back to when the managed "Flags" field was first
added to the Add Advertising path: the prepended LE_AD_NO_BREDR flag does
not depend on the user-supplied adv_flags, but tlv_data_is_valid() only
reserved room when MGMT_ADV_FLAG_DISCOV was set. Commit 47c0390
("Bluetooth: eir: Fix possible crashes on eir_create_adv_data") later
added the "size" argument and bounds-checked the "Flags" and "Tx Power"
AD structures, but left this copy unguarded. Guard it the same way so
the data is only copied when it fits.

The bug is reachable by a local user with CAP_NET_ADMIN that owns an
LE-only controller using the legacy advertising path.

Fixes: b44133f ("Bluetooth: Support the "discoverable" adv flag")
Reported-by: Xiang Mei xmei5@asu.edu
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Weiming Shi bestswngs@gmail.com

net/bluetooth/eir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

eir_create_adv_data() builds the advertising data into a fixed-size
buffer of "size" bytes (31 for the legacy path in hci_set_adv_data_sync()).
It may prepend a 3-byte "Flags" AD structure, but the per-instance
advertising data is then copied without checking that it still fits:

skip_flags:
	if (adv) {
		memcpy(ptr, adv->adv_data, adv->adv_data_len);

The "Flags" structure is added whenever BR/EDR is disabled
(LE_AD_NO_BREDR), which is the normal state for an LE-only controller.
However, the mgmt length validator tlv_data_max_len() only reserves
those 3 bytes when the user-supplied adv_flags carries a managed-flags
bit (DISCOV / LIMITED_DISCOV / MANAGED_FLAGS). Adding an instance with
flags == 0 reserves nothing, so adv_data_len is accepted up to the full
buffer size. At advertise time the 3 flag bytes are still prepended,
and the subsequent memcpy() writes 3 + adv_data_len bytes into the
size-byte buffer, overflowing it by the attacker-controlled tail of
adv_data:

  BUG: KASAN: stack-out-of-bounds in eir_create_adv_data (net/bluetooth/eir.c:302)
  Write of size 31 at addr ffff88800b7e7bac by task kworker/u9:0/51
  Workqueue: hci0 hci_cmd_sync_work
   __asan_memcpy (mm/kasan/shadow.c:106)
   eir_create_adv_data (net/bluetooth/eir.c:302)
   hci_update_adv_data_sync (net/bluetooth/hci_sync.c:1689)
   hci_schedule_adv_instance_sync (net/bluetooth/hci_sync.c:2015)
   hci_cmd_sync_work (net/bluetooth/hci_sync.c:332)
  This frame has 1 object:
   [32, 64) 'cp'

The inconsistency dates back to when the managed "Flags" field was first
added to the Add Advertising path: the prepended LE_AD_NO_BREDR flag does
not depend on the user-supplied adv_flags, but tlv_data_is_valid() only
reserved room when MGMT_ADV_FLAG_DISCOV was set. Commit 47c0390
("Bluetooth: eir: Fix possible crashes on eir_create_adv_data") later
added the "size" argument and bounds-checked the "Flags" and "Tx Power"
AD structures, but left this copy unguarded. Guard it the same way so
the data is only copied when it fits.

The bug is reachable by a local user with CAP_NET_ADMIN that owns an
LE-only controller using the legacy advertising path.

Fixes: b44133f ("Bluetooth: Support the "discoverable" adv flag")
Reported-by: Xiang Mei <xmei5@asu.edu>
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

CheckPatch
Desc: Run checkpatch.pl script
Duration: 0.78 seconds
Result: FAIL
Output:

Bluetooth: eir: Fix stack OOB write in eir_create_adv_data()
WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report
#146: 
Reported-by: Xiang Mei <xmei5@asu.edu>
Assisted-by: Claude:claude-opus-4-8

total: 0 errors, 1 warnings, 0 checks, 8 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14605450.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

VerifyFixes
Desc: Verify Fixes tag format and validity
Duration: 0.14 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

VerifySignedoff
Desc: Verify Signed-off-by chain
Duration: 0.14 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

GitLint
Desc: Run gitlint
Duration: 0.40 seconds
Result: FAIL
Output:

Bluetooth: eir: Fix stack OOB write in eir_create_adv_data()

11: B3 Line contains hard tab characters (\t): "	if (adv) {"
12: B3 Line contains hard tab characters (\t): "		memcpy(ptr, adv->adv_data, adv->adv_data_len);"
25: B1 Line exceeds max length (82>80): "  BUG: KASAN: stack-out-of-bounds in eir_create_adv_data (net/bluetooth/eir.c:302)"

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

SubjectPrefix
Desc: Check subject contains "Bluetooth" prefix
Duration: 0.13 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

BuildKernel
Desc: Build Kernel for Bluetooth
Duration: 28.38 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

CheckAllWarning
Desc: Run linux kernel with all warning enabled
Duration: 31.35 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

CheckSparse
Desc: Run sparse tool with linux kernel
Duration: 30.08 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

BuildKernel32
Desc: Build 32bit Kernel for Bluetooth
Duration: 27.75 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunnerSetup
Desc: Setup kernel and bluez for test-runner
Duration: 606.70 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_l2cap-tester
Desc: Run l2cap-tester with test-runner
Duration: 64.46 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_iso-tester
Desc: Run iso-tester with test-runner
Duration: 93.80 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_bnep-tester
Desc: Run bnep-tester with test-runner
Duration: 19.81 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_mgmt-tester
Desc: Run mgmt-tester with test-runner
Duration: 220.39 seconds
Result: FAIL
Output:

Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.257 seconds

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_rfcomm-tester
Desc: Run rfcomm-tester with test-runner
Duration: 26.70 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_sco-tester
Desc: Run sco-tester with test-runner
Duration: 33.44 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_ioctl-tester
Desc: Run ioctl-tester with test-runner
Duration: 27.01 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_mesh-tester
Desc: Run mesh-tester with test-runner
Duration: 26.98 seconds
Result: FAIL
Output:

Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    2.782 seconds
Mesh - Send cancel - 2                               Timed out    1.991 seconds

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_smp-tester
Desc: Run smp-tester with test-runner
Duration: 23.79 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_userchan-tester
Desc: Run userchan-tester with test-runner
Duration: 20.52 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

TestRunner_6lowpan-tester
Desc: Run 6lowpan-tester with test-runner
Duration: 23.05 seconds
Result: PASS

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

IncrementalBuild
Desc: Incremental build with the patches in the series
Duration: 32.28 seconds
Result: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants