Re: [PATCH v5 2/6] usb: interface authorization: Introduces the default interface authorization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 27, 2015 at 09:50:44AM +0200, Stefan Koch wrote:
> Am Mittwoch, den 22.07.2015, 16:40 -0700 schrieb Greg KH:
> > On Thu, Jun 18, 2015 at 07:23:22PM +0200, Stefan Koch wrote:
> > > Interfaces are allowed per default.
> > > This can disabled or enabled (again) by writing 0 or 1 to
> > > /sys/bus/usb/devices/usbX/interface_authorized_default
> > > 
> > > Signed-off-by: Stefan Koch <skoch@xxxxxxx>
> > > ---
> > >  drivers/usb/core/hcd.c     | 52 ++++++++++++++++++++++++++++++++++++++++++++++
> > >  drivers/usb/core/message.c |  2 ++
> > >  include/linux/usb/hcd.h    |  3 +++
> > >  3 files changed, 57 insertions(+)
> > > 
> > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> > > index 45a915c..4ceb753 100644
> > > --- a/drivers/usb/core/hcd.c
> > > +++ b/drivers/usb/core/hcd.c
> > > @@ -882,9 +882,58 @@ static ssize_t authorized_default_store(struct device *dev,
> > >  }
> > >  static DEVICE_ATTR_RW(authorized_default);
> > >  
> > > +/*
> > > + * interface_authorized_default_show - show default authorization status
> > > + * for USB interfaces
> > > + *
> > > + * note: interface_auhorized_default is the default value
> > > + *       for initializing the authorized attribute of interfaces
> > > + */
> > > +static ssize_t interface_authorized_default_show(struct device *dev,
> > > +		struct device_attribute *attr, char *buf)
> > > +{
> > > +	struct usb_device *usb_dev = to_usb_device(dev);
> > > +	struct usb_hcd *hcd = bus_to_hcd(usb_dev->bus);
> > > +	unsigned def = HCD_INTERFACE_AUTHORIZED_DEFAULT(hcd) ? 1 : 0;
> > > +
> > > +	return sprintf(buf, "%u\n", def);
> > > +}
> > > +
> > > +/*
> > > + * interface_authorized_default_store - store default authorization status
> > > + * for USB interfaces
> > > + *
> > > + * note: interface_auhorized_default is the default value
> > > + *       for initializing the authorized attribute of interfaces
> > > + */
> > > +static ssize_t interface_authorized_default_store(struct device *dev,
> > > +		struct device_attribute *attr, const char *buf, size_t count)
> > > +{
> > > +	struct usb_device *usb_dev = to_usb_device(dev);
> > > +	struct usb_hcd *hcd = bus_to_hcd(usb_dev->bus);
> > > +	int rc = count;
> > > +	bool val;
> > > +
> > > +	if (strtobool(buf, &val) != 0)
> > > +		return -EINVAL;
> > > +
> > > +	switch (val) {
> > > +	case 0:
> > > +		clear_bit(HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT, &hcd->flags);
> > > +		break;
> > > +	case 1:
> > > +		set_bit(HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT, &hcd->flags);
> > > +		break;
> > > +	}
> > > +
> > > +	return rc;
> > > +}
> > > +static DEVICE_ATTR_RW(interface_authorized_default);
> > > +
> > >  /* Group all the USB bus attributes */
> > >  static struct attribute *usb_bus_attrs[] = {
> > >  		&dev_attr_authorized_default.attr,
> > > +		&dev_attr_interface_authorized_default.attr,
> > >  		NULL,
> > >  };
> > >  
> > > @@ -2679,6 +2728,9 @@ int usb_add_hcd(struct usb_hcd *hcd,
> > >  		hcd->authorized_default = authorized_default;
> > >  	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
> > >  
> > > +	/* per default all interfaces are authorized */
> > > +	set_bit(HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT, &hcd->flags);
> > > +
> > >  	/* HC is in reset state, but accessible.  Now do the one-time init,
> > >  	 * bottom up so that hcds can customize the root hubs before hub_wq
> > >  	 * starts talking to them.  (Note, bus id is assigned early too.)
> > > diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
> > > index f368d20..1e85f62 100644
> > > --- a/drivers/usb/core/message.c
> > > +++ b/drivers/usb/core/message.c
> > > @@ -1807,6 +1807,8 @@ free_interfaces:
> > >  		intfc = cp->intf_cache[i];
> > >  		intf->altsetting = intfc->altsetting;
> > >  		intf->num_altsetting = intfc->num_altsetting;
> > > +		intf->authorized =
> > > +				HCD_INTERFACE_AUTHORIZED_DEFAULT(hcd) ? 1 : 0;
> > >  		kref_get(&intfc->ref);
> > >  
> > >  		alt = usb_altnum_to_altsetting(intf, 0);
> > > diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
> > > index 68b1e83..93c19b2 100644
> > > --- a/include/linux/usb/hcd.h
> > > +++ b/include/linux/usb/hcd.h
> > > @@ -120,6 +120,7 @@ struct usb_hcd {
> > >  #define HCD_FLAG_WAKEUP_PENDING		4	/* root hub is resuming? */
> > >  #define HCD_FLAG_RH_RUNNING		5	/* root hub is running? */
> > >  #define HCD_FLAG_DEAD			6	/* controller has died? */
> > > +#define HCD_FLAG_INTERFACE_AUTHORIZED_DEFAULT	8
> > 
> > Why not pick 7?
> > 
> > And that's a huge name, how about 'HCD_FLAG_INTF_AUTHORIZED'?
> > 
> 
> 7 is used that 6 can used later for the device authorization.

What does that mean?  We don't plan ahead for things that might someday
come in the future, unless they are part of the patchset being reviewed.

> Furthermore see Alan's second reply to [PATCH v3 2/6].

I have no idea what that response was, sorry, it's long gone from my
archives.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux