Why side-effects on open(2) are evil. (was Re: [RFD w/info-PATCH] device arguments from lookup)
Quoted 4 lines
Quoted 1 line
Opening device files often has interesting side effects.
Too bad. They can be triggered by similar races between attacker changing the type of object (file<->symlink) and backup.
Yes. This is a well-known security problem.
Doing
stat("file", &s);
if (action desired) {
action("file");
}
is no good because there is a race.
But doing
fd = open("file", flags);
fstat(fd, &s);
if (action desired) {
f_action(fd);
}is no good either because the open() has unknown side effects. It helps to add flags like O_NONBLOCK and perhaps O_NOCTTY, but that is not quite good enough.
One would like to have a version of the open() call that was guaranteed free of side effects, and gave a fd only - perhaps for stat(), perhaps for ioctl().
This guarantee could perhaps be obtained by omitting the
f->f_op->open(inode,f);
call in dentry_open() when the open call is
open("file", O_FDONLY);
Of course it may be that we afterwards decide that fd must
be used, and then it needs upgrading:
fd = f_open(fd, O_RDWR);Andries
[Such a construction allows various cleanups.
But no doubt it has problems that I have not yet thought of.]
Quoted 10 lines · On Sat, 19 May 2001 [email protected] wrote:
One would like to have a version of the
open()call that was guaranteed free of side effects, and gave a fd only - perhaps forstat(), perhaps forioctl().
This guarantee could perhaps be obtained by omitting thef->f_op->open(inode,f); call in dentry_open() when the open call is open("file", O_FDONLY); Of course it may be that we afterwards decide that fd must be used, and then it needs upgrading: fd = f_open(fd, O_RDWR);
clone(), walk(), clunk(), stat() and open() ;-) Basically, we can add unopened descriptors. I.e. no IO until you open it (turning the thing into opened one), but we can do lookups (move to child), we can clone and kill them and we can stat them.
It makes tree traversals much easier, but AFAIK nobody had exported that API directly to userland. Might be a good idea, but it's completely non-portable...
Quoted 4 lines · Alexander Viro
clone(),walk(),clunk(),stat()andopen();-) Basically, we can add unopened descriptors. I.e. no IO until you open it (turning the thing into opened one), but we can do lookups (move to child), we can clone and kill them and we can stat them.
Those who would like a more detailed explanation can find one at
http://plan9.bell-labs.com/sys/man/5/INDEX.html
Signature · 1 line
Revolutions do not require corporate support.
Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Alexander Viro
clone(),walk(),clunk(),stat()andopen();-) Basically, we can add unopened descriptors. I.e. no IO until you open it (turning the thing into opened one), but we can do lookups (move to child), we can clone and kill them and we can stat them.Those who would like a more detailed explanation can find one at
http://plan9.bell-labs.com/sys/man/5/INDEX.html
Umm... Yes, it's an allusion to 9P, but no, I'm not serious about exporting that to userland.
Quoted 3 lines · On Sat, 19 May 2001 [email protected] wrote:
One would like to have a version of the
open()call that was guaranteed free of side effects, and gave a fd only - perhaps forstat(), perhaps forioctl().
I did this a while ago, after some discussion. The implementation may suck, but I think it's a useful facility.
http://web.gnu.walfield.org/mail-archive/linux-fsdevel/2000-March/0230.html
Matthew.