All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Bunk <bunk@kernel.org>
To: Alexey Starikovskiy <aystarik@gmail.com>
Cc: Alexey Starikovskiy <astarikovskiy@suse.de>,
	Len Brown <len.brown@intel.com>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [2.6 patch] acpi/ec.c: fix use-after-free
Date: Wed, 24 Oct 2007 19:26:04 +0200	[thread overview]
Message-ID: <20071024172604.GD30533@stusta.de> (raw)
In-Reply-To: <471F7DA6.2060907@gmail.com>

On Wed, Oct 24, 2007 at 09:15:18PM +0400, Alexey Starikovskiy wrote:
> Adrian,
> 
> commit 30c08574da0ead1a47797ce028218ce5b2de61c7 can not introduce use-after-free.
> 
> Please check...


Commit 30c08574da0ead1a47797ce028218ce5b2de61c7 did:

<--  snip  -->

 	list_for_each_entry(handler, &ec->list, node) {
                if (query_bit == handler->query_bit) {
                        list_del(&handler->node);
                        kfree(handler);
-                       break;
                }
	}

<--  snip  -->


If you look at the definition of list_for_each_entry() in 
include/linux/list.h:

<--  snip  -->

#define list_for_each_entry(pos, head, member)                          \
        for (pos = list_entry((head)->next, typeof(*pos), member);      \
             prefetch(pos->member.next), &pos->member != (head);        \
             pos = list_entry(pos->member.next, typeof(*pos), member))
                              ^^^^^^^^^^^^^^^^

<--  snip  -->


Without the "break", "handler" is being dereferenced after it was freed.


> Regards,
> Alex.
> Adrian Bunk wrote:
> > This patch fixes a use-after-free introduced by
> > commit 30c08574da0ead1a47797ce028218ce5b2de61c7.
> > 
> > Spotted by the Coverity checker.
> > 
> > Signed-off-by: Adrian Bunk <bunk@kernel.org>
> > 
> > ---
> > --- linux-2.6/drivers/acpi/ec.c.old	2007-10-23 19:39:47.000000000 +0200
> > +++ linux-2.6/drivers/acpi/ec.c	2007-10-23 19:34:55.000000000 +0200
> > @@ -434,11 +442,11 @@
> >  EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
> >  
> >  void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
> >  {
> > -	struct acpi_ec_query_handler *handler;
> > +	struct acpi_ec_query_handler *handler, *tmp;
> >  	mutex_lock(&ec->lock);
> > -	list_for_each_entry(handler, &ec->list, node) {
> > +	list_for_each_entry_safe(handler, tmp, &ec->list, node) {
> >  		if (query_bit == handler->query_bit) {
> >  			list_del(&handler->node);
> >  			kfree(handler);
> >  		}
> > 


cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


  reply	other threads:[~2007-10-24 17:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-24 16:26 [2.6 patch] acpi/ec.c: fix use-after-free Adrian Bunk
2007-10-24 17:15 ` Alexey Starikovskiy
2007-10-24 17:26   ` Adrian Bunk [this message]
2007-10-24 17:30     ` Alexey Starikovskiy
2007-10-25 20:38       ` Len Brown

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=20071024172604.GD30533@stusta.de \
    --to=bunk@kernel.org \
    --cc=astarikovskiy@suse.de \
    --cc=aystarik@gmail.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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.