Skip to content

[PW_SID:1168176] Bluetooth: hci_core: Fix leak of request command on tx timeout - #786

Open
BluezTestBot wants to merge 1 commit into
workflowfrom
1168176
Open

BluezTestBot wants to merge 1 commit into
workflowfrom
1168176

Conversation

@BluezTestBot

Copy link
Copy Markdown

When a command transmission times out, hci_cmd_timeout() calls
hci_cmd_sync_cancel_sync() to mark the pending request as
HCI_REQ_CANCELED and wake up the waiter. However, nothing releases
the request command skb in this path: hci_cmd_sync_complete(), the
only place which frees hdev->req_skb during normal operation, bails
out early because the request status is no longer HCI_REQ_PEND.
Since commit f5afdff ("Bluetooth: hci_core: use skb_get()
instead of skb_clone() for req_skb"), hdev->req_skb holds an extra
reference to the same skb object as hdev->sent_cmd, so both pointers
keep the buffer alive and it leaks unless the device is closed,
which a fuzzer never does. This is the leak reported by kmemleak as
"memory leak in __hci_cmd_sync_sk".

Free the request command and the last sent command on the timeout
path and clear HCI_CMD_PENDING, mirroring the cleanup done by
hci_dev_close_sync(). This is safe because the waiter has already
been woken up and later command completion events tolerate a NULL
sent_cmd/req_skb via the hci_cmd_data() NULL checks.

Fixes: 63298d6 ("Bluetooth: hci_core: Cancel request on command timeout")
Signed-off-by: Jiakai Xu xujiakai24@mails.ucas.ac.cn

net/bluetooth/hci_core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

When a command transmission times out, hci_cmd_timeout() calls
hci_cmd_sync_cancel_sync() to mark the pending request as
HCI_REQ_CANCELED and wake up the waiter. However, nothing releases
the request command skb in this path: hci_cmd_sync_complete(), the
only place which frees hdev->req_skb during normal operation, bails
out early because the request status is no longer HCI_REQ_PEND.
Since commit f5afdff ("Bluetooth: hci_core: use skb_get()
instead of skb_clone() for req_skb"), hdev->req_skb holds an extra
reference to the same skb object as hdev->sent_cmd, so both pointers
keep the buffer alive and it leaks unless the device is closed,
which a fuzzer never does. This is the leak reported by kmemleak as
"memory leak in __hci_cmd_sync_sk".

Free the request command and the last sent command on the timeout
path and clear HCI_CMD_PENDING, mirroring the cleanup done by
hci_dev_close_sync(). This is safe because the waiter has already
been woken up and later command completion events tolerate a NULL
sent_cmd/req_skb via the hci_cmd_data() NULL checks.

Fixes: 63298d6 ("Bluetooth: hci_core: Cancel request on command timeout")
Signed-off-by: Jiakai Xu <xujiakai24@mails.ucas.ac.cn>
@github-actions

Copy link
Copy Markdown

CheckPatch
Desc: Run checkpatch.pl script
Duration: 1.55 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

GitLint
Desc: Run gitlint
Duration: 0.29 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

CheckKernelLLVM
Desc: Build kernel with LLVM + context analysis
Duration: 32.98 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

Total: 501, Passed: 496 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.031 seconds

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

TestRunner_mesh-tester
Desc: Run mesh-tester with test-runner
Duration: 8.18 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.451 seconds
Mesh - Send cancel - 2                               Timed out    1.998 seconds

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

IncrementalBuild
Desc: Incremental build with the patches in the series
Duration: 25.94 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