[lkml]   [2000]   [Aug]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: checking out if file may be executed?
(reposting this because it bounced) :-/

Julien Oster wrote:
> Hello,
> I'm using 2.4.0-test6 on ix86.
> Is there any quick way in the kernel to find out if a file may be executed?
> Of course I could issue the execve syscall and check if there's any error...
> but the problem with this is, that the file actually gets executed if it
> may be executed. And I don't want this.
> "may be executed" includes permission checks et al. I don't matter if it's
> actually a known binary format or whatever, I just want to check if the
> current process (resp. the current user) is allowed to execute it.
> In clear, I want to perform exactly those checks an execve is issuing before
> actually trying to execute it somehow.
> Simply checking the permissions myself seems incomplete to me. i.e., the
> filesystem could be mounted with "noexec", it could be in a directory the
> user isn't allowed to access and many more...
> I'm sure there must be a function which performs these checks, but I don't
> know what it is :)
> I thought about IS_NOEXEC, but especially open_exec() does much more than
> that. And I don't want to use open_exec since it seems to open the file and
> do stuff I don't quite understand yet.

But open_exec() seems to be exactly what you want. The only thing you
need to know is what conditions you have to satisfy for the close, and
they seem pretty simple. Basically you just re-allow write access and
then fput the file. You can check out current practice here:
(load_elf_binary opens a file for execution)
(and closes it again, having decided not to do anything with it)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:37    [W:0.032 / U:1.512 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site