Skip to content

Commit 81a6976

Browse files
gmtaawesomekling
authored andcommitted
Kernel: De-atomicize fields for promises in Process
These 4 fields were made `Atomic` in c3f668a, at which time these were still accessed unserialized and TOCTOU bugs could happen. Later, in 8ed06ad, we serialized access to these fields in a number of helper methods, removing the need for `Atomic`.
1 parent 7f855ad commit 81a6976

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Kernel/Syscalls/execve.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_d
712712
// NOTE: Be careful to not trigger any page faults below!
713713

714714
with_mutable_protected_data([&](auto& protected_data) {
715-
protected_data.promises = protected_data.execpromises.load();
716-
protected_data.has_promises = protected_data.has_execpromises.load();
715+
protected_data.promises = protected_data.execpromises;
716+
protected_data.has_promises = protected_data.has_execpromises;
717717

718718
protected_data.execpromises = 0;
719719
protected_data.has_execpromises = false;

Kernel/Syscalls/fork.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
9999

100100
with_protected_data([&](auto& my_protected_data) {
101101
child->with_mutable_protected_data([&](auto& child_protected_data) {
102-
child_protected_data.promises = my_protected_data.promises.load();
103-
child_protected_data.execpromises = my_protected_data.execpromises.load();
104-
child_protected_data.has_promises = my_protected_data.has_promises.load();
105-
child_protected_data.has_execpromises = my_protected_data.has_execpromises.load();
102+
child_protected_data.promises = my_protected_data.promises;
103+
child_protected_data.execpromises = my_protected_data.execpromises;
104+
child_protected_data.has_promises = my_protected_data.has_promises;
105+
child_protected_data.has_execpromises = my_protected_data.has_execpromises;
106106
child_protected_data.credentials = my_protected_data.credentials;
107107
child_protected_data.umask = my_protected_data.umask;
108108
child_protected_data.signal_trampoline = my_protected_data.signal_trampoline;

Kernel/Tasks/Process.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ class Process final
120120
RefPtr<TTY> tty;
121121
bool dumpable { false };
122122
bool executable_is_setid { false };
123-
Atomic<bool> has_promises { false };
124-
Atomic<u32> promises { 0 };
125-
Atomic<bool> has_execpromises { false };
126-
Atomic<u32> execpromises { 0 };
123+
bool has_promises { false };
124+
u32 promises { 0 };
125+
bool has_execpromises { false };
126+
u32 execpromises { 0 };
127127
mode_t umask { 022 };
128128
VirtualAddress signal_trampoline;
129129
Atomic<u32> thread_count { 0 };
@@ -520,7 +520,7 @@ class Process final
520520

521521
bool has_promises() const
522522
{
523-
return with_protected_data([](auto& protected_data) { return protected_data.has_promises.load(); });
523+
return with_protected_data([](auto& protected_data) { return protected_data.has_promises; });
524524
}
525525
bool has_promised(Pledge pledge) const
526526
{

0 commit comments

Comments
 (0)