mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: "Jia-Ju Bai" <baijiaju1990@gmail.com>
Cc: <bhelgaas@google.com>, <tglx@linutronix.de>,
	<gregkh@linuxfoundation.org>, <kirr@nexedi.com>, <perex@perex.cz>,
	<rfontana@redhat.com>, <alsa-devel@alsa-project.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ALSA: core: Fix possible null-pointer dereferences in snd_timer_proc_read()
Date: Wed, 24 Jul 2019 14:32:04 +0200	[thread overview]
Message-ID: <s5hpnlz396j.wl-tiwai@suse.de> (raw)
In-Reply-To: <20190724121327.9894-1-baijiaju1990@gmail.com>

On Wed, 24 Jul 2019 14:13:27 +0200,
Jia-Ju Bai wrote:
> 
> In snd_timer_proc_read(), there is an if statement on line 1204 to check
> whether timer->card is NULL:
>     if (timer->card && timer->card->shutdown)
> 
> When timer->card is NULL, it is used on lines 1212 and 1215:
>     timer->card->number
> 
> Thus, possible null-pointer dereferences may occur.
> 
> To fix these bugs, timer->card is checked before being used.

Both cases can (should) never happen.  The SNDRV_TIMER_CLASS_CARD is
always associated with a timer with a card object.  Ditto for
SNDRV_TIMER_CLASS_PCM, where a PCM is always tied with a card.

So, if any, this should be a WARN_ON().  But I doubt it being any
useful.


thanks,

Takashi

> 
> These bugs are found by a static analysis tool STCheck written by us.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  sound/core/timer.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/core/timer.c b/sound/core/timer.c
> index 5c9fbf3f4340..967d06a3cdec 100644
> --- a/sound/core/timer.c
> +++ b/sound/core/timer.c
> @@ -1208,11 +1208,13 @@ static void snd_timer_proc_read(struct snd_info_entry *entry,
>  			snd_iprintf(buffer, "G%i: ", timer->tmr_device);
>  			break;
>  		case SNDRV_TIMER_CLASS_CARD:
> -			snd_iprintf(buffer, "C%i-%i: ",
> -				    timer->card->number, timer->tmr_device);
> +			snd_iprintf(buffer, "C%i-%i: ", 
> +					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:
> -- 
> 2.17.0
> 
> 

      reply	other threads:[~2019-07-24 12:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 12:13 Jia-Ju Bai
2019-07-24 12:32 ` 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=s5hpnlz396j.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=baijiaju1990@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kirr@nexedi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=rfontana@redhat.com \
    --cc=tglx@linutronix.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

all inboxes | Powered by JetHome®