Skip to contentSkip to conversation

PATCH/FIX for drivers/cdrom/cdrom.c

DISCUSSION Bodo Eggert 8 participants 17 messages Aug 17, 2006 – Aug 21, 2006 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 6 lines · Arjan van de Ven
Quoted 4 lines · Lennart Sorensen

Perhaps the real problem is that some @#$@#$ user space task is constantly trying to mount the disc while something else is trying to write to it.

Quoted 7 lines
Quoted 3 lines

gnome and kde both seem very eager to implement such things.  perhaps there should be a way to prevent any access by such processes while writing to the disc.

there is. O_EXCL works for this.
Any sane desktop app and cd burning app use O_EXCL already for this purpose...

This was discussed to death:

HAL using O_EXCL will randomly prevent burning/mounting/etc by causing a race condition, so it can't do that. HAL not using O_EXCL will OTOH succeed in opening despite of O_EXCL used by the burning process and thereby prevent burning by opening a busy device. The proposed solution was introducing O_NONE or O_HARMLESS to prevent side-effects from opening the device.

This will, however, not prevent other users from maliciously destroying the CD by not using O_EXCL. Chowning the device is not a real solution, since users should be able to fusermount the CD.

Maybe it's possible to cache the result and thereby prevent repeated opening from disturbing the burning process.

Signature · 4 lines
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.

http://david.woodhou.se/why-not-spf.html
#4 lore raw
Quoted 11 lines · Bodo Eggert
Quoted 10 lines · Arjan van de Ven
Quoted 7 lines · Lennart Sorensen

Perhaps the real problem is that some @#$@#$ user space task is constantly trying to mount the disc while something else is trying to write to it.

gnome and kde both seem very eager to implement such things. perhaps there should be a way to prevent any access by such processes while writing to the disc.

Quoted 8 lines
Quoted 3 lines

there is. O_EXCL works for this.
Any sane desktop app and cd burning app use O_EXCL already for this purpose...

This was discussed to death:

HAL using O_EXCL will randomly prevent burning/mounting/etc by causing a race condition, so it can't do that.

all burning apps will retry a few times if they get "busy"....

Quoted 5 lines

HAL not using O_EXCL will OTOH succeed
in opening despite of O_EXCL used by the burning process and thereby prevent burning by opening a busy device. The proposed solution was introducing O_NONE or O_HARMLESS to prevent side-effects from opening the device.

doesn't help, since hal doesn't just open it, but also issues an ioctl that then goes to the device, and THAT is causing the damage. Not the open itself.

Quoted 2 lines

This will, however, not prevent other users from maliciously destroying the CD by not using O_EXCL.

if the user wants to destroy his own burning cd... then why is it the kernels job to stop him?

Quoted 2 lines

Maybe it's possible to cache the result and thereby prevent repeated opening from disturbing the burning process.

oh I really want to have this ioctl cached, but more so that the kernel can enforce a reasonable polling interval ;)

Signature · 1 line
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
#5 lore raw
Quoted 7 lines · Arjan van de Ven
Quoted 2 lines · Bodo Eggert

This will, however, not prevent other users from maliciously destroying the CD by not using O_EXCL.

if the user wants to destroy his own burning cd... then why is it the kernels job to stop him?

It's user a destroying the CD of user b (e.g. because he erroneously believes his CD with the plain tar archive is in the burner, or because he's simply malicious).

Signature · 2 lines
"Of course, as admin, I can read all your email. But I am not THAT bored!"
	-- unknown author in comp.unix.aix
#6 lore raw
Quoted 6 lines · Bodo Eggert
Quoted 5 lines · Arjan van de Ven
Quoted 2 lines · Bodo Eggert

This will, however, not prevent other users from maliciously destroying the CD by not using O_EXCL.

Quoted 6 lines
Quoted 2 lines

if the user wants to destroy his own burning cd... then why is it the kernels job to stop him?

It's user a destroying the CD of user b (e.g. because he erroneously believes his CD with the plain tar archive is in the burner, or because he's simply malicious).

that would only be if both A and B have write access to the same device, at which point they can destroy eachother anyway
(nothing stops user B from issuing a blank command to the cdrw the milisecond A is done)

Signature · 1 line
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
#7 lore raw
In reply to Bodo Eggert

Ar Gwe, 2006-08-18 am 14:31 +0200, ysgrifennodd Bodo Eggert:

Quoted 3 lines

It's user a destroying the CD of user b (e.g. because he erroneously believes his CD with the plain tar archive is in the burner, or because he's simply malicious).

Thats why you need revoke().

Alan

#8 lore raw
In reply to Bodo Eggert

Ar Iau, 2006-08-17 am 14:27 +0200, ysgrifennodd Bodo Eggert:

Quoted 2 lines

HAL using O_EXCL will randomly prevent burning/mounting/etc by causing a race condition, so it can't do that. HAL not using O_EXCL will OTOH succeed

man 3 sleep
man 2 flock

or in the GUI world I'm firmly assured that the sun shines out of the arse of dbus for intra desktop communication.

Lots of solutions.

Quoted 2 lines

Maybe it's possible to cache the result and thereby prevent repeated opening from disturbing the burning process.

We could certainly add an ioctl for this in the new libata layer. We couldn't automate it as with pass through commands the kernel doesn't really know what kind of exclusivity is needed and when.

Not sure its actually useful but its doable.

Alan

#9 lore raw
Quoted 6 lines · Alan Cox

man 3 sleep
man 2 flock

or in the GUI world I'm firmly assured that the sun shines out of the arse of dbus for intra desktop communication.

Quoted 7 lines

Lots of solutions.

We could certainly add an ioctl for this in the new libata layer. We couldn't automate it as with pass through commands the kernel doesn't really know what kind of exclusivity is needed and when.

Not sure its actually useful but its doable.

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive. That way when the burning program opens the device with O_EXCL, no one else can screw it up while it is open. If it happens to be polled by hal when the burning program tries to open it, it can just wait and retry again until it gets it open.

--
Len Sorensen

#10 lore raw
Quoted 6 lines · Lennart Sorensen

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive. That way when the burning program opens the device with O_EXCL, no one else can screw it up while it is open. If it happens to be polled by hal when the burning program tries to open it, it can just wait and retry again until it gets it open.

Such use of O_EXCL is a weird and non-standard behavior.

Jeff

#11 lore raw
Quoted 9 lines · Jeff Garzik
Quoted 6 lines · Lennart Sorensen

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive. That way when the burning program opens the device with O_EXCL, no one else can screw it up while it is open. If it happens to be polled by hal when the burning program tries to open it, it can just wait and retry again until it gets it open.

Such use of O_EXCL is a weird and non-standard behavior.

So what method exists for opening a file/device an guaranteeing that nothing else can do anything to it?

Looking an man 2 open, I can't even see any way O_EXCL even has a normal meaning for a device, so how much more "weird and non-standard" would it be to have it control exclusive access to a device? It appears it is only supposed to have a meaning for creating files.

--
Len Sorensen

#12 lore raw
Quoted 11 lines · Lennart Sorensen
Quoted 9 lines · Jeff Garzik
Quoted 7 lines · Lennart Sorensen

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive. That way when the burning program opens the device with O_EXCL, no one else can screw it up while it is open. If it happens to be polled by hal when the burning program tries to open it, it can just wait and retry again until it gets it open.

Quoted 6 lines
Quoted 2 lines

Such use of O_EXCL is a weird and non-standard behavior.

So what method exists for opening a file/device an guaranteeing that nothing else can do anything to it?

None on the file level I hope, for it will surely get abused. Windows have exclusive open for example, and there acrobat reader locks the pdf file it views, so you can't make a new version without killing acrobat first. (And then you have to restart it to view the new file.) Stupid in the extreme. Fortunately, acrobat can't do that on linux where there is no (easy) opportunity to do so.

There are many other examples - backup sw can't read files that happens to be opened exclusive by some process.

I guess this particular case could be solved by fixing the cdrom driver like this:

Whenever the device is opened for writing (i.e. someone is burning a CD/DVD), then reject the probing ioctls HAL uses. Or just make the device exclusive while burning. Restore
normal operation as soon as the burn ends. There is no
use for reading the device during a burn anyway - a special case for CD/DVD writers.

Helge Hafting

#13 lore raw
Quoted 6 lines · Helge Hafting

None on the file level I hope, for it will surely get abused. Windows have exclusive open for example, and there acrobat reader locks the pdf file it views, so you can't make a new version without killing acrobat first. (And then you have to restart it to view the new file.) Stupid in the extreme. Fortunately, acrobat can't do that on linux where there is no (easy) opportunity to do so.

The default open mode on network-aware DOS-systems will automatically aquire an exclusive lock in order to maintain DOS 2.0 compatibility, and the filename is part of the file's metadata. Windows seems to have kept this behaviour.

Signature · 2 lines
"Bravery is being the only one who knows you're afraid."
-David Hackworth
#14 lore raw
In reply to Lennart Sorensen

Ar Iau, 2006-08-17 am 09:23 -0400, ysgrifennodd Lennart Sorensen:

Quoted 2 lines

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive.

If you were designing a new OS from scratch you might want to explore that semantic as a design idea. I wouldn't recommend it because a lot of apps will be upset if they issue an ioctl and it mysteriously fails or hangs.

Issues of this nature require high level synchronization and that (witness email) is generally done in user space which is the only place that has transaction level visibility.

Alan

#15 lore raw
Quoted 8 lines · Alan Cox

Ar Iau, 2006-08-17 am 09:23 -0400, ysgrifennodd Lennart Sorensen:

Quoted 2 lines

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive.

If you were designing a new OS from scratch you might want to explore that semantic as a design idea. I wouldn't recommend it because a lot of apps will be upset if they issue an ioctl and it mysteriously fails or hangs.

I think hal should get an error when it tries to open the cdrom device when the burning application is using it. It shouldn't even get a chance to issue an ioctl. I was assuming hal doesn't keep the cdrom device open at all times (if it does, well that would be stupid).

Quoted 3 lines

Issues of this nature require high level synchronization and that (witness email) is generally done in user space which is the only place that has transaction level visibility.

Hmm, so how does one tell hal to go to hell and leave the cdrom device alone at all times (other than totally disabling hal). Who the heck wants all that stupid auto crap anyhow. :)

--
Len Sorensen

#16 lore raw
Quoted 5 lines · Lennart Sorensen
Quoted 4 lines · Alan Cox

Ar Iau, 2006-08-17 am 09:23 -0400, ysgrifennodd Lennart Sorensen:

Quoted 2 lines

Why can't O_EXCL mean that the kernel prevents anyone else from issuing ioctl's to the device? One would think that is the meaning of exlusive.

Quoted 7 lines
Quoted 4 lines

If you were designing a new OS from scratch you might want to explore that semantic as a design idea. I wouldn't recommend it because a lot of apps will be upset if they issue an ioctl and it mysteriously fails or hangs.

I think hal should get an error when it tries to open the cdrom device when the burning application is using it.

this is what O_EXCL is for ;)

Quoted 2 lines

Hmm, so how does one tell hal to go to hell and leave the cdrom device alone at all times (other than totally disabling hal).

make sure hal uses O_EXCL, and if not, beat up the hal guys about it ;)

Signature · 1 line
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
#17 lore raw
In reply to Lennart Sorensen

Ar Iau, 2006-08-17 am 10:36 -0400, ysgrifennodd Lennart Sorensen:

Quoted 2 lines

I think hal should get an error when it tries to open the cdrom device when the burning application is using it. It shouldn't even get a

If it uses O_EXCL it will find the device busy assuming both parties use O_EXCL properly.

Quoted 2 lines

chance to issue an ioctl. I was assuming hal doesn't keep the cdrom device open at all times (if it does, well that would be stupid).

Indeed but this is HAL so I suggest you strace it first 8)

#18 lore raw
In reply to Lennart Sorensen
Quoted 3 lines · Lennart Sorensen

Hmm, so how does one tell hal to go to hell and leave the cdrom device alone at all times (other than totally disabling hal).

AFAIK many drivers allow multiple opening of device files. If programs do not honor any kind of locking (advisory, O_EXCL) use mandatory locking (DOS 2.0 compatibility, no problems ;)

Quoted 2 lines

Who the heck wants all that stupid auto crap anyhow. :)

Yea. But see RH managers on its videos, happy about usb sticks being plugged and worked, he-he:
<http://www.redhat.com/v/magazine/mov/005_BehindScenes_RHEL4.mov>.

I've just installed debian-gnu and got all that cpufrequtils, powermgmt, acpiutils installed on amd64 laptop while i just need:
,-

|modprobe powernow-k8
|modprobe cpufreq_ondemand
|echo ondemand >scailing_governor

`-
Anyway long, almost 10 years, way to win95 and win98 is never ending ;D

--
-o--=O`C /. .\ (???) (+) /o o\
#oo'L O o | o.
<___=E M ^-- | (you're barking up the wrong tree) =--'

#19 lore raw
Quoted 13 lines · Oleg Verych

AFAIK many drivers allow multiple opening of device files. If programs do not
honor any kind of locking (advisory, O_EXCL) use mandatory locking (DOS 2.0 compatibility, no problems ;)

Yea. But see RH managers on its videos, happy about usb sticks being plugged and worked, he-he:
<http://www.redhat.com/v/magazine/mov/005_BehindScenes_RHEL4.mov>.

I've just installed debian-gnu and got all that cpufrequtils, powermgmt, acpiutils installed on amd64 laptop while i just need:
,-

Quoted 5 lines
|modprobe powernow-k8
|modprobe cpufreq_ondemand
|echo ondemand >scailing_governor

`-
Anyway long, almost 10 years, way to win95 and win98 is never ending ;D

Don't worry, NT4 didn't do that either, you had to wait for windows 2000 before you got a decent kernel and all the power management and hotplug stuff.

--
Len Sorensen