mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Cordes <peter@llama.nslug.ns.ca>
To: linux-kernel@vger.kernel.org
Subject: access() says EROFS even for device files if /dev is mounted RO
Date: Sun, 26 Nov 2000 23:35:22 -0400	[thread overview]
Message-ID: <20001126233522.A436@llama.nslug.ns.ca> (raw)


 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/

             reply	other threads:[~2000-11-27  4:06 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-27  3:35 Peter Cordes [this message]
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
2000-11-29 17:17 Andries.Brouwer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20001126233522.A436@llama.nslug.ns.ca \
    --to=peter@llama.nslug.ns.ca \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®