Getting udev name from usb_device structure

2013-09-19 Thread Sergio Work
Hi all!

I'm writting a LSM hook in order to allow to mount just only some
particular USB Mass Storage devices according to their idVendor,
idProduct, and Serial. The hook is executed when a device is going to
be mounted, and it has the following prototype:

static int sb_mount(const char *dev_name, struct path *path, const char *type,
unsigned long flags, void *data)

The relevant parameter here is dev_name, which provides the name of
the device to be mounted in a "udev" style (e.g. "/dev/sdb1"). So, the
main idea to perform the mount restriction inside the hook is,
firstly, to determine if there is a USB Mass Storage device connected
to the system which is identified as dev_name. After that, I will
inspect if it's corresponding idVendor, idProduct and serial are
considered valid according to a given list of authorized devices, and
then
allow the mount.

Currently, I'm using the usb_for_each_dev function, which gives me
access to the idVendor, idProduct and serial of all the USB devices by
means of the usb_device structure.  However, I don't know how I can
determine which is the "udev device name" associated to each
usb_device structure. I have observed that the name of the "udev
device" is present in the sysfs, so I guess that by accesing to the
kobject of the usb_device I could obtain such mapping (usb_device <->
udev name). I also know that the Mass Storage Devices are considered
as SCSI devices, so I guess that the name can also be obtained from a
structure related with the SCSI subsystem. The problem is that I don't
know which is the best way to find the mapping between the usb_device
and the dev_name parameter. I have tried to inspect all the related
structures without any success :-(

Can anyone advise me about how can I obtain the udev device name of a
USB by means of the usb_device structure. Any other better idea will
be appreciated :-)

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


Re: Getting udev name from usb_device structure

2013-09-20 Thread Sergio Work
> Why would this be an LSM hook?  What's wrong with the existing solutions
> for this that are all in userspace today?

Because we want to apply the restriction of what USB pendrives can be
mounted to all the users of the system, including root. So we need to
perform this in kernel space, otherwise any other userspace solutions
can be manipulated by root.

I guess that it's a little difficult to understand all the deteails
without a whole image of the context, but I can't provide more details
since my NDA doesn't allow me :(

Anyway, if we doesn't consider such aspects, how could I obtain the
udev device name associated to a given usb_device structure.

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