public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC PATCH] ALSA: usb-audio: endpoint: Prevent NULL pointer deference in snd_usb_endpoint_close
@ 2024-04-26 12:25 Rajashekar kuruva
  2024-04-26 12:43 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Rajashekar kuruva @ 2024-04-26 12:25 UTC (permalink / raw)
  To: srinivas.kandagatla, mathias.nyman, perex, conor+dt, corbet,
	lgirdwood, andersson, krzysztof.kozlowski+dt, gregkh,
	Thinh.Nguyen, broonie, bgoswami, tiwai, robh, konrad.dybcio
  Cc: linux-kernel, devicetree, linux-sound, linux-usb, linux-arm-msm,
	linux-doc, alsa-devel, Rajashekar kuruva

When multiple plug-in and plug-out events occur,
there is a risk of encountering a NULL pointer dereference
leading to a kernel panic during a headset use-case.
this issue arises in the snd_usb_endpoint_close function

To avoid check if ep->iface_ref is not null before decrementing
its opened count. If ep->iface_ref is null, we skip the decrement
and the subsequent logic.

Signed-off-by: Rajashekar kuruva <quic_kuruva@quicinc.com>
---
 sound/usb/endpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 8f65349a06d3..0e3101b7e392 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -950,7 +950,7 @@ void snd_usb_endpoint_close(struct snd_usb_audio *chip,
 	usb_audio_dbg(chip, "Closing EP 0x%x (count %d)\n",
 		      ep->ep_num, ep->opened);
 
-	if (!--ep->iface_ref->opened &&
+	if (ep->iface_ref && !--ep->iface_ref->opened &&
 		!(chip->quirk_flags & QUIRK_FLAG_IFACE_SKIP_CLOSE))
 		endpoint_set_interface(chip, ep, false);
 
-- 
2.25.1


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

end of thread, other threads:[~2024-04-29  6:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 12:25 [PATCH] [RFC PATCH] ALSA: usb-audio: endpoint: Prevent NULL pointer deference in snd_usb_endpoint_close Rajashekar kuruva
2024-04-26 12:43 ` Takashi Iwai
2024-04-29  6:23   ` Rajashekar Kuruva (Temp)
2024-04-29  6:57     ` Takashi Iwai

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