public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiaming Zhang <r772577952@gmail.com>
To: tiwai@suse.de, 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 v2 1/1] ALSA: usb-audio: Fix NULL pointer deference in try_to_register_card
Date: Wed, 15 Oct 2025 13:16:45 +0800	[thread overview]
Message-ID: <20251015051645.519470-2-r772577952@gmail.com> (raw)
In-Reply-To: <20251015051645.519470-1-r772577952@gmail.com>

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().

Fixes: 39efc9c ("ALSA: usb-audio: Fix last interface check for registration")
Closes: https://lore.kernel.org/all/CANypQFYtQxHL5ghREs-BujZG413RPJGnO5TH=xjFBKpPts33tA@mail.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


  reply	other threads:[~2025-10-15  5:16 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   ` [PATCH] ALSA: usb-audio: Fix NULL pointer deference " Jiaming Zhang
2025-10-14  5:26     ` 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           ` Jiaming Zhang [this message]
2025-10-15  8:18             ` [PATCH v2 1/1] " 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=20251015051645.519470-2-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 \
    --cc=tiwai@suse.de \
    /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