From: Max Asbock <masbock@us.ibm.com>
To: Dave Jones <davej@redhat.com>
Cc: Andrew Morton <akpm@osdl.org>,
Srihari Vijayaraghavan <sriharivijayaraghavan@yahoo.com.au>,
linux-kernel@vger.kernel.org, Vernon Mauery <vernux@us.ibm.com>
Subject: Re: Oops on ibmasm
Date: Thu, 09 Mar 2006 09:37:20 -0800 [thread overview]
Message-ID: <1141925840.6240.18.camel@w-amax> (raw)
In-Reply-To: <20060309132655.GA26354@redhat.com>
On Thu, 2006-03-09 at 05:26, Dave Jones wrote:
> On Thu, Mar 09, 2006 at 01:40:23AM -0800, Andrew Morton wrote:
>
> > I assume this'll fix it?
> >
> > I suspect there's no point in the locking around that kobject_put() anyway.
> > Or if there is, it wasn't the right way to fix the race.
> >
> > diff -puN drivers/misc/ibmasm/ibmasm.h~ibmasm-use-after-free-fix drivers/misc/ibmasm/ibmasm.h
> > --- devel/drivers/misc/ibmasm/ibmasm.h~ibmasm-use-after-free-fix 2006-03-09 01:35:05.000000000 -0800
> > +++ devel-akpm/drivers/misc/ibmasm/ibmasm.h 2006-03-09 01:35:16.000000000 -0800
> > @@ -100,11 +100,7 @@ struct command {
> >
> > static inline void command_put(struct command *cmd)
> > {
> > - unsigned long flags;
> > -
> > - spin_lock_irqsave(cmd->lock, flags);
> > kobject_put(&cmd->kobj);
> > - spin_unlock_irqrestore(cmd->lock, flags);
> > }
>
> I don't think this is right. This is just a kobject-convoluted
> use-after-free afaics.
>
I put the locks around the kobject_put after reading
Documentation/kref.txt and after realizing that there was a race. In the
kref.txt example there is a lock around kref_put (only a mutex instead
of a spinlock).
I still think there is a point in putting locks around kobject_put(). Or
is there a better way?
And btw, I am using kobject because this code predates kref. So maybe
one day I should just convert it to kref.
Anyway, I think the locks are necessary, the way they are implemented is
probably ugly and caused me to make the mistake in the first place. But
a while I ago posted the following patch that fixes the situation.
cmd->lock points to a persistent lock that is not freed with cmd.
max
Original patch:
ibmasm driver:
Fix the command_put() function which uses a pointer for a spinlock that
can be freed before dereferencing it.
Signed-off-by: Max Asbock masbock@us.ibm.com
---
diff -burpN linux-2.6.16-rc1/drivers/misc/ibmasm/ibmasm.h linux-2.6.16-rc1.ibmasm/drivers/misc/ibmasm/ibmasm.h
--- linux-2.6.16-rc1/drivers/misc/ibmasm/ibmasm.h 2006-02-01 11:50:01.000000000 -0800
+++ linux-2.6.16-rc1.ibmasm/drivers/misc/ibmasm/ibmasm.h 2006-02-03 13:57:42.000000000 -0800
@@ -101,10 +101,11 @@ struct command {
static inline void command_put(struct command *cmd)
{
unsigned long flags;
+ spinlock_t *lock = cmd->lock;
- spin_lock_irqsave(cmd->lock, flags);
+ spin_lock_irqsave(lock, flags);
kobject_put(&cmd->kobj);
- spin_unlock_irqrestore(cmd->lock, flags);
+ spin_unlock_irqrestore(lock, flags);
}
static inline void command_get(struct command *cmd)
next prev parent reply other threads:[~2006-03-09 17:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-08 22:41 Srihari Vijayaraghavan
2006-03-08 22:59 ` Dave Jones
2006-03-09 6:41 ` Greg KH
2006-03-09 9:40 ` Andrew Morton
2006-03-09 13:26 ` Dave Jones
2006-03-09 17:37 ` Max Asbock [this message]
2006-03-09 21:58 ` Srihari Vijayaraghavan
2006-03-10 4:35 Srihari Vijayaraghavan
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=1141925840.6240.18.camel@w-amax \
--to=masbock@us.ibm.com \
--cc=akpm@osdl.org \
--cc=davej@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sriharivijayaraghavan@yahoo.com.au \
--cc=vernux@us.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®