Why are non executable files "executable" for root?

Why are non executable files "executable" for root?

Post by Michael Sc » Tue, 07 Oct 2008 18:34:13


Hi!

Following simple test program confuses me on Solaris 9/10:

--($ ~)-- cat _X_
#!/bin/bash

if [ -x /etc/passwd ]; then
echo yes
else
echo no
fi
# EOF #

$ ls -al /etc/passwd
-r--r--r-- 1 root sys 1211 Jun 10 09:52 /etc/passwd

When I run that program on Solaris 9 or 10, it prints "no" when I'm a
normal user.

BUT: When I run that program as root (eg. with "sudo bash _X_"), then
it prints "yes". Why's that so?

Funnily, though:

--($ ~)-- sudo /etc/passwd
sudo: /etc/passwd: command not found

Seems that the program wasn't executable?!

When I run _X_ on a Linux system, it always prints "no", even when run
as root. That's the behaviour I'd expect.

Michael
 
 
 

Why are non executable files "executable" for root?

Post by Casper H.S » Tue, 07 Oct 2008 18:47:20

Michael Schmarck < XXXX@XXXXX.COM > writes:






The access(2) system call returns 0 when you're root;
I seem to remember that it only returned 0 if one of the
X bits was said when you're root, but that is apparently not
the case now.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

Why are non executable files "executable" for root?

Post by andre » Tue, 07 Oct 2008 18:59:13

In article < XXXX@XXXXX.COM >,
Michael Schmarck < XXXX@XXXXX.COM > writes:

Looks like a bash-ism.
Other shells I tried don't behave this way.
BTW, it's not just execute access -- does the same for write access.
I suppose that since root can write to a file even when it doesn't
have write access, that's partway reasonable. Other shells also do
the write access one.

--
Andrew Gabriel
[email address is not usable -- followup in the newsgroup]
 
 
 

Why are non executable files "executable" for root?

Post by Michael Sc » Tue, 07 Oct 2008 19:35:55


On testing some more, I found that this seems to be a bug in the CSW
bash. Compare this:

--($ ~)-- sudo /opt/csw/bin/bash -x -c "[ -x /etc/passwd ] && echo true || echo false"
Passwort:
+ '[' -x /etc/passwd ']'
+ echo true
true

--($ ~)-- sudo /bin/bash -x -c "[ -x /etc/passwd ] && echo true || echo false"
+ '[' -x /etc/passwd ']'
+ echo false
false

--($ ~)-- /opt/csw/bin/bash --version
GNU bash, version 3.2.33(1)-release (sparc-sun-solaris2.8)
Copyright (C) 2007 Free Software Foundation, Inc.

With the Sun supplied bash or with a (more current?) bash on Linux, this
problem doesn't happen.
Michael