mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:27:44 +00:00
Kernel/Process: Move protected values to the end of the object
The compiler can re-order the structure (class) members if that's necessary, so if we make Process to inherit from ProcFSExposedComponent, even if the declaration is to inherit first from ProcessBase, then from ProcFSExposedComponent and last from Weakable<Process>, the members of class ProcFSExposedComponent (including the Ref-counted parts) are the first members of the Process class. This problem made it impossible to safely use the current toggling method with the write-protection bit on the ProcessBase members, so instead of inheriting from it, we make its members the last ones in the Process class so we can safely locate and modify the corresponding page write protection bit of these values. We make sure that the Process class doesn't expand beyond 8192 bytes and the protected values are always aligned on a page boundary.
This commit is contained in:
parent
e405f436b6
commit
01b79910b3
12 changed files with 130 additions and 128 deletions
|
@ -21,7 +21,7 @@ KResultOr<FlatPtr> Process::sys$seteuid(uid_t new_euid)
|
|||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
|
||||
m_euid = new_euid;
|
||||
m_protected_values.euid = new_euid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ KResultOr<FlatPtr> Process::sys$setegid(gid_t new_egid)
|
|||
set_dumpable(false);
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_egid = new_egid;
|
||||
m_protected_values.egid = new_egid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,9 @@ KResultOr<FlatPtr> Process::sys$setuid(uid_t new_uid)
|
|||
set_dumpable(false);
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_uid = new_uid;
|
||||
m_euid = new_uid;
|
||||
m_suid = new_uid;
|
||||
m_protected_values.uid = new_uid;
|
||||
m_protected_values.euid = new_uid;
|
||||
m_protected_values.suid = new_uid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,9 @@ KResultOr<FlatPtr> Process::sys$setgid(gid_t new_gid)
|
|||
set_dumpable(false);
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_gid = new_gid;
|
||||
m_egid = new_gid;
|
||||
m_sgid = new_gid;
|
||||
m_protected_values.gid = new_gid;
|
||||
m_protected_values.egid = new_gid;
|
||||
m_protected_values.sgid = new_gid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -98,8 +98,8 @@ KResultOr<FlatPtr> Process::sys$setreuid(uid_t new_ruid, uid_t new_euid)
|
|||
set_dumpable(false);
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_uid = new_ruid;
|
||||
m_euid = new_euid;
|
||||
m_protected_values.uid = new_ruid;
|
||||
m_protected_values.euid = new_euid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -123,9 +123,9 @@ KResultOr<FlatPtr> Process::sys$setresuid(uid_t new_ruid, uid_t new_euid, uid_t
|
|||
set_dumpable(false);
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_uid = new_ruid;
|
||||
m_euid = new_euid;
|
||||
m_suid = new_suid;
|
||||
m_protected_values.uid = new_ruid;
|
||||
m_protected_values.euid = new_euid;
|
||||
m_protected_values.suid = new_suid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -149,9 +149,9 @@ KResultOr<FlatPtr> Process::sys$setresgid(gid_t new_rgid, gid_t new_egid, gid_t
|
|||
set_dumpable(false);
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_gid = new_rgid;
|
||||
m_egid = new_egid;
|
||||
m_sgid = new_sgid;
|
||||
m_protected_values.gid = new_rgid;
|
||||
m_protected_values.egid = new_egid;
|
||||
m_protected_values.sgid = new_sgid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ KResultOr<FlatPtr> Process::sys$setgroups(size_t count, Userspace<const gid_t*>
|
|||
|
||||
if (!count) {
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
m_extra_gids.clear();
|
||||
m_protected_values.extra_gids.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -181,13 +181,13 @@ KResultOr<FlatPtr> Process::sys$setgroups(size_t count, Userspace<const gid_t*>
|
|||
}
|
||||
|
||||
ProtectedDataMutationScope scope { *this };
|
||||
if (!m_extra_gids.try_resize(unique_extra_gids.size()))
|
||||
if (!m_protected_values.extra_gids.try_resize(unique_extra_gids.size()))
|
||||
return ENOMEM;
|
||||
size_t i = 0;
|
||||
for (auto& extra_gid : unique_extra_gids) {
|
||||
if (extra_gid == gid())
|
||||
continue;
|
||||
m_extra_gids[i++] = extra_gid;
|
||||
m_protected_values.extra_gids[i++] = extra_gid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue