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:   Sun, 3 Mar 2019 16:40:56 -0500
From:   Kimberly Brown <kimbrownkd@...il.com>
To:     Michael Kelley <mikelley@...rosoft.com>
Cc:     Long Li <longli@...rosoft.com>,
        Sasha Levin <Alexander.Levin@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        Dexuan Cui <decui@...rosoft.com>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        KY Srinivasan <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        "linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4] Drivers: hv: vmbus: Expose monitor data only when
 monitor pages are used

On Sat, Mar 02, 2019 at 06:39:30PM +0000, Michael Kelley wrote:
> From: Kimberly Brown <kimbrownkd@...il.com>  Sent: Friday, March 1, 2019 11:18 AM
> > 
> > +/*
> > + * Channel-level attribute_group callback function. Returns the permission for
> > + * each attribute, and returns 0 if an attribute is not visible.
> > + */
> > +static umode_t vmbus_chan_attr_is_visible(struct kobject *kobj,
> > +					  struct attribute *attr, int idx)
> > +{
> > +	const struct vmbus_channel *channel =
> > +		container_of(kobj, struct vmbus_channel, kobj);
> > +
> > +	/* Hide the monitor attributes if the monitor mechanism is not used. */
> > +	if (!channel->offermsg.monitor_allocated &&
> > +	    (attr == &chan_attr_pending.attr ||
> > +	     attr == &chan_attr_latency.attr ||
> > +	     attr == &chan_attr_monitor_id.attr))
> > +		return 0;
> > +
> > +	return attr->mode;
> > +}
> > +
> > +static struct attribute_group vmbus_chan_group = {
> > +	.attrs = vmbus_chan_attrs,
> > +	.is_visible = vmbus_chan_attr_is_visible
> > +};
> > +
> >  static struct kobj_type vmbus_chan_ktype = {
> >  	.sysfs_ops = &vmbus_chan_sysfs_ops,
> >  	.release = vmbus_chan_release,
> > -	.default_attrs = vmbus_chan_attrs,
> 
> Just to double-check my understanding, removing the default_attrs
> here means that in vmbus_add_channel_kobj(), the call to
> kobject_init_and_add() will only create the sub-directory that is the
> channel number.  The sub-directory will be empty.  Then the new
> call to sysfs_create_group() that you added below will populate
> the subdirectory, as filtered by vmbus_chan_attr_is_visible().

Yes, that's my understanding as well.

> 
> >  };
> > 
> >  /*
> > @@ -1571,6 +1624,12 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct
> > vmbus_channel *channel)
> >  	if (ret)
> >  		return ret;
> > 
> > +	ret = sysfs_create_group(kobj, &vmbus_chan_group);
> > +	if (ret) {
> > +		pr_err("Unable to set up channel sysfs files\n");
> > +		return ret;
> 
> In this error case, the previously created sub-directory that is the
> channel number needs to be deleted/cleaned up.

I was going to let the kobject and sysfs systems take care of that. If
vmbus_add_channel_kobj() returns an error to the calling functions, they
call kobject_put(), which eventually removes the directory.

There are two functions that call vmbus_add_channel_kobj():
vmbus_add_channel_work() and vmbus_device_register(). If
vmbus_add_channel_kobj() returns an error to vmbus_add_channel_work(),
the function calls are:

free_channel() => kobject_put() (channel kobj ref. count should now be
0) => kobject_release() => kobject_cleanup() => kobject_del() =>
sysfs_remove_dir()

If vmbus_add_channel_kobject() returns an error to
vmbus_device_register(), the device's sub-directory is removed:

device_unregister() => put_device() => kobject_put() (device kobj ref.
count should now be 0) => kobject_release() => ...


So, I don't think its necessary to cleanup the subdirectory created by
kobject_init_and_add() here.

Thanks,
Kim


> 
> > +	}
> > +
> 
> Michael

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ