Skip to contentSkip to conversation

Should snd_card_free() check for null pointer?

DISCUSSION Jerome Marchand 2 participants 4 messages Feb 9, 2016 – Feb 10, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

Before commit f24640648186b (ALSA: Use standard device refcount for card accounting), snd_card_free() would return -EINVAL on a null pointer. Now it ends up in a null pointer dereference. There is at least one driver that can call snd_card_free() with null argument: saa7134_alsa. It can easily be triggered by just inserting and removing the module (no need to have the hardware).
I don't think that is a rule, but it seems that the standard behavior of *_free() functions is to check for null pointer. What do you think?

Thanks,
Jerome

#1 lore raw
Quoted 11 lines · Jerome Marchand

Hi,

Before commit f24640648186b (ALSA: Use standard device refcount for card accounting), snd_card_free() would return -EINVAL on a null pointer. Now it ends up in a null pointer dereference. There is at least one driver that can call snd_card_free() with null argument: saa7134_alsa. It can easily be triggered by just inserting and removing the module (no need to have the hardware).
I don't think that is a rule, but it seems that the standard behavior of *_free() functions is to check for null pointer. What do you think?

Well, I have a mixed feeling about this. Allowing NULL sometimes makes the code easier. OTOH, caling snd_card_free() with NULL is really an unexpected situation, and if a driver does it, most likely it does something weird.

So, at this moment, I would fix the caller side. But, it's not a final call, just my gut feeling.

thanks,

Takashi

#2 lore raw

----- Original Message -----

Quoted 20 lines

From: "Takashi Iwai" <[email protected]>
To: "Jerome Marchand" <[email protected]>
Cc: "Jaroslav Kysela" <[email protected]>, [email protected], [email protected]
Sent: Tuesday, February 9, 2016 10:56:39 PM
Subject: Re: Should snd_card_free() check for null pointer?

Quoted 11 lines · Jerome Marchand

Hi,

Before commit f24640648186b (ALSA: Use standard device refcount for card accounting), snd_card_free() would return -EINVAL on a null pointer. Now it ends up in a null pointer dereference. There is at least one driver that can call snd_card_free() with null argument: saa7134_alsa. It can easily be triggered by just inserting and removing the module (no need to have the hardware).
I don't think that is a rule, but it seems that the standard behavior of *_free() functions is to check for null pointer. What do you think?

Quoted 7 lines

Well, I have a mixed feeling about this. Allowing NULL sometimes makes the code easier. OTOH, caling snd_card_free() with NULL is really an unexpected situation, and if a driver does it, most likely it does something weird.

So, at this moment, I would fix the caller side. But, it's not a final call, just my gut feeling.

I have no strong opinion either way and I have a patch that fixes saa7134 driver ready to be sent if that is your preference.

Thanks,
Jerome

Quoted 6 lines

thanks,

Takashi

#3 lore raw
Quoted 27 lines · Jerome Marchand

----- Original Message -----

Quoted 25 lines

From: "Takashi Iwai" <[email protected]>
To: "Jerome Marchand" <[email protected]>
Cc: "Jaroslav Kysela" <[email protected]>, [email protected], [email protected]
Sent: Tuesday, February 9, 2016 10:56:39 PM
Subject: Re: Should snd_card_free() check for null pointer?

Quoted 11 lines · Jerome Marchand

Hi,

Before commit f24640648186b (ALSA: Use standard device refcount for card accounting), snd_card_free() would return -EINVAL on a null pointer. Now it ends up in a null pointer dereference. There is at least one driver that can call snd_card_free() with null argument: saa7134_alsa. It can easily be triggered by just inserting and removing the module (no need to have the hardware).
I don't think that is a rule, but it seems that the standard behavior of *_free() functions is to check for null pointer. What do you think?

Well, I have a mixed feeling about this. Allowing NULL sometimes makes the code easier. OTOH, caling snd_card_free() with NULL is really an unexpected situation, and if a driver does it, most likely it does something weird.

Quoted 5 lines
Quoted 2 lines

So, at this moment, I would fix the caller side. But, it's not a final call, just my gut feeling.

I have no strong opinion either way and I have a patch that fixes saa7134 driver ready to be sent if that is your preference.

Go ahead, let's fix saa7134 side for now.

thanks,

Takashi