All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Mark Brown <broonie@kernel.org>,
	Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com>
Cc: lgirdwood@gmail.com, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org, tiwai@suse.com
Subject: Re: [PATCH] ASoC: dapm: Fix NULL pointer dereference in snd_soc_dapm_new_dai
Date: Thu, 21 Mar 2019 08:59:55 -0500	[thread overview]
Message-ID: <13b5c552-69a6-f1e0-174c-b5aa48560858@linux.intel.com> (raw)
In-Reply-To: <20190321123156.GB5684@sirena.org.uk>

On 3/21/19 7:31 AM, Mark Brown wrote:

> On Thu, Mar 21, 2019 at 03:41:25PM +0530, Pankaj Bharadiya wrote:
>
>>   outfree_kcontrol_news:
>>   	devm_kfree(card->dev, (void *)template.kcontrol_news);
>> -	snd_soc_dapm_free_kcontrol(card, &private_value,
>> -				   rtd->dai_link->num_params, w_param_text);
>> +	if (w_param_text)
>> +		snd_soc_dapm_free_kcontrol(card, &private_value,
>> +				rtd->dai_link->num_params, w_param_text);
> This is very non-obvious - it's not at all clear why we'd need the text
> to free controls.  If there is an issue here it seems like it'd be
> better to make sure that snd_soc_dapm_free_kcontrol() can cope with that
> being NULL, that will be clearer and also avoid potential issues with
> other callers.

I believe the issue is real, but you need to look at the entire code to figure it out

     /* allocate memory for control, only in case of multiple configs */
     if (rtd->dai_link->num_params > 1) {
         w_param_text = devm_kcalloc(card->dev,
                         rtd->dai_link->num_params,
                         sizeof(char *), GFP_KERNEL);
         if (!w_param_text) {
             ret = -ENOMEM;
             goto param_fail;
         }

         template.num_kcontrols = 1;
         template.kcontrol_news =
                     snd_soc_dapm_alloc_kcontrol(card,
                         link_name,
                         rtd->dai_link->params,
                         rtd->dai_link->num_params,
                         w_param_text, &private_value);
         if (!template.kcontrol_news) {
             ret = -ENOMEM;
             goto param_fail;
         }
     } else {
         w_param_text = NULL; <<<< this is set when there is a single config
     }
     dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);

     w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
     if (IS_ERR(w)) {
         ret = PTR_ERR(w);
         goto outfree_kcontrol_news; <<< the control creation failed
     }

     w->priv = rtd;

     return w;

outfree_kcontrol_news:
     devm_kfree(card->dev, (void *)template.kcontrol_news);

<<< and in the function below we try to access w_param_text and private_value which haven't been allocated.

     snd_soc_dapm_free_kcontrol(card, &private_value,
                    rtd->dai_link->num_params, w_param_text);

That said I agree with Mark that it's better to change snd_soc_dapm_free_kcontrol directly.

  reply	other threads:[~2019-03-21 13:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-21 10:11 [PATCH] ASoC: dapm: Fix NULL pointer dereference in snd_soc_dapm_new_dai Pankaj Bharadiya
2019-03-21 12:31 ` Mark Brown
2019-03-21 13:59   ` Pierre-Louis Bossart [this message]
2019-03-21 14:09     ` [alsa-devel] " Mark Brown
2019-03-21 16:31       ` Bharadiya,Pankaj

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=13b5c552-69a6-f1e0-174c-b5aa48560858@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pankaj.laxminarayan.bharadiya@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.