Re: permission denied on exec of unexistent file?

From: Alessandro Suardi (asuardi@uninetcom.it)
Date: Sun Mar 26 2000 - 09:14:31 EST


Oleg Drokin wrote:
>
> Hello!
>
> Alessandro Suardi wrote:
>
> > > I just found something that looks somewhat weird:
> > > mordor:~$ /bin/nonexistent_binary
> > > bash: ./nonexistent_binary: Permission denied
> > > mordor:~$ nonexistent_binary
> > > bash: nonexistent_binary: command not found
> > >
> > > Shouldn't first attempt also say "command not found"?
> > > BASH_VERSION='2.03.0(1)-release'
> > > I'm running 2.3.99-pre3
> > Not a kernel problem (TM).
> Not likely. execve(2) returns permission denied.
> But it should return ENOENT (from man execve(2):)
> ENOENT The file filename or a script or ELF interpreter
> does not exist.
>
> See:
> mordor:~$ strace -e trace=stat bash -c '/bin/nonexistent_binary'
> stat("/home/green", {...}) = 0
> ...
> stat("/bin/nonexistent_binary", 0xbffff77c) = -1 ENOENT (No such file or directory)
> BUT!
> mordor:~$ strace -e trace=execve bash -c '/bin/nonexistent_binary'
> execve("/usr/bin/bash", ["bash", "-c", "/bin/nonexistent_binary"], [/* 29 vars */]) = 0
> execve("/bin/nonexistent_binary", ["/bin/nonexistent_binary"], [/* 27 vars */])
> = -1 EACCES (Permission denied)
> bash: /bin/nonexistent_binary: Permission denied

Hmm, you are right about the EACCES wrong retcode; though, on bash-1.14.7
 it seems the end-user message is the proper one despite EACCES, because
 bash tries to stat() the file anyway:

rt_sigaction(SIGQUIT, {SIG_DFL}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL}, {0x806059c, [], 0x4000000}, 8) = 0
execve("/bin/nonexistent_binary", ["/bin/nonexistent_binary"], [/* 25 vars */]) = -1 EACCES (Permission denied)
stat("/bin/nonexistent_binary", 0xbffff71c) = -1 ENOENT (No such file or directory)
fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40013000
ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "bash: /bin/nonexistent_binary: N"..., 57bash: /bin/nonexistent_binary: No such file or directory
) = 57
munmap(0x40013000, 4096) = 0
_exit(126) = ?

So yes, execve() is wrong - but bash-1.14.7 masks it just fine...

Ciao,

--alessandro <asuardi@uninetcom.it> <asuardi@it.oracle.com>

Linux 2.2.14/2.3.99-pre3 glibc-2.1.2-11 gcc-2.95.2 binutils-2.9.5.0.31

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



This archive was generated by hypermail 2b29 : Fri Mar 31 2000 - 21:00:17 EST