mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 01:51:03 +09:00
Kernel+LibC: Add O_EXEC, move exec permission checking to VFS::open()
O_EXEC is mentioned by POSIX, so let's have it. Currently, it is only used inside the kernel to ensure the process has the right permissions when opening an executable.
This commit is contained in:
parent
4566c2d811
commit
2fcbb846fb
Notes:
sideshowbarker
2024-07-19 10:11:50 +09:00
Author: https://github.com/bugaevc
Commit: 2fcbb846fb
Pull-request: https://github.com/SerenityOS/serenity/pull/1053
4 changed files with 7 additions and 4 deletions
|
@ -215,6 +215,10 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
|
|||
return KResult(-EISDIR);
|
||||
should_truncate_file = options & O_TRUNC;
|
||||
}
|
||||
if (options & O_EXEC) {
|
||||
if (!metadata.may_execute(current->process()))
|
||||
return KResult(-EACCES);
|
||||
}
|
||||
|
||||
if (metadata.is_device()) {
|
||||
auto device = Device::get_device(metadata.major_device, metadata.minor_device);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define O_RDONLY 0
|
||||
#define O_WRONLY 1
|
||||
#define O_RDWR 2
|
||||
#define O_EXEC 4
|
||||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
|
|
|
@ -653,15 +653,12 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
|||
if (parts.is_empty())
|
||||
return -ENOENT;
|
||||
|
||||
auto result = VFS::the().open(path, 0, 0, current_directory());
|
||||
auto result = VFS::the().open(path, O_EXEC, 0, current_directory());
|
||||
if (result.is_error())
|
||||
return result.error();
|
||||
auto description = result.value();
|
||||
auto metadata = description->metadata();
|
||||
|
||||
if (!metadata.may_execute(*this))
|
||||
return -EACCES;
|
||||
|
||||
if (!metadata.size)
|
||||
return -ENOTIMPL;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ __BEGIN_DECLS
|
|||
#define O_WRONLY 1
|
||||
#define O_RDWR 2
|
||||
#define O_ACCMODE 3
|
||||
#define O_EXEC 4
|
||||
#define O_CREAT 0100
|
||||
#define O_EXCL 0200
|
||||
#define O_NOCTTY 0400
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue