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]
Date:	Wed, 25 Sep 2013 14:11:05 -0700
From:	Guenter Roeck <linux@...ck-us.net>
To:	Wolfram Sang <wsa@...-dreams.de>
Cc:	linux-i2c@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] i2c: i2c-dev: Create 'name' attribute automatically

On Wed, Sep 25, 2013 at 10:20:35PM +0200, Wolfram Sang wrote:
> On Sat, Aug 31, 2013 at 09:30:19AM -0700, Guenter Roeck wrote:
> > The 'name' attribute is needed for all i2c-dev class devices, meaning
> > it can be created automatically by pointing to it in the class data
> > structure. This simplifies the code and reduces the probability for race
> > conditions.
> 
> What race condition?
> 

Userspace trying to access the name attribute before it is created.
See http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
for details; Greg describes the problem and solution much better than I could
ever do.

> > 
> > Signed-off-by: Guenter Roeck <linux@...ck-us.net>
> > ---
> >  drivers/i2c/i2c-dev.c |   32 ++++++++++++++++----------------
> >  1 file changed, 16 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
> > index c3ccdea..46eea02 100644
> > --- a/drivers/i2c/i2c-dev.c
> > +++ b/drivers/i2c/i2c-dev.c
> > @@ -111,7 +111,11 @@ static ssize_t show_adapter_name(struct device *dev,
> >  		return -ENODEV;
> >  	return sprintf(buf, "%s\n", i2c_dev->adap->name);
> >  }
> > -static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
> > +
> > +static struct device_attribute i2c_dev_attributes[] = {
> > +	__ATTR(name, S_IRUGO, show_adapter_name, NULL),
> > +	{ }
> > +};
> >  
> >  /* ------------------------------------------------------------------------- */
> >  
> > @@ -538,7 +542,11 @@ static const struct file_operations i2cdev_fops = {
> >  
> >  /* ------------------------------------------------------------------------- */
> >  
> > -static struct class *i2c_dev_class;
> > +static struct class i2c_dev_class = {
> > +	.owner = THIS_MODULE,
> > +	.name = "i2c-dev",
> > +	.dev_attrs = i2c_dev_attributes,
> > +};
> 
> Have you tried this with two instances? I don't think it will work since
> class_register modifies the class struct.
> 
Half a dozen instances, actually. Unless I am missing something, seems to be
unlikely that there is a problem, since the kernel would fail all over the place
if there was a problem with class->dev_attrs (or its replacement dev_groups);

Anyway, the patch is obsolete; one is supposed to use class->dev_groups now.

Thanks,
Guenter
--
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