1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

Shell: Limit the access of processes spawned for autocompletion

This commit limits the autocomplete processes to effectively have
readonly access to the fs, and only enough pledges to get the dynamic
loader working.
This commit is contained in:
Ali Mohammad Pur 2022-03-25 01:19:48 +04:30 committed by Ali Mohammad Pur
parent 8233da3398
commit f12d81ddf5
2 changed files with 51 additions and 0 deletions

View file

@ -844,6 +844,14 @@ ErrorOr<RefPtr<Job>> Shell::run_command(const AST::Command& command)
void Shell::execute_process(Vector<const char*>&& argv)
{
#ifdef __serenity__
for (auto& promise : m_active_promises) {
pledge("exec", promise.data.exec_promises.characters());
for (auto& item : promise.data.unveils)
unveil(item.path.characters(), item.access.characters());
}
#endif
int rc = execvp(argv[0], const_cast<char* const*>(argv.data()));
if (rc < 0) {
auto parts = StringView { argv[0] }.split_view('/');
@ -1833,6 +1841,13 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
});
timer->start();
// Restrict the process to effectively readonly access to the FS.
auto scoped_promise = promise({
.exec_promises = "stdio rpath prot_exec no_error",
.unveils = {
{ "/", "rx" },
},
});
execute_node->for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) -> IterationDecision {
auto result = entry->resolve_as_string(*this);
JsonParser parser(result);