Messages in this thread |  | | From | Daniel Phillips <> | Subject | Re: checking out if file may be executed? | Date | Sun, 20 Aug 2000 15:35:36 +0200 |
| |
(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:
http://innominate.org/~graichen/projects/lxr/source/fs/binfmt_elf.c?v=v2.3#L510 (load_elf_binary opens a file for execution)
http://innominate.org/~graichen/projects/lxr/source/fs/binfmt_elf.c?v=v2.3#L757 (and closes it again, having decided not to do anything with it)
-- Daniel - 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/
|  |