Re: Write protect access on USB port [WORKS]

2012-11-28 Thread Amit
Pascal Hambourg plouf.fr.eu.org> writes: > > Amit a écrit : > > Pascal Hambourg plouf.fr.eu.org> writes: > > > >> That's because the filesystem is on a partition, not on the whole disk, > >> an the partition block device is still read-write. > >> The read-only flag must be set on the disk and

Re: Write protect access on USB port

2012-11-28 Thread Pascal Hambourg
Amit a écrit : > Pascal Hambourg plouf.fr.eu.org> writes: > >> That's because the filesystem is on a partition, not on the whole disk, >> an the partition block device is still read-write. >> The read-only flag must be set on the disk and all its partitions. I >> guess udev can do this. > > I di

Re: Write protect access on USB port

2012-11-27 Thread Amit
Pascal Hambourg plouf.fr.eu.org> writes: > That's because the filesystem is on a partition, not on the whole disk, > an the partition block device is still read-write. > The read-only flag must be set on the disk and all its partitions. I > guess udev can do this. > I did this for the block devi

Re: Write protect access on USB port

2012-11-27 Thread Pascal Hambourg
Amit a écrit : > > However, this still poses a problem. Check out the following case: > > 1. Plug in a USB drive with an ext4 filesystem. > 2. Set the readonly flag using blockdev. > 3. Compute the checksum on this block device. > 4. Mount the ext4 filesytem and then unmount it without doing

Re: Write protect access on USB port

2012-11-27 Thread Andrei POPESCU
On Lu, 26 nov 12, 23:51:32, Amit wrote: > > Now, for example, there have been cases where I accidentaly (as root), > do a dd and overwrite a portion of the drive I was analyzing/reading from. Ok, I understand now. In my opinion such safety nets are dangerous, because they tend to encourage carel

Re: Write protect access on USB port

2012-11-27 Thread Pascal Hambourg
Hello, Dom a écrit : > > I just tested a basic udev rule which sets read-only permissions on any > usb disk when inserted. [...] > > #Make USB storage devices read only > KERNEL=="sd*",ACTION=="add",ENV{ID_BUS}=="usb",MODE="0444" This won't work, root ignores file permissions. -- To UNSUBSC

Re: Write protect access on USB port

2012-11-27 Thread Amit
Kushal Kumaran gmail.com> writes: > > There is a blockdev command with a --setro option in the util-linux > package. You can modify your udev rules to run this command when the > device is plugged in. > Thanks I did not know about this tool. I looked at it and it accomplishes the read-only se

Re: Write protect access on USB port

2012-11-26 Thread Dom
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 no

Re: Write protect access on USB port

2012-11-26 Thread Kushal Kumaran
Amit writes: > Andrei POPESCU gmail.com> writes: > >> >> On Lu, 26 nov 12, 22:33:51, Amit wrote: >> > >> > Yes, I basically want to avoid even the root user (or process with root >> > privileges) to able to access this. So the kernel has to be replaced in >> > order to disable the "write prote

Re: Write protect access on USB port

2012-11-26 Thread Amit
Andrei POPESCU gmail.com> writes: > > On Lu, 26 nov 12, 22:33:51, Amit wrote: > > > > Yes, I basically want to avoid even the root user (or process with root > > privileges) to able to access this. So the kernel has to be replaced in > > order to disable the "write protect" on that USB port. >

Re: Write protect access on USB port

2012-11-26 Thread Andrei POPESCU
On Lu, 26 nov 12, 22:33:51, Amit wrote: > > Yes, I basically want to avoid even the root user (or process with root > privileges) to able to access this. So the kernel has to be replaced in > order to disable the "write protect" on that USB port. > > It is more of a guarantee that there can be no

Re: Write protect access on USB port

2012-11-26 Thread Amit
Andrei POPESCU gmail.com> writes: > > 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

Re: Write protect access on USB port

2012-11-26 Thread Andrei POPESCU
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, ther

Re: Write protect access on USB port

2012-11-26 Thread berenger . morel
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. T

Re: Write protect access on USB port

2012-11-26 Thread Amit
neutralite.org> writes: > > If a partition is mounted as read-only, I think no software will be > able to write on it, because the kernel is responsible of what will > happen. Low level open&close functions just call kernel's API, so if the > kernel refuse writings, I can not see a solution t

Re: Write protect access on USB port

2012-11-26 Thread Tom Furie
On Mon, Nov 26, 2012 at 09:28:19PM +, Amit wrote: > > Thanks for the reply. I was looking for block level write protect. That > is, nobody can write a simple C program and use the open call and write > garbage to the device. Tweak the udev rules to remove write permissions on the USB bus? Ch

Re: Write protect access on USB port

2012-11-26 Thread berenger . morel
Le 26.11.2012 22:28, Amit a écrit : neutralite.org> writes: You can enable read-only on partitions by using the "ro" flag in fstab. By example: # proc/proc procdefaults0 0 #Entry for /dev/sda6 : UUID=85bb1632-546f-460f-8cc7-5b15fd2c046b /

Re: Write protect access on USB port

2012-11-26 Thread Amit
neutralite.org> writes: > > You can enable read-only on partitions by using the "ro" flag in fstab. > > By example: > # > > proc /proc procdefaults0 0 > #Entry for /dev/sda6 : > UUID=85bb1632-546f-460f-8cc7-5b15fd2c046b / ext4 > noatime,error

Re: Write protect access on USB port

2012-11-26 Thread berenger . morel
You can enable read-only on partitions by using the "ro" flag in fstab. By example: # proc/proc procdefaults0 0 #Entry for /dev/sda6 : UUID=85bb1632-546f-460f-8cc7-5b15fd2c046b / ext4 noatime,errors=remount-ro 0 1 Here, / will

Write protect access on USB port

2012-11-26 Thread Amit
Hello, I would like to block write access by default to all drives plugged in to my USB port (a specific USB port). This capability would probably be at the kernel level to be effective. Doing research on LWN.net, I noticed the following sentence by Corbet: (http://lwn.net/Articles/428533/): En