public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
@ 2025-11-20 16:12 Douglas Anderson
  2025-11-20 16:41 ` [v3] " bluez.test.bot
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Douglas Anderson @ 2025-11-20 16:12 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: Thorsten Leemhuis, regressions, incogcyberpunk, johan.hedberg,
	sean.wang, Douglas Anderson, stable, linux-arm-kernel,
	linux-bluetooth, linux-kernel, linux-mediatek

In btusb_mtk_setup(), we set `btmtk_data->isopkt_intf` to:
  usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM)

That function can return NULL in some cases. Even when it returns
NULL, though, we still go on to call btusb_mtk_claim_iso_intf().

As of commit e9087e828827 ("Bluetooth: btusb: mediatek: Add locks for
usb_driver_claim_interface()"), calling btusb_mtk_claim_iso_intf()
when `btmtk_data->isopkt_intf` is NULL will cause a crash because
we'll end up passing a bad pointer to device_lock(). Prior to that
commit we'd pass the NULL pointer directly to
usb_driver_claim_interface() which would detect it and return an
error, which was handled.

Resolve the crash in btusb_mtk_claim_iso_intf() by adding a NULL check
at the start of the function. This makes the code handle a NULL
`btmtk_data->isopkt_intf` the same way it did before the problematic
commit (just with a slight change to the error message printed).

Reported-by: IncogCyberpunk <incogcyberpunk@proton.me>
Closes: http://lore.kernel.org/r/a380d061-479e-4713-bddd-1d6571ca7e86@leemhuis.info
Fixes: e9087e828827 ("Bluetooth: btusb: mediatek: Add locks for usb_driver_claim_interface()")
Cc: stable@vger.kernel.org
Tested-by: IncogCyberpunk <incogcyberpunk@proton.me>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v3:
- Added Cc to stable.
- Added IncogCyberpunk Tested-by tag.
- v2: https://patch.msgid.link/20251119092641.v2.1.I1ae7aebc967e52c7c4be7aa65fbd81736649568a@changeid

Changes in v2:
- Rebase atop commit 529ac8e706c3 ("Bluetooth: ... mtk iso interface")
- v1: https://patch.msgid.link/20251119085354.1.I1ae7aebc967e52c7c4be7aa65fbd81736649568a@changeid

 drivers/bluetooth/btusb.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index fcc62e2fb641..683ac02e964b 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2751,6 +2751,11 @@ static void btusb_mtk_claim_iso_intf(struct btusb_data *data)
 	if (!btmtk_data)
 		return;
 
+	if (!btmtk_data->isopkt_intf) {
+		bt_dev_err(data->hdev, "Can't claim NULL iso interface");
+		return;
+	}
+
 	/*
 	 * The function usb_driver_claim_interface() is documented to need
 	 * locks held if it's not called from a probe routine. The code here
-- 
2.52.0.rc1.455.g30608eb744-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-20 16:12 [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref Douglas Anderson
@ 2025-11-20 16:41 ` bluez.test.bot
  2025-11-20 17:04 ` [PATCH v3] " Paul Menzel
  2025-11-20 18:50 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 8+ messages in thread
From: bluez.test.bot @ 2025-11-20 16:41 UTC (permalink / raw)
  To: linux-bluetooth, dianders

[-- Attachment #1: Type: text/plain, Size: 2297 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1025911

---Test result---

Test Summary:
CheckPatch                    PENDING   0.32 seconds
GitLint                       PENDING   0.27 seconds
SubjectPrefix                 PASS      0.12 seconds
BuildKernel                   PASS      25.07 seconds
CheckAllWarning               PASS      27.24 seconds
CheckSparse                   PASS      30.60 seconds
BuildKernel32                 PASS      25.01 seconds
TestRunnerSetup               PASS      550.71 seconds
TestRunner_l2cap-tester       PASS      23.65 seconds
TestRunner_iso-tester         PASS      64.88 seconds
TestRunner_bnep-tester        PASS      6.15 seconds
TestRunner_mgmt-tester        FAIL      121.43 seconds
TestRunner_rfcomm-tester      PASS      10.49 seconds
TestRunner_sco-tester         PASS      14.59 seconds
TestRunner_ioctl-tester       PASS      9.74 seconds
TestRunner_mesh-tester        FAIL      11.47 seconds
TestRunner_smp-tester         PASS      8.37 seconds
TestRunner_userchan-tester    PASS      6.42 seconds
IncrementalBuild              PENDING   0.67 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.103 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    2.108 seconds
Mesh - Send cancel - 2                               Timed out    2.001 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-20 16:12 [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref Douglas Anderson
  2025-11-20 16:41 ` [v3] " bluez.test.bot
@ 2025-11-20 17:04 ` Paul Menzel
  2025-11-20 17:13   ` Doug Anderson
  2025-11-20 18:50 ` patchwork-bot+bluetooth
  2 siblings, 1 reply; 8+ messages in thread
From: Paul Menzel @ 2025-11-20 17:04 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, Matthias Brugger,
	AngeloGioacchino Del Regno, Thorsten Leemhuis, regressions,
	incogcyberpunk, johan.hedberg, sean.wang, stable,
	linux-arm-kernel, linux-bluetooth, linux-kernel, linux-mediatek

Dear Douglas,


Thank you for your patch.

Am 20.11.25 um 17:12 schrieb Douglas Anderson:
> In btusb_mtk_setup(), we set `btmtk_data->isopkt_intf` to:
>    usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM)
> 
> That function can return NULL in some cases. Even when it returns
> NULL, though, we still go on to call btusb_mtk_claim_iso_intf().
> 
> As of commit e9087e828827 ("Bluetooth: btusb: mediatek: Add locks for
> usb_driver_claim_interface()"), calling btusb_mtk_claim_iso_intf()
> when `btmtk_data->isopkt_intf` is NULL will cause a crash because
> we'll end up passing a bad pointer to device_lock(). Prior to that
> commit we'd pass the NULL pointer directly to
> usb_driver_claim_interface() which would detect it and return an
> error, which was handled.
> 
> Resolve the crash in btusb_mtk_claim_iso_intf() by adding a NULL check
> at the start of the function. This makes the code handle a NULL
> `btmtk_data->isopkt_intf` the same way it did before the problematic
> commit (just with a slight change to the error message printed).
> 
> Reported-by: IncogCyberpunk <incogcyberpunk@proton.me>
> Closes: http://lore.kernel.org/r/a380d061-479e-4713-bddd-1d6571ca7e86@leemhuis.info
> Fixes: e9087e828827 ("Bluetooth: btusb: mediatek: Add locks for usb_driver_claim_interface()")
> Cc: stable@vger.kernel.org
> Tested-by: IncogCyberpunk <incogcyberpunk@proton.me>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> 
> Changes in v3:
> - Added Cc to stable.
> - Added IncogCyberpunk Tested-by tag.
> - v2: https://patch.msgid.link/20251119092641.v2.1.I1ae7aebc967e52c7c4be7aa65fbd81736649568a@changeid
> 
> Changes in v2:
> - Rebase atop commit 529ac8e706c3 ("Bluetooth: ... mtk iso interface")
> - v1: https://patch.msgid.link/20251119085354.1.I1ae7aebc967e52c7c4be7aa65fbd81736649568a@changeid
> 
>   drivers/bluetooth/btusb.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index fcc62e2fb641..683ac02e964b 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -2751,6 +2751,11 @@ static void btusb_mtk_claim_iso_intf(struct btusb_data *data)
>   	if (!btmtk_data)
>   		return;
>   
> +	if (!btmtk_data->isopkt_intf) {
> +		bt_dev_err(data->hdev, "Can't claim NULL iso interface");

As an error is printed now, what should be done about? Do drivers need 
fixing? Is it broken hardware?

> +		return;
> +	}
> +
>   	/*
>   	 * The function usb_driver_claim_interface() is documented to need
>   	 * locks held if it's not called from a probe routine. The code here

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-20 17:04 ` [PATCH v3] " Paul Menzel
@ 2025-11-20 17:13   ` Doug Anderson
  0 siblings, 0 replies; 8+ messages in thread
From: Doug Anderson @ 2025-11-20 17:13 UTC (permalink / raw)
  To: Paul Menzel
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, Matthias Brugger,
	AngeloGioacchino Del Regno, Thorsten Leemhuis, regressions,
	incogcyberpunk, johan.hedberg, sean.wang, stable,
	linux-arm-kernel, linux-bluetooth, linux-kernel, linux-mediatek

Hi,

On Thu, Nov 20, 2025 at 9:04 AM Paul Menzel <pmenzel@molgen.mpg.de> wrote:
>
> > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > index fcc62e2fb641..683ac02e964b 100644
> > --- a/drivers/bluetooth/btusb.c
> > +++ b/drivers/bluetooth/btusb.c
> > @@ -2751,6 +2751,11 @@ static void btusb_mtk_claim_iso_intf(struct btusb_data *data)
> >       if (!btmtk_data)
> >               return;
> >
> > +     if (!btmtk_data->isopkt_intf) {
> > +             bt_dev_err(data->hdev, "Can't claim NULL iso interface");
>
> As an error is printed now,

An error was also printed before commit e9087e828827 ("Bluetooth:
btusb: mediatek: Add locks for usb_driver_claim_interface()") too, it
was just a different error message. Previously the NULL would have
been noticed by usb_driver_claim_interface(), which would have
returned -ENODEV. That error would have been noticed and the message
printed would have been:

Failed to claim iso interface: -19

So that error is merely changed into:

Can't claim NULL iso interface

> what should be done about? Do drivers need
> fixing? Is it broken hardware?

Personally, I have no idea. I was mostly trying to get the regression
fixed and, after looking at the code, I was convinced that this would
get us back to working at least as well as we did before commit
e9087e828827 ("Bluetooth: btusb: mediatek: Add locks for
usb_driver_claim_interface()"), plus we'd still have the device_lock()
in place to avoid the problems I noticed earlier. It sounds as if,
even with the error printed, things were working well enough for
IncogCyberpunk.

If someone wants to analyze how / why `btmtk_data->isopkt_intf` would
be NULL in this case and if we should do something better to handle
it, I'd certainly support it!


> > +             return;
> > +     }
> > +
> >       /*
> >        * The function usb_driver_claim_interface() is documented to need
> >        * locks held if it's not called from a probe routine. The code here
>
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>

Thanks!

-Doug

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-20 16:12 [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref Douglas Anderson
  2025-11-20 16:41 ` [v3] " bluez.test.bot
  2025-11-20 17:04 ` [PATCH v3] " Paul Menzel
@ 2025-11-20 18:50 ` patchwork-bot+bluetooth
  2025-11-26  3:18   ` incogcyberpunk
  2 siblings, 1 reply; 8+ messages in thread
From: patchwork-bot+bluetooth @ 2025-11-20 18:50 UTC (permalink / raw)
  To: Doug Anderson
  Cc: marcel, luiz.dentz, matthias.bgg, angelogioacchino.delregno,
	regressions, regressions, incogcyberpunk, johan.hedberg,
	sean.wang, stable, linux-arm-kernel, linux-bluetooth,
	linux-kernel, linux-mediatek

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu, 20 Nov 2025 08:12:28 -0800 you wrote:
> In btusb_mtk_setup(), we set `btmtk_data->isopkt_intf` to:
>   usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM)
> 
> That function can return NULL in some cases. Even when it returns
> NULL, though, we still go on to call btusb_mtk_claim_iso_intf().
> 
> As of commit e9087e828827 ("Bluetooth: btusb: mediatek: Add locks for
> usb_driver_claim_interface()"), calling btusb_mtk_claim_iso_intf()
> when `btmtk_data->isopkt_intf` is NULL will cause a crash because
> we'll end up passing a bad pointer to device_lock(). Prior to that
> commit we'd pass the NULL pointer directly to
> usb_driver_claim_interface() which would detect it and return an
> error, which was handled.
> 
> [...]

Here is the summary with links:
  - [v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
    https://git.kernel.org/bluetooth/bluetooth-next/c/dd6dda907d09

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-20 18:50 ` patchwork-bot+bluetooth
@ 2025-11-26  3:18   ` incogcyberpunk
  2025-11-26  3:29     ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 8+ messages in thread
From: incogcyberpunk @ 2025-11-26  3:18 UTC (permalink / raw)
  To: patchwork-bot+bluetooth
  Cc: Doug Anderson, marcel, luiz.dentz, matthias.bgg,
	angelogioacchino.delregno, regressions, regressions,
	johan.hedberg, sean.wang, stable, linux-arm-kernel,
	linux-bluetooth, linux-kernel, linux-mediatek

Hey,

It's been almost a week since the regression was reported and an patch was provided to fix the issue, which has now been accepted in the linux-next tree; but I see that despite being a patch for regression, a merge/pull request was not made upstream for the latest -rc mainline release. 

Is there any way that I can track the updates for this patch to be onto the mainline release? 

Sorry, if I am missing anything. 

Regards, 
IncogCyberpunk

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-26  3:18   ` incogcyberpunk
@ 2025-11-26  3:29     ` Luiz Augusto von Dentz
  2025-11-26  5:14       ` incogcyberpunk
  0 siblings, 1 reply; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2025-11-26  3:29 UTC (permalink / raw)
  To: incogcyberpunk
  Cc: patchwork-bot+bluetooth, Doug Anderson, marcel, matthias.bgg,
	angelogioacchino.delregno, regressions, regressions,
	johan.hedberg, sean.wang, stable, linux-arm-kernel,
	linux-bluetooth, linux-kernel, linux-mediatek

Hi,

On Tue, Nov 25, 2025 at 10:18 PM <incogcyberpunk@proton.me> wrote:
>
> Hey,
>
> It's been almost a week since the regression was reported and an patch was provided to fix the issue, which has now been accepted in the linux-next tree; but I see that despite being a patch for regression, a merge/pull request was not made upstream for the latest -rc mainline release.
>
> Is there any way that I can track the updates for this patch to be onto the mainline release?
>
> Sorry, if I am missing anything.

This was merged into net tree a few days ago:

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=8a4dfa8fa6b5

So it should get into Linus tree in the next few days.

> Regards,
> IncogCyberpunk



-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref
  2025-11-26  3:29     ` Luiz Augusto von Dentz
@ 2025-11-26  5:14       ` incogcyberpunk
  0 siblings, 0 replies; 8+ messages in thread
From: incogcyberpunk @ 2025-11-26  5:14 UTC (permalink / raw)
  To: Luiz Augusto von Dentz
  Cc: patchwork-bot+bluetooth, Doug Anderson, marcel, matthias.bgg,
	angelogioacchino.delregno, regressions, regressions,
	johan.hedberg, sean.wang, stable, linux-arm-kernel,
	linux-bluetooth, linux-kernel, linux-mediatek

Hi, 

Don't want to add trouble, just out of curiosity.

What is normally the route for patches to get into the mainline kernel? 

Isn't it as follows , as suggested in the documentations ? 
subsystem -> -next -> mainline -> stable ? 

What's this net tree , and how are the patches cherrypicked onto the  mainline kernel? is there a certain process? 

Regards, 
IncogCyberpunk


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-11-26  5:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 16:12 [PATCH v3] Bluetooth: btusb: mediatek: Avoid btusb_mtk_claim_iso_intf() NULL deref Douglas Anderson
2025-11-20 16:41 ` [v3] " bluez.test.bot
2025-11-20 17:04 ` [PATCH v3] " Paul Menzel
2025-11-20 17:13   ` Doug Anderson
2025-11-20 18:50 ` patchwork-bot+bluetooth
2025-11-26  3:18   ` incogcyberpunk
2025-11-26  3:29     ` Luiz Augusto von Dentz
2025-11-26  5:14       ` incogcyberpunk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox