lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1265737574.9195.16.camel@maxim-laptop>
Date:	Tue, 09 Feb 2010 19:46:14 +0200
From:	Maxim Levitsky <maximlevitsky@...il.com>
To:	Peter Zijlstra <peterz@...radead.org>
Cc:	David Woodhouse <dwmw2@...radead.org>,
	Artem Bityutskiy <dedekind1@...il.com>,
	linux-mtd <linux-mtd@...ts.infradead.org>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	Alex Dubov <oakad@...oo.com>, joern <joern@...fs.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	"stanley.miao" <stanley.miao@...driver.com>,
	Vitaly Wool <vitalywool@...il.com>
Subject: Re: [PATCH 01/17] MTD: create lockless versions of
 {get,put}_mtd_device This will be used to resolve deadlock in block
 translation layer.

On Tue, 2010-02-09 at 19:23 +0200, Maxim Levitsky wrote: 
> On Tue, 2010-02-09 at 18:14 +0100, Peter Zijlstra wrote: 
> > On Tue, 2010-02-09 at 18:57 +0200, Maxim Levitsky wrote:
> > > These functions can be used as long as we don't need access to global mtd table, but have
> > > a pointer to the mtd device.
> > > 
> > > Signed-off-by: Maxim Levitsky <maximlevitsky@...il.com>
> > > ---
> > >  drivers/mtd/mtdcore.c   |   60 ++++++++++++++++++++++++++++++----------------
> > >  include/linux/mtd/mtd.h |    3 +-
> > >  2 files changed, 41 insertions(+), 22 deletions(-)
> > 
> > > +int __get_mtd_device(struct mtd_info *mtd)
> > > +{
> > > +	int err;
> > > +
> > > +	if (!try_module_get(mtd->owner))
> > > +		return -ENODEV;
> > > +
> > > +	if (mtd->get_device) {
> > > +
> > > +		err = mtd->get_device(mtd);
> > > +
> > > +		if (err) {
> > > +			module_put(mtd->owner);
> > > +			return err;
> > > +		}
> > > +	}
> > > +	mtd->usecount++;
> > > +	return 0;
> > >  }
> > 
> > > +void __put_mtd_device(struct mtd_info *mtd)
> > > +{
> > > +	--mtd->usecount;
> > > +	BUG_ON(mtd->usecount < 0);
> > > +
> > >  	if (mtd->put_device)
> > >  		mtd->put_device(mtd);
> > >  
> > >  	module_put(mtd->owner);
> > >  }
> > 
> > That's racy, use kref.
> > 
> Couldn't agree with you more.
> 
> However, these functions aren't intended for general use, and probably
> will be used by mtd translation layer only. I do have a lock that
> protects concurrent use of these functions.
> 
> Thus, I better add a comment about this?
However on second thought, there is still a race if two FTLs access same
mtd device.
While this might seem impossible, and I say it is quite dangerous. I can
imagine using both some FTL and mtdblock for testing.

Just using kref (nothing against it) won't help here.
The mtd->get_device/put_device aren't expecting to be called
concurrently ether...

I can add per mtd lock, but it is a bit ugly...

What do you think?

Best regards,
Maxim Levitsky



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ