mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
Kernel: Fix pledge syscall applying new pledges when it fails (#2076)
If the exec promises fail to apply, then the normal promises should not apply either. Add a test for this fixed functionality.
This commit is contained in:
parent
37d1b0c875
commit
58a34fbe09
Notes:
sideshowbarker
2024-07-19 07:01:57 +09:00
Author: https://github.com/ToadKing 🔰 Commit: https://github.com/SerenityOS/serenity/commit/58a34fbe09a Pull-request: https://github.com/SerenityOS/serenity/pull/2076
2 changed files with 37 additions and 4 deletions
|
@ -4826,24 +4826,32 @@ int Process::sys$pledge(const Syscall::SC_pledge_params* user_params)
|
|||
return true;
|
||||
};
|
||||
|
||||
u32 new_promises;
|
||||
u32 new_execpromises;
|
||||
|
||||
if (!promises.is_null()) {
|
||||
u32 new_promises = 0;
|
||||
new_promises = 0;
|
||||
if (!parse_pledge(promises, new_promises))
|
||||
return -EINVAL;
|
||||
if (m_promises && (!new_promises || new_promises & ~m_promises))
|
||||
return -EPERM;
|
||||
m_promises = new_promises;
|
||||
} else {
|
||||
new_promises = m_promises;
|
||||
}
|
||||
|
||||
if (!execpromises.is_null()) {
|
||||
u32 new_execpromises = 0;
|
||||
new_execpromises = 0;
|
||||
if (!parse_pledge(execpromises, new_execpromises))
|
||||
return -EINVAL;
|
||||
if (m_execpromises && (!new_execpromises || new_execpromises & ~m_execpromises))
|
||||
return -EPERM;
|
||||
m_execpromises = new_execpromises;
|
||||
} else {
|
||||
new_execpromises = m_execpromises;
|
||||
}
|
||||
|
||||
m_promises = new_promises;
|
||||
m_execpromises = new_execpromises;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
25
Tests/Kernel/pledge-test-failures.cpp
Normal file
25
Tests/Kernel/pledge-test-failures.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int res = pledge("stdio unix rpath", "stdio");
|
||||
if (res < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
res = pledge("stdio unix", "stdio unix");
|
||||
if (res >= 0) {
|
||||
fprintf(stderr, "second pledge should have failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
res = pledge("stdio rpath", "stdio");
|
||||
if (res < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue