public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* access() says EROFS even for device files if /dev is mounted RO
@ 2000-11-27  3:35 Peter Cordes
  2000-11-27 12:42 ` Andries Brouwer
  0 siblings, 1 reply; 26+ messages in thread
From: Peter Cordes @ 2000-11-27  3:35 UTC (permalink / raw)
  To: linux-kernel


 While doing some hdparm hacking, after booting with init=/bin/sh, I noticed
that open(1) doesn't work when / is mounted read only.  It complains that it
"Cannot open /dev/tty2 read/write"...

 I straced it:
 
execve("/usr/bin/open", ["open"], [/* 13 vars */]) = 0
...
brk(0x804c000)                          = 0x804c000
open("/dev/tty", O_RDWR)                = -1 ENXIO (No such device or address)
open("/dev/tty0", O_RDWR)               = 4
ioctl(4, KDGKBTYPE, 0xbffffcdb)         = 0
ioctl(4, VT_GETSTATE, 0xbffffda4)       = 0
ioctl(4, VT_OPENQRY, 0xbffffd90)        = 0
open("/dev/tty2", O_RDWR)               = 5
close(5)                                = 0


access("/dev/tty2", R_OK|W_OK)          = -1 EROFS (Read-only file system)


write(2, "Cannot open /dev/tty2 read/write"..., 57) = 57
_exit(5)                                = ?


 However, this is wrong.  You _can_ write to device files on read-only
filesystems.  (open shouldn't bother calling access(), but the kernel should
definitely give the right answer!)  Running
(bash < /dev/tty2 &>/dev/tty2 &)
will work (but for reasons unknown to me it won't do job control or handle
^C, etc.)

 I'm pretty sure the problem is in linux/fs/open.c, in sys_access():
        ...
	int res = -EINVAL;
	...
        dentry = namei(filename);
        res = PTR_ERR(dentry);
        if (!IS_ERR(dentry)) {
                res = permission(dentry->d_inode, mode);
                /* SuS v2 requires we report a read only fs too */

                if(!res && (mode & S_IWOTH) && IS_RDONLY(dentry->d_inode))

                        res = -EROFS;
	        dput(dentry);
        }
        ...
	return res;
 
 I think the  if( !res ... )  line is the problem.  I think the fix is to
add a check that the file is not a device file, socket, named pipe, or a
symlink to a file on a non-readonly FS (unless permission already follow
links?  There's probably some file type I didn't think of that needs to get
checked, too.).  

 I'm don't know what macro to use, since I don't have much kernel hacking
experience (yet ;), so I'll leave the fix for someone who knows what
they're doing :->

 BTW, this is in a 2.2.17 kernel on an IA32 machine.
 
 Please CC me on any replies, since I'm not subscribed to the list.

-- 
#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter@llama.nslug. , ns.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BCE
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: access() says EROFS even for device files if /dev is mounted RO
@ 2000-11-29 17:17 Andries.Brouwer
  0 siblings, 0 replies; 26+ messages in thread
From: Andries.Brouwer @ 2000-11-29 17:17 UTC (permalink / raw)
  To: alan, tigran, viro; +Cc: aeb, hugh, linux-kernel

    From viro@math.psu.edu Wed Nov 29 17:52:57 2000

    > Should the majority win? I.e. should we say OK, as we do now?

    We should, but we don't. 2.4 does the right thing.
    2.2 got the following change back in 2.2.6:

            res = PTR_ERR(dentry);
            if (!IS_ERR(dentry)) {
                    res = permission(dentry->d_inode, mode);
    +               /* SuS v2 requires we report a read only fs too */
    +               if(!res && (mode & S_IWOTH) && IS_RDONLY(dentry->d_inode))
    +                       res = -EROFS;
                    dput(dentry);
            }
    ... and that's what really ticks me off - permission() does the right
    tests in case of read-only fs (ignoring the r/o vs. r/w for devices and
    FIFOs), but sys_access() explicitly overrides that.

    IMO we should revert that in 2.2. HP/UX is probably hopeless - if they
    will ever start caring about bogus behaviour access() will not be anywhere
    near the top of their list ;-/

Yes. Alan, it seems we all agree that 

--- open.c~     Tue Jan  4 19:12:23 2000
+++ open.c      Wed Nov 29 18:14:14 2000
@@ -305,9 +305,6 @@
        res = PTR_ERR(dentry);
        if (!IS_ERR(dentry)) {
                res = permission(dentry->d_inode, mode);
-               /* SuS v2 requires we report a read only fs too */
-               if(!res && (mode & S_IWOTH) && IS_RDONLY(dentry->d_inode))
-                       res = -EROFS;
                dput(dentry);
        }

is a good idea.

Andries

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2000-12-01 18:30 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-27  3:35 access() says EROFS even for device files if /dev is mounted RO Peter Cordes
2000-11-27 12:42 ` Andries Brouwer
2000-11-27 21:47   ` Rogier Wolff
2000-11-28  0:09     ` Andries Brouwer
2000-11-28 14:04       ` Rogier Wolff
2000-11-28 21:37         ` Andries Brouwer
2000-11-29 12:01           ` Hugh Dickins
2000-11-29 12:39             ` Alexander Viro
2000-11-29 15:46               ` Hugh Dickins
2000-11-29 16:18                 ` Alexander Viro
2000-11-29 16:40                   ` Tigran Aivazian
2000-11-29 16:52                     ` Alexander Viro
2000-12-01 17:12                     ` Olivier Galibert
2000-12-01 17:59                       ` Richard B. Johnson
2000-11-29 16:24                 ` Tigran Aivazian
2000-11-29 16:25                   ` Tigran Aivazian
2000-11-29 16:42                   ` Alexander Viro
2000-11-29 16:58                     ` Tigran Aivazian
2000-11-29 17:07                       ` Tigran Aivazian
2000-11-29 16:48                   ` Hugh Dickins
2000-11-29 14:24             ` Richard B. Johnson
2000-11-29 14:33               ` Broken NTFS Joseph K. Malek
2000-11-29 19:28                 ` Jeff V. Merkey
2000-11-28 22:56   ` access() says EROFS even for device files if /dev is mounted RO Peter Cordes
2000-11-28 23:23     ` Alexander Viro
  -- strict thread matches above, loose matches on Subject: below --
2000-11-29 17:17 Andries.Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox