Normally proc files are either read-only or read-write. I had to look
this up since I have not had to use this before.
register is owned by root on my system
–w------- 1 root root 0 Oct 24 14:49 register
found this in kernel doc’s
“To actually register a new binary type, you have to set up a string
looking like
:name:type:offset:magic:mask:interpreter:flags (where you can choose
the ‘:’ upon
your needs) and echo it to /proc/sys/fs/binfmt_misc/register.”
So it makes sense that you can write or read to it as root.
Do you get a different result as a non-root user?
take care,
Brad
As I mentioned to Igor, the inconsistency between File.readable? and the
output of ‘ls -al’ when they are both executed as root that I find
surprising.
When executing as non-root, this file (and several others) are
unreadable (as expected). That doesn’t concern me.
And if you ‘regular work’ involves interrogating the /proc file system,
then what?
Then you better are not surprised when such things happen, or go first
to your $HOME/tmp or similar and acquaint yourself with the way your
brand of OS works, before you show up as ‘root’ in protected system
environments such as /proc
Regards
None of this was run ‘in /proc filesystem’. Note the prompts.
I don’t give fig for you or your objections. I’m looking for
an explanation of the behavior. It’s clear you can offer nothing
constructive so silence would be an obvious choice.
I don’t know what’s your problem beside your surprise! I also don’t give
a rats ass, how you are treating your systems. You asked a question, got
an answer and continue to be surprised with the facts!
Well, that’s how Unix works. I have two objections:
(1) You should not be using superuser account for regular work!
(2) You have no business running irb in /proc filesystem!
If you do either of these things, you better not be surprised, ever!
And if you ‘regular work’ involves interrogating the /proc file system,
then what?
You could use something like this? You’d need to flesh out some error/
input handling, and these constants (sadly not exposed by ruby that I
can find) will be platform specific. I think the ‘problem’ is that root
can do pretty much anything it wants (make a file owned root:root, chmod
000, and enjoy echo’ing stuff into it). The stdlib seems to use
‘eaccess( path, R_OK )’ which I guess gives a 0 for euid 0.
And if you ‘regular work’ involves interrogating the /proc file system,
then what?
Then you better are not surprised when such things happen, or go first
to your $HOME/tmp or similar and acquaint yourself with the way your
brand of OS works, before you show up as ‘root’ in protected system
environments such as /proc
So, while ls tells you the attributes on the file, root overrides all.
If you made something that root couldn’t get to / change / rm / read
then you’d wind up with a really wonky system. For example, instant DOS:
while true ; do
F=$$.$(date +%s)
dd if=/dev/zero of=$F bs=1g count=1
chmod 0 $F
done
Well, that’s how Unix works. I have two objections:
(1) You should not be using superuser account for regular work!
(2) You have no business running irb in /proc filesystem!
If you do either of these things, you better not be surprised, ever!
And if you ‘regular work’ involves interrogating the /proc file system,
then what?
You could use something like this? You’d need to flesh out some error/
input handling, and these constants (sadly not exposed by ruby that I
can find) will be platform specific. I think the ‘problem’ is that root
can do pretty much anything it wants (make a file owned root:root, chmod
000, and enjoy echo’ing stuff into it). The stdlib seems to use
‘eaccess( path, R_OK )’ which I guess gives a 0 for euid 0.
It wasn’t exactly what I expected but it focused on all the right issues
and that has lead to a conclusion.
As you pointed out, eaccess is the key.
If the stdlib implements eaccess with the same behavior as the
implementation in file.c (line 1034), root is simply granted
read and write permission without ever hitting stat.
‘ls -al’, on the other hand, relies on stat.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.