public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: hariconscious@gmail.com
Cc: perex@perex.cz, tiwai@suse.com, khalid@kernel.org,
	shuah@kernel.org, david.hunter.linux@gmail.com, mingo@kernel.org,
	tglx@linutronix.de, thorsten.blum@linux.dev,
	mengdewei@cqsoftware.com.cn, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: timer: Fix null dereference of 'timer->card' reported by smatch
Date: Tue, 04 Nov 2025 10:50:23 +0100	[thread overview]
Message-ID: <875xbqi0tc.wl-tiwai@suse.de> (raw)
In-Reply-To: <20251103114902.11423-2-hariconscious@gmail.com>

On Mon, 03 Nov 2025 12:49:03 +0100,
hariconscious@gmail.com wrote:
> 
> From: HariKrishna Sagala <hariconscious@gmail.com>
> 
> Fix null dereference in snd_timer_proc_read().
> 
> Smatch reported that  was previously assumed to be null
> at line 1226, but later accessed without a check.
> This could lead to a null pointer dereference under certain conditions.
> 
> Add a null check before accessing to ensure safe execution.
> 
> Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
> ---
> This patch addresses a null pointer dereference in snd_timer_proc_read()
> by adding a proper check for timer->card.The issue was flagged by Smatch,
> which noted that timer->card was previously assumed to be null at
> line 1226 but accessed without validation.To ensure safe access, a
> conditional check has been introduced before referencing timer->card.
> The fix was verified by booting the kernel and performing audio playback
> using ALSA commands. Additionally, the /proc/asound/timers
> interface was inspected to confirm that timer information is
> correctly populated and accessible without errors.
> Note: Couldn't simulate a scenario where 'timer->card' is null and
> 'timer->card->shutdown' is 1 (shutdown initiated).

timer->card is guaranteed to be non-NULL for SNDRV_TIMER_CLASS_CARD
timer->and SNDRV_TIMER_CLASS_PCM at the creation in snd_timer_new().
So this check is superfluous.


thanks,

Takashi

> 
>  sound/core/timer.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/core/timer.c b/sound/core/timer.c
> index d9fff5c87613..d65e8bcb2f46 100644
> --- a/sound/core/timer.c
> +++ b/sound/core/timer.c
> @@ -1231,10 +1231,11 @@ static void snd_timer_proc_read(struct snd_info_entry *entry,
>  			break;
>  		case SNDRV_TIMER_CLASS_CARD:
>  			snd_iprintf(buffer, "C%i-%i: ",
> -				    timer->card->number, timer->tmr_device);
> +				    timer->card ? timer->card->number : -1, timer->tmr_device);
>  			break;
>  		case SNDRV_TIMER_CLASS_PCM:
> -			snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number,
> +			snd_iprintf(buffer, "P%i-%i-%i: ",
> +				    timer->card ? timer->card->number : -1,
>  				    timer->tmr_device, timer->tmr_subdevice);
>  			break;
>  		default:
> 
> base-commit: 6093a688a07da07808f0122f9aa2a3eed250d853
> -- 
> 2.43.0
> 

      reply	other threads:[~2025-11-04  9:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03 11:49 [PATCH] ALSA: timer: Fix null dereference of 'timer->card' reported by smatch hariconscious
2025-11-04  9:50 ` Takashi Iwai [this message]

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=875xbqi0tc.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=david.hunter.linux@gmail.com \
    --cc=hariconscious@gmail.com \
    --cc=khalid@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mengdewei@cqsoftware.com.cn \
    --cc=mingo@kernel.org \
    --cc=perex@perex.cz \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thorsten.blum@linux.dev \
    --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