* [PATCH] ALSA: usb-audio: us144mkii: Fix null-deref in tascam_midi_in_urb_complete()
@ 2025-08-19 17:38 Šerif Rami
2025-08-19 18:10 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Šerif Rami @ 2025-08-19 17:38 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Stephen Rothwell, Šerif Rami,
open list:SOUND, open list
Cc: kernel test robot, Dan Carpenter
The smatch tool reported a potential null pointer dereference in
tascam_midi_in_urb_complete(). The 'tascam' variable, derived from
'urb->context', was checked for nullity in one place, but dereferenced
without a check in several other places.
This patch fixes the issue by adding a null check at the beginning of
the function. If 'tascam' is null, the function now safely exits.
This prevents any potential crashes from null pointer dereferences.
It also fixes a latent bug where 'usb_put_urb()' could
be called twice for the same URB on submission failure, which would
lead to a use-after-free error.
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202508192109.lcMrINK1-lkp@intel.com/
Signed-off-by: Šerif Rami <ramiserifpersia@gmail.com>
---
sound/usb/usx2y/us144mkii_midi.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/usb/usx2y/us144mkii_midi.c b/sound/usb/usx2y/us144mkii_midi.c
index 5759f6010..1aca38f38 100644
--- a/sound/usb/usx2y/us144mkii_midi.c
+++ b/sound/usb/usx2y/us144mkii_midi.c
@@ -41,6 +41,9 @@ void tascam_midi_in_urb_complete(struct urb *urb)
struct tascam_card *tascam = urb->context;
int ret;
+ if (!tascam)
+ goto out;
+
if (urb->status) {
if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
urb->status != -ESHUTDOWN && urb->status != -EPROTO) {
@@ -51,7 +54,7 @@ void tascam_midi_in_urb_complete(struct urb *urb)
goto out;
}
- if (tascam && atomic_read(&tascam->midi_in_active) &&
+ if (atomic_read(&tascam->midi_in_active) &&
urb->actual_length > 0) {
kfifo_in_spinlocked(&tascam->midi_in_fifo, urb->transfer_buffer,
urb->actual_length, &tascam->midi_in_lock);
@@ -66,11 +69,14 @@ void tascam_midi_in_urb_complete(struct urb *urb)
"Failed to resubmit MIDI IN URB: error %d\n", ret);
usb_unanchor_urb(urb);
usb_put_urb(urb);
+ goto out;
}
+
out:
usb_put_urb(urb);
}
+
/**
* tascam_midi_in_open() - Opens the MIDI input substream.
* @substream: The ALSA rawmidi substream to open.
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: usb-audio: us144mkii: Fix null-deref in tascam_midi_in_urb_complete()
2025-08-19 17:38 [PATCH] ALSA: usb-audio: us144mkii: Fix null-deref in tascam_midi_in_urb_complete() Šerif Rami
@ 2025-08-19 18:10 ` Dan Carpenter
2025-08-19 18:33 ` [PATCH] ALSA: usb-audio: usx2y: " Šerif Rami
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-08-19 18:10 UTC (permalink / raw)
To: Šerif Rami
Cc: Jaroslav Kysela, Takashi Iwai, Stephen Rothwell, open list:SOUND,
open list, kernel test robot
On Tue, Aug 19, 2025 at 07:38:30PM +0200, Šerif Rami wrote:
> The smatch tool reported a potential null pointer dereference in
> tascam_midi_in_urb_complete(). The 'tascam' variable, derived from
> 'urb->context', was checked for nullity in one place, but dereferenced
> without a check in several other places.
>
> This patch fixes the issue by adding a null check at the beginning of
> the function. If 'tascam' is null, the function now safely exits.
> This prevents any potential crashes from null pointer dereferences.
>
> It also fixes a latent bug where 'usb_put_urb()' could
> be called twice for the same URB on submission failure, which would
> lead to a use-after-free error.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/r/202508192109.lcMrINK1-lkp@intel.com/
> Signed-off-by: Šerif Rami <ramiserifpersia@gmail.com>
> ---
> sound/usb/usx2y/us144mkii_midi.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/sound/usb/usx2y/us144mkii_midi.c b/sound/usb/usx2y/us144mkii_midi.c
> index 5759f6010..1aca38f38 100644
> --- a/sound/usb/usx2y/us144mkii_midi.c
> +++ b/sound/usb/usx2y/us144mkii_midi.c
> @@ -41,6 +41,9 @@ void tascam_midi_in_urb_complete(struct urb *urb)
> struct tascam_card *tascam = urb->context;
> int ret;
>
> + if (!tascam)
> + goto out;
> +
> if (urb->status) {
> if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
> urb->status != -ESHUTDOWN && urb->status != -EPROTO) {
> @@ -51,7 +54,7 @@ void tascam_midi_in_urb_complete(struct urb *urb)
> goto out;
> }
>
> - if (tascam && atomic_read(&tascam->midi_in_active) &&
> + if (atomic_read(&tascam->midi_in_active) &&
> urb->actual_length > 0) {
> kfifo_in_spinlocked(&tascam->midi_in_fifo, urb->transfer_buffer,
> urb->actual_length, &tascam->midi_in_lock);
> @@ -66,11 +69,14 @@ void tascam_midi_in_urb_complete(struct urb *urb)
> "Failed to resubmit MIDI IN URB: error %d\n", ret);
> usb_unanchor_urb(urb);
> usb_put_urb(urb);
usb_put_urb() is still called twice, though?
> + goto out;
> }
> +
> out:
> usb_put_urb(urb);
> }
>
> +
You accidentally added a double blank line here.
> /**
> * tascam_midi_in_open() - Opens the MIDI input substream.
> * @substream: The ALSA rawmidi substream to open.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: usb-audio: usx2y: Fix null-deref in tascam_midi_in_urb_complete()
2025-08-19 18:10 ` Dan Carpenter
@ 2025-08-19 18:33 ` Šerif Rami
0 siblings, 0 replies; 3+ messages in thread
From: Šerif Rami @ 2025-08-19 18:33 UTC (permalink / raw)
To: dan.carpenter
Cc: linux-kernel, linux-sound, lkp, perex, ramiserifpersia, sfr,
tiwai
Hi Dan,
Thanks for the review and for spotting these issues. You are correct.
I'll send a v2 shortly that addresses these points.
Thanks,
Šerif
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-19 18:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 17:38 [PATCH] ALSA: usb-audio: us144mkii: Fix null-deref in tascam_midi_in_urb_complete() Šerif Rami
2025-08-19 18:10 ` Dan Carpenter
2025-08-19 18:33 ` [PATCH] ALSA: usb-audio: usx2y: " Šerif Rami
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).