linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: How to use Udev to restrict USB access only to particular set of
Date: Thu, 24 Feb 2011 17:01:07 +0000	[thread overview]
Message-ID: <20110224170107.GA7841@kroah.com> (raw)
In-Reply-To: <AANLkTinqeg=o_bmdR0CKuVmP14x71kkrE3=zdaxx2AE=@mail.gmail.com>

On Thu, Feb 24, 2011 at 06:36:19PM +0200, Vilius Benetis wrote:
> On Thu, Feb 24, 2011 at 5:46 PM, Greg KH <greg@kroah.com> wrote:
> >>[vilius]
> >> we tried to disable USB storage sticks with the following command:
> >>
> >> SUBSYSTEMS="usb" DRIVERS="usb-storage"  OPTIONS:="ignore_device"
> >>
> >> but we failed to make it work.
> >
> > Ignoring the device still makes it "active" in the system, especially as
> > you just tested that the usb-storage device was bound to your device
> > (which wouldn't be true that early in the process, which is one reason
> > why this failed).
> >
> > you need to write a 0 to the "authorized" file in sysfs which will
> > disable the whole USB device entirely if it meets your "list of devices
> > to reject".  You also need to test not for driver binding, which again
> > will not have happened, and you don't want to have happen, but that it
> > is a usb storage device type (by virtue of the correct class config
> > options as shown by sysfs) and that it doesn't pass your list of valid
> > serial numbers.
> >
> > Note, all of that might be easier to do in a script than in a udev rule
> > alone, but it should be possible.
> 
> I can follow the logic, but I think I am not able to convert the
> guidance to the actions.
> 
> do you mean (am not sure what is this "authorised" file in sysfs):
> 
> KERNEL!="sd[a-z][0-9]", GOTO="end_usb_key_filter"

Nope, way too late, you want to catch things _before_ the usb-storage
driver binds to it, right?

So match on a usb interfaces, and look at the class values to match the
usb storage ones.  If they are a match, then go up a level and disable
the device by writing a 0 to the "authorized" file.

> SUBSYSTEM="usb", ATTRS{serial}="xx1", GOTO="end_usb_key_filter"
> SUBSYSTEM="usb", ATTRS{serial}="xx2", GOTO="end_usb_key_filter"
> SUBSYSTEM="usb", RUN="echo 0 >/sys/xxx"
> 
> or just:
> 
> SUBSYSTEM="usb", ATTRS{serial}="xx1|xx2|xx3", GOTO="end_usb_key_filter"
> SUBSYSTEM="usb", RUN="echo 0 >/sys/xxx"
> LABEL="end_usb_key_filter"

That might work, but watch out that you don't deactivate your USB
keyboards :)

thanks,

greg k-h

  parent reply	other threads:[~2011-02-24 17:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21  9:01 How to use Udev to restrict USB access only to particular set of USB sticks? Vilius Benetis
2011-02-21  9:05 ` How to use Udev to restrict USB access only to particular set of Andrey Borzenkov
2011-02-21  9:27 ` Vilius Benetis
2011-02-21 15:57 ` How to use Udev to restrict USB access only to particular set Greg KH
2011-02-22 13:46 ` How to use Udev to restrict USB access only to particular set of Vilius Benetis
2011-02-22 13:54 ` How to use Udev to restrict USB access only to particular set Greg KH
2011-02-22 14:01 ` How to use Udev to restrict USB access only to particular set of Vilius Benetis
2011-02-22 14:28 ` Vilius Benetis
2011-02-22 14:38 ` How to use Udev to restrict USB access only to particular set Greg KH
2011-02-24 13:52 ` How to use Udev to restrict USB access only to particular set of Vilius Benetis
2011-02-24 15:46 ` Greg KH
2011-02-24 16:36 ` Vilius Benetis
2011-02-24 17:01 ` Greg KH [this message]
2011-02-24 17:36 ` Vilius Benetis
2011-03-01 14:32 ` Vilius Benetis
2011-03-02  7:06 ` How to use Udev to restrict USB access only to particular set Bryan Kadzban
2011-03-02  8:33 ` How to use Udev to restrict USB access only to particular set of Vilius Benetis
2011-03-03  4:01 ` How to use Udev to restrict USB access only to particular set Bryan Kadzban

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=20110224170107.GA7841@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-hotplug@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).