public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe
@ 2023-11-23 15:54 Kunwu Chan
  2023-12-04 11:34 ` Péter Ujfalusi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kunwu Chan @ 2023-11-23 15:54 UTC (permalink / raw)
  To: pierre-louis.bossart, lgirdwood, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, kai.vehmanen, broonie, perex,
	tiwai, chao.song
  Cc: kunwu.chan, sound-open-firmware, linux-sound, linux-kernel,
	Kunwu Chan

devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 46207ca24545 ("ASoC: SOF: pci: change the default firmware path when the community key is used")
Fixes: 25bbc0c59ee1 ("ASoC: SOF: Add path definition for external firmware libraries")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 sound/soc/sof/sof-pci-dev.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c
index 64b326e3ef85..75a9bfa5bfbe 100644
--- a/sound/soc/sof/sof-pci-dev.c
+++ b/sound/soc/sof/sof-pci-dev.c
@@ -282,6 +282,10 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
 			devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
 				       sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
 				       "community");
+		if (!sof_pdata->fw_filename_prefix) {
+			ret = -ENOMEM;	
+			goto out;
+		}
 
 		dev_dbg(dev,
 			"Platform uses community key, changed fw path to %s\n",
@@ -303,6 +307,10 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
 				devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
 					sof_pdata->desc->default_lib_path[sof_pdata->ipc_type],
 					"community");
+			if (!sof_pdata->fw_lib_prefix) {
+				ret = -ENOMEM;
+				goto out;
+			}
 
 			dev_dbg(dev,
 				"Platform uses community key, changed fw_lib path to %s\n",
-- 
2.34.1


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

* Re: [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe
  2023-11-23 15:54 [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe Kunwu Chan
@ 2023-12-04 11:34 ` Péter Ujfalusi
  2023-12-04 12:38 ` Mark Brown
       [not found] ` <1701766721668457.408.seg@mailgw>
  2 siblings, 0 replies; 6+ messages in thread
From: Péter Ujfalusi @ 2023-12-04 11:34 UTC (permalink / raw)
  To: Kunwu Chan, pierre-louis.bossart, lgirdwood, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, kai.vehmanen, broonie, perex,
	tiwai, chao.song
  Cc: kunwu.chan, sound-open-firmware, linux-sound, linux-kernel



On 23/11/2023 17:54, Kunwu Chan wrote:
> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> 
> Fixes: 46207ca24545 ("ASoC: SOF: pci: change the default firmware path when the community key is used")
> Fixes: 25bbc0c59ee1 ("ASoC: SOF: Add path definition for external firmware libraries")
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>

This patch cannot fix both commits as at 46207ca24545 the lib path was
not present.
Please don't bundle unrelated fixes, it makes maintainers life harder.

As a note: if the allocation fails it is not going to cause null
dereference as the code checks !sof_pdata->*_prefix to see if it is
provided (override) or not (use default).
At most it will cause the kernel to 'ignore' the path override, but if
this allocation fails this is least of our problem ;)

> ---
>  sound/soc/sof/sof-pci-dev.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c
> index 64b326e3ef85..75a9bfa5bfbe 100644
> --- a/sound/soc/sof/sof-pci-dev.c
> +++ b/sound/soc/sof/sof-pci-dev.c
> @@ -282,6 +282,10 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
>  			devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
>  				       sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
>  				       "community");
> +		if (!sof_pdata->fw_filename_prefix) {
> +			ret = -ENOMEM;	
> +			goto out;
> +		}
>  
>  		dev_dbg(dev,
>  			"Platform uses community key, changed fw path to %s\n",
> @@ -303,6 +307,10 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
>  				devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
>  					sof_pdata->desc->default_lib_path[sof_pdata->ipc_type],
>  					"community");
> +			if (!sof_pdata->fw_lib_prefix) {
> +				ret = -ENOMEM;
> +				goto out;
> +			}
>  
>  			dev_dbg(dev,
>  				"Platform uses community key, changed fw_lib path to %s\n",

-- 
Péter

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

* Re: [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe
  2023-11-23 15:54 [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe Kunwu Chan
  2023-12-04 11:34 ` Péter Ujfalusi
@ 2023-12-04 12:38 ` Mark Brown
  2023-12-05  9:12   ` Kunwu Chan
       [not found] ` <1701766721668457.408.seg@mailgw>
  2 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2023-12-04 12:38 UTC (permalink / raw)
  To: Kunwu Chan
  Cc: pierre-louis.bossart, lgirdwood, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, kai.vehmanen, perex, tiwai,
	chao.song, kunwu.chan, sound-open-firmware, linux-sound,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

On Thu, Nov 23, 2023 at 11:54:24PM +0800, Kunwu Chan wrote:
> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.

In addition to the issues others mentioned this doesn't apply against
current code, please check and resend.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe
       [not found] ` <1701766721668457.408.seg@mailgw>
@ 2023-12-05  9:10   ` Kunwu Chan
  2023-12-05  9:44     ` Péter Ujfalusi
  0 siblings, 1 reply; 6+ messages in thread
From: Kunwu Chan @ 2023-12-05  9:10 UTC (permalink / raw)
  To: Péter Ujfalusi, pierre-louis.bossart, lgirdwood,
	yung-chuan.liao, ranjani.sridharan, daniel.baluta, kai.vehmanen,
	broonie, perex, tiwai, chao.song
  Cc: kunwu.chan, sound-open-firmware, linux-sound, linux-kernel

It's my bad, i'll follow your suggestion in v2 patch:
1. remove 'Fixes: 46207ca24545' label

2. rename subject to 'ASoC: SOF: Add null pointer check to sof_pci_probe'

3. when sof_pdata->fw_filename_prefix is NULL,don't use it to dev_dbg. 
Or just use a
if (sof_pdata->fw_filename_prefix)
         dev_dbg(dev,
                 "Platform uses community key, changed fw path to %s\n",
                 sof_pdata->fw_filename_prefix);
else
	dev_dbg(dev,
                 "Platform uses community key, changed fw path to %s/%s\n",
                  sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
                  "community");

Is it okay to modify it like this?


Thanks,
Kunwu

On 2023/12/4 19:34, Péter Ujfalusi wrote:
> 
> 
> On 23/11/2023 17:54, Kunwu Chan wrote:
>> devm_kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure.
>>
>> Fixes: 46207ca24545 ("ASoC: SOF: pci: change the default firmware path when the community key is used")
>> Fixes: 25bbc0c59ee1 ("ASoC: SOF: Add path definition for external firmware libraries")
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> 
> This patch cannot fix both commits as at 46207ca24545 the lib path was
> not present.
> Please don't bundle unrelated fixes, it makes maintainers life harder.
> 
> As a note: if the allocation fails it is not going to cause null
> dereference as the code checks !sof_pdata->*_prefix to see if it is
> provided (override) or not (use default).
> At most it will cause the kernel to 'ignore' the path override, but if
> this allocation fails this is least of our problem ;)
> 
>> ---
>>   sound/soc/sof/sof-pci-dev.c | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c
>> index 64b326e3ef85..75a9bfa5bfbe 100644
>> --- a/sound/soc/sof/sof-pci-dev.c
>> +++ b/sound/soc/sof/sof-pci-dev.c
>> @@ -282,6 +282,10 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
>>   			devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
>>   				       sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
>>   				       "community");
>> +		if (!sof_pdata->fw_filename_prefix) {
>> +			ret = -ENOMEM;	
>> +			goto out;
>> +		}
>>   
>>   		dev_dbg(dev,
>>   			"Platform uses community key, changed fw path to %s\n",
>> @@ -303,6 +307,10 @@ int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
>>   				devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
>>   					sof_pdata->desc->default_lib_path[sof_pdata->ipc_type],
>>   					"community");
>> +			if (!sof_pdata->fw_lib_prefix) {
>> +				ret = -ENOMEM;
>> +				goto out;
>> +			}
>>   
>>   			dev_dbg(dev,
>>   				"Platform uses community key, changed fw_lib path to %s\n",
> 

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

* Re: [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe
  2023-12-04 12:38 ` Mark Brown
@ 2023-12-05  9:12   ` Kunwu Chan
  0 siblings, 0 replies; 6+ messages in thread
From: Kunwu Chan @ 2023-12-05  9:12 UTC (permalink / raw)
  To: Mark Brown
  Cc: pierre-louis.bossart, lgirdwood, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, kai.vehmanen, perex, tiwai,
	chao.song, kunwu.chan, sound-open-firmware, linux-sound,
	linux-kernel

Thanks for your reply.
I'll check the patch and modify it by a better way.

Thanks again,
Kunwu

On 2023/12/4 20:38, Mark Brown wrote:
> On Thu, Nov 23, 2023 at 11:54:24PM +0800, Kunwu Chan wrote:
>> devm_kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure.
> 
> In addition to the issues others mentioned this doesn't apply against
> current code, please check and resend.

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

* Re: [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe
  2023-12-05  9:10   ` Kunwu Chan
@ 2023-12-05  9:44     ` Péter Ujfalusi
  0 siblings, 0 replies; 6+ messages in thread
From: Péter Ujfalusi @ 2023-12-05  9:44 UTC (permalink / raw)
  To: Kunwu Chan, pierre-louis.bossart, lgirdwood, yung-chuan.liao,
	ranjani.sridharan, daniel.baluta, kai.vehmanen, broonie, perex,
	tiwai, chao.song
  Cc: kunwu.chan, sound-open-firmware, linux-sound, linux-kernel



On 05/12/2023 11:10, Kunwu Chan wrote:
> It's my bad, i'll follow your suggestion in v2 patch:
> 1. remove 'Fixes: 46207ca24545' label
> 
> 2. rename subject to 'ASoC: SOF: Add null pointer check to sof_pci_probe'
> 
> 3. when sof_pdata->fw_filename_prefix is NULL,don't use it to dev_dbg.
> Or just use a
> if (sof_pdata->fw_filename_prefix)
>         dev_dbg(dev,
>                 "Platform uses community key, changed fw path to %s\n",
>                 sof_pdata->fw_filename_prefix);
> else
>     dev_dbg(dev,
>                 "Platform uses community key, changed fw path to %s/%s\n",
>                  sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
>                  "community");
> 
> Is it okay to modify it like this?

The code has been rewritten and all of these issues have been
eliminated, fixed in core SOF.

> 
> 
> Thanks,
> Kunwu
> 
> On 2023/12/4 19:34, Péter Ujfalusi wrote:
>>
>>
>> On 23/11/2023 17:54, Kunwu Chan wrote:
>>> devm_kasprintf() returns a pointer to dynamically allocated memory
>>> which can be NULL upon failure.
>>>
>>> Fixes: 46207ca24545 ("ASoC: SOF: pci: change the default firmware
>>> path when the community key is used")
>>> Fixes: 25bbc0c59ee1 ("ASoC: SOF: Add path definition for external
>>> firmware libraries")
>>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>>
>> This patch cannot fix both commits as at 46207ca24545 the lib path was
>> not present.
>> Please don't bundle unrelated fixes, it makes maintainers life harder.
>>
>> As a note: if the allocation fails it is not going to cause null
>> dereference as the code checks !sof_pdata->*_prefix to see if it is
>> provided (override) or not (use default).
>> At most it will cause the kernel to 'ignore' the path override, but if
>> this allocation fails this is least of our problem ;)
>>
>>> ---
>>>   sound/soc/sof/sof-pci-dev.c | 8 ++++++++
>>>   1 file changed, 8 insertions(+)
>>>
>>> diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c
>>> index 64b326e3ef85..75a9bfa5bfbe 100644
>>> --- a/sound/soc/sof/sof-pci-dev.c
>>> +++ b/sound/soc/sof/sof-pci-dev.c
>>> @@ -282,6 +282,10 @@ int sof_pci_probe(struct pci_dev *pci, const
>>> struct pci_device_id *pci_id)
>>>               devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
>>>                         
>>> sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
>>>                          "community");
>>> +        if (!sof_pdata->fw_filename_prefix) {
>>> +            ret = -ENOMEM;   
>>> +            goto out;
>>> +        }
>>>             dev_dbg(dev,
>>>               "Platform uses community key, changed fw path to %s\n",
>>> @@ -303,6 +307,10 @@ int sof_pci_probe(struct pci_dev *pci, const
>>> struct pci_device_id *pci_id)
>>>                   devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
>>>                      
>>> sof_pdata->desc->default_lib_path[sof_pdata->ipc_type],
>>>                       "community");
>>> +            if (!sof_pdata->fw_lib_prefix) {
>>> +                ret = -ENOMEM;
>>> +                goto out;
>>> +            }
>>>                 dev_dbg(dev,
>>>                   "Platform uses community key, changed fw_lib path
>>> to %s\n",
>>

-- 
Péter

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

end of thread, other threads:[~2023-12-05  9:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-23 15:54 [PATCH] ASoC: SOF: Fix null pointer dereference in sof_pci_probe Kunwu Chan
2023-12-04 11:34 ` Péter Ujfalusi
2023-12-04 12:38 ` Mark Brown
2023-12-05  9:12   ` Kunwu Chan
     [not found] ` <1701766721668457.408.seg@mailgw>
2023-12-05  9:10   ` Kunwu Chan
2023-12-05  9:44     ` Péter Ujfalusi

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