Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1330291 > unrolled thread

Should snd_card_free() check for null pointer?

Started byJerome Marchand <jmarchan@redhat.com>
First post2016-02-09 15:40 +0100
Last post2016-02-10 09:50 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  Should snd_card_free() check for null pointer? Jerome Marchand <jmarchan@redhat.com> - 2016-02-09 15:40 +0100
    Re: Should snd_card_free() check for null pointer? Takashi Iwai <tiwai@suse.de> - 2016-02-09 23:00 +0100
      Re: Should snd_card_free() check for null pointer? Jerome Marchand <jmarchan@redhat.com> - 2016-02-10 08:50 +0100
        Re: Should snd_card_free() check for null pointer? Takashi Iwai <tiwai@suse.de> - 2016-02-10 09:50 +0100

#1330291 — Should snd_card_free() check for null pointer?

FromJerome Marchand <jmarchan@redhat.com>
Date2016-02-09 15:40 +0100
SubjectShould snd_card_free() check for null pointer?
Message-ID<r0hCq-5hG-19@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view 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

[toc] | [next] | [standalone]


#1330673

FromTakashi Iwai <tiwai@suse.de>
Date2016-02-09 23:00 +0100
Message-ID<r0ouf-1tt-21@gated-at.bofh.it>
In reply to#1330291
On Tue, 09 Feb 2016 15:30:16 +0100,
Jerome Marchand wrote:
> 
> 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

[toc] | [prev] | [next] | [standalone]


#1330938

FromJerome Marchand <jmarchan@redhat.com>
Date2016-02-10 08:50 +0100
Message-ID<r0xHb-7GV-7@gated-at.bofh.it>
In reply to#1330673
----- Original Message -----
> From: "Takashi Iwai" <tiwai@suse.de>
> To: "Jerome Marchand" <jmarchan@redhat.com>
> Cc: "Jaroslav Kysela" <perex@perex.cz>, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
> Sent: Tuesday, February 9, 2016 10:56:39 PM
> Subject: Re: Should snd_card_free() check for null pointer?
> 
> On Tue, 09 Feb 2016 15:30:16 +0100,
> Jerome Marchand wrote:
> > 
> > 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.

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

> 
> 
> thanks,
> 
> Takashi
> 

[toc] | [prev] | [next] | [standalone]


#1330947

FromTakashi Iwai <tiwai@suse.de>
Date2016-02-10 09:50 +0100
Message-ID<r0yDg-8hG-1@gated-at.bofh.it>
In reply to#1330938
On Wed, 10 Feb 2016 08:41:38 +0100,
Jerome Marchand wrote:
> 
> ----- Original Message -----
> > From: "Takashi Iwai" <tiwai@suse.de>
> > To: "Jerome Marchand" <jmarchan@redhat.com>
> > Cc: "Jaroslav Kysela" <perex@perex.cz>, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
> > Sent: Tuesday, February 9, 2016 10:56:39 PM
> > Subject: Re: Should snd_card_free() check for null pointer?
> > 
> > On Tue, 09 Feb 2016 15:30:16 +0100,
> > Jerome Marchand wrote:
> > > 
> > > 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.
> 
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web