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

Re: Write protect access on USB port



On 26/11/12 22:18, Andrei POPESCU wrote:
On Lu, 26 nov 12, 21:47:36, Amit wrote:

Yes the above would work in most cases but in the case I am dealing
with, the filesystem is not mounted yet. For example, I plug in a USB
drive.  Before it is mounted, there is a /dev/sd[x] node. I can open
this node and write anything I want, thereby corrupting the filesystem
on that device.

Not unless you are 'root' or member of group 'floppy':

$ ls -l /dev/sdb1
brw-rw---T 1 root floppy 8, 17 nov 27 00:14 /dev/sdb1

You could just tweak the relevant udev rule to create the device nodes
as root:root or root:disk (like hard drives), since root would be able
to circumvent any protection and 'disk' is almost the same as 'root'.

I just tested a basic udev rule which sets read-only permissions on any usb disk when inserted. Obviously root would be able to change those permissions, but I don't believe any command (other than chmod) would override read-only for the device file.

dom@oz:~$ cat /etc/udev/rules.d/99-usb-ro.rules:

#Make USB storage devices read only
KERNEL=="sd*",ACTION=="add",ENV{ID_BUS}=="usb",MODE="0444"

dom@oz:~$#(plugs in usb storage device)
dom@oz:~$ ls -l /dev/sd*
brw-rw---T 1 root disk   8,  0 Nov 27 03:16 /dev/sda
brw-rw---T 1 root disk   8,  1 Nov 27 03:16 /dev/sda1
brw-rw---T 1 root disk   8,  2 Nov 27 03:16 /dev/sda2
br--r--r-T 1 root floppy 8, 16 Nov 27 07:12 /dev/sdb
br--r--r-T 1 root floppy 8, 17 Nov 27 07:12 /dev/sdb1
dom@oz:~$

The rule may need a bit of tweaking perhaps. I'm not a udev expert by a long way.
--
Dom


Reply to: