From: Jiaming Zhang <r772577952@gmail.com>
To: gregkh@linuxfoundation.org
Cc: broonie@kernel.org, cryolitia@uniontech.com,
linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org,
perex@perex.cz, pierre-louis.bossart@linux.dev,
quic_wcheng@quicinc.com, r772577952@gmail.com,
syzkaller@googlegroups.com, tiwai@suse.com
Subject: [PATCH] ALSA: usb-audio: Fix NULL pointer deference in try_to_register_card
Date: Tue, 14 Oct 2025 12:01:49 +0800 [thread overview]
Message-ID: <20251014040149.1031348-1-r772577952@gmail.com> (raw)
In-Reply-To: <2025101225-lisp-monkhood-af34@gregkh>
Hi Greg,
Thanks for the guidance. You're right, the root cause of this issue is
that a USB audio device is created without a proper interface.
To fix this issue, I added a check for the NULL return value in
try_to_register_card() before calling usb_interface_claimed().
I have tested patch with the reproducer on the latest version (v6.18-rc1),
the issue was not triggered again.
Please let me know if any changes are needed.
Best regards,
Jiaming Zhang
---
In try_to_register_card(), the return value of usb_ifnum_to_if() is
passed directly to usb_interface_claimed() without a NULL check, which
will lead to a NULL pointer dereference when creating an invalid
USB audio device. Fix this by adding a check to ensure the interface
pointer is valid before passing it to usb_interface_claimed().
Reported-by: Jiaming Zhang <r772577952@gmail.com>
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
sound/usb/card.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 1d5a65eac933..270dad84d825 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -891,10 +891,16 @@ get_alias_quirk(struct usb_device *dev, unsigned int id)
*/
static int try_to_register_card(struct snd_usb_audio *chip, int ifnum)
{
+ struct usb_interface *iface;
+
if (check_delayed_register_option(chip) == ifnum ||
- chip->last_iface == ifnum ||
- usb_interface_claimed(usb_ifnum_to_if(chip->dev, chip->last_iface)))
+ chip->last_iface == ifnum)
+ return snd_card_register(chip->card);
+
+ iface = usb_ifnum_to_if(chip->dev, chip->last_iface);
+ if (iface && usb_interface_claimed(iface))
return snd_card_register(chip->card);
+
return 0;
}
--
2.34.1
next prev parent reply other threads:[~2025-10-14 4:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-12 11:11 [Linux Kernel Bug] general protection fault in try_to_register_card Jiaming Zhang
2025-10-12 11:18 ` Greg KH
2025-10-14 4:01 ` Jiaming Zhang [this message]
2025-10-14 5:26 ` [PATCH] ALSA: usb-audio: Fix NULL pointer deference " Greg KH
2025-10-14 5:53 ` Takashi Iwai
2025-10-15 5:16 ` [PATCH v2 0/1] " Jiaming Zhang
2025-10-15 5:16 ` [PATCH v2 1/1] " Jiaming Zhang
2025-10-15 8:18 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251014040149.1031348-1-r772577952@gmail.com \
--to=r772577952@gmail.com \
--cc=broonie@kernel.org \
--cc=cryolitia@uniontech.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=pierre-louis.bossart@linux.dev \
--cc=quic_wcheng@quicinc.com \
--cc=syzkaller@googlegroups.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox