|
@@ -16,15 +16,26 @@ ErrorOr<FlatPtr> Process::sys$seteuid(UserID new_euid)
|
|
if (new_euid == (uid_t)-1)
|
|
if (new_euid == (uid_t)-1)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
- if (new_euid != uid() && new_euid != suid() && !is_superuser())
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
|
|
+ if (new_euid != credentials->uid() && new_euid != credentials->suid() && !credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
- if (euid() != new_euid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ credentials->uid(),
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ new_euid,
|
|
|
|
+ credentials->egid(),
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
|
|
|
|
- m_protected_values.euid = new_euid;
|
|
|
|
|
|
+ if (credentials->euid() != new_euid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -36,14 +47,26 @@ ErrorOr<FlatPtr> Process::sys$setegid(GroupID new_egid)
|
|
if (new_egid == (uid_t)-1)
|
|
if (new_egid == (uid_t)-1)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
- if (new_egid != gid() && new_egid != sgid() && !is_superuser())
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
|
|
+ if (new_egid != credentials->gid() && new_egid != credentials->sgid() && !credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
- if (egid() != new_egid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ credentials->uid(),
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ credentials->euid(),
|
|
|
|
+ new_egid,
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.egid = new_egid;
|
|
|
|
|
|
+
|
|
|
|
+ if (credentials->egid() != new_egid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -55,16 +78,26 @@ ErrorOr<FlatPtr> Process::sys$setuid(UserID new_uid)
|
|
if (new_uid == (uid_t)-1)
|
|
if (new_uid == (uid_t)-1)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
- if (new_uid != uid() && new_uid != euid() && !is_superuser())
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
|
|
+ if (new_uid != credentials->uid() && new_uid != credentials->euid() && !credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
- if (euid() != new_uid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ new_uid,
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ new_uid,
|
|
|
|
+ credentials->egid(),
|
|
|
|
+ new_uid,
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.uid = new_uid;
|
|
|
|
- m_protected_values.euid = new_uid;
|
|
|
|
- m_protected_values.suid = new_uid;
|
|
|
|
|
|
+
|
|
|
|
+ if (credentials->euid() != new_uid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -76,16 +109,26 @@ ErrorOr<FlatPtr> Process::sys$setgid(GroupID new_gid)
|
|
if (new_gid == (uid_t)-1)
|
|
if (new_gid == (uid_t)-1)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
- if (new_gid != gid() && new_gid != egid() && !is_superuser())
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
|
|
+ if (new_gid != credentials->gid() && new_gid != credentials->egid() && !credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
- if (egid() != new_gid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ credentials->uid(),
|
|
|
|
+ new_gid,
|
|
|
|
+ credentials->euid(),
|
|
|
|
+ new_gid,
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ new_gid,
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.gid = new_gid;
|
|
|
|
- m_protected_values.egid = new_gid;
|
|
|
|
- m_protected_values.sgid = new_gid;
|
|
|
|
|
|
+
|
|
|
|
+ if (credentials->egid() != new_gid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -94,24 +137,35 @@ ErrorOr<FlatPtr> Process::sys$setreuid(UserID new_ruid, UserID new_euid)
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::id));
|
|
TRY(require_promise(Pledge::id));
|
|
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
if (new_ruid == (uid_t)-1)
|
|
if (new_ruid == (uid_t)-1)
|
|
- new_ruid = uid();
|
|
|
|
|
|
+ new_ruid = credentials->uid();
|
|
if (new_euid == (uid_t)-1)
|
|
if (new_euid == (uid_t)-1)
|
|
- new_euid = euid();
|
|
|
|
|
|
+ new_euid = credentials->euid();
|
|
|
|
|
|
- auto ok = [this](UserID id) { return id == uid() || id == euid() || id == suid(); };
|
|
|
|
|
|
+ auto ok = [&credentials](UserID id) { return id == credentials->uid() || id == credentials->euid() || id == credentials->suid(); };
|
|
if (!ok(new_ruid) || !ok(new_euid))
|
|
if (!ok(new_ruid) || !ok(new_euid))
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
if (new_ruid < (uid_t)-1 || new_euid < (uid_t)-1)
|
|
if (new_ruid < (uid_t)-1 || new_euid < (uid_t)-1)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
- if (euid() != new_euid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ new_ruid,
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ new_euid,
|
|
|
|
+ credentials->egid(),
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.uid = new_ruid;
|
|
|
|
- m_protected_values.euid = new_euid;
|
|
|
|
|
|
+
|
|
|
|
+ if (credentials->euid() != new_euid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -120,24 +174,34 @@ ErrorOr<FlatPtr> Process::sys$setresuid(UserID new_ruid, UserID new_euid, UserID
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::id));
|
|
TRY(require_promise(Pledge::id));
|
|
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
if (new_ruid == (uid_t)-1)
|
|
if (new_ruid == (uid_t)-1)
|
|
- new_ruid = uid();
|
|
|
|
|
|
+ new_ruid = credentials->uid();
|
|
if (new_euid == (uid_t)-1)
|
|
if (new_euid == (uid_t)-1)
|
|
- new_euid = euid();
|
|
|
|
|
|
+ new_euid = credentials->euid();
|
|
if (new_suid == (uid_t)-1)
|
|
if (new_suid == (uid_t)-1)
|
|
- new_suid = suid();
|
|
|
|
|
|
+ new_suid = credentials->suid();
|
|
|
|
|
|
- auto ok = [this](UserID id) { return id == uid() || id == euid() || id == suid(); };
|
|
|
|
- if ((!ok(new_ruid) || !ok(new_euid) || !ok(new_suid)) && !is_superuser())
|
|
|
|
|
|
+ auto ok = [&credentials](UserID id) { return id == credentials->uid() || id == credentials->euid() || id == credentials->suid(); };
|
|
|
|
+ if ((!ok(new_ruid) || !ok(new_euid) || !ok(new_suid)) && !credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
- if (euid() != new_euid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ new_ruid,
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ new_euid,
|
|
|
|
+ credentials->egid(),
|
|
|
|
+ new_suid,
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.uid = new_ruid;
|
|
|
|
- m_protected_values.euid = new_euid;
|
|
|
|
- m_protected_values.suid = new_suid;
|
|
|
|
|
|
+
|
|
|
|
+ if (credentials->euid() != new_euid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -146,58 +210,84 @@ ErrorOr<FlatPtr> Process::sys$setresgid(GroupID new_rgid, GroupID new_egid, Grou
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::id));
|
|
TRY(require_promise(Pledge::id));
|
|
|
|
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
if (new_rgid == (gid_t)-1)
|
|
if (new_rgid == (gid_t)-1)
|
|
- new_rgid = gid();
|
|
|
|
|
|
+ new_rgid = credentials->gid();
|
|
if (new_egid == (gid_t)-1)
|
|
if (new_egid == (gid_t)-1)
|
|
- new_egid = egid();
|
|
|
|
|
|
+ new_egid = credentials->egid();
|
|
if (new_sgid == (gid_t)-1)
|
|
if (new_sgid == (gid_t)-1)
|
|
- new_sgid = sgid();
|
|
|
|
|
|
+ new_sgid = credentials->sgid();
|
|
|
|
|
|
- auto ok = [this](GroupID id) { return id == gid() || id == egid() || id == sgid(); };
|
|
|
|
- if ((!ok(new_rgid) || !ok(new_egid) || !ok(new_sgid)) && !is_superuser())
|
|
|
|
|
|
+ auto ok = [&credentials](GroupID id) { return id == credentials->gid() || id == credentials->egid() || id == credentials->sgid(); };
|
|
|
|
+ if ((!ok(new_rgid) || !ok(new_egid) || !ok(new_sgid)) && !credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
- if (egid() != new_egid)
|
|
|
|
- set_dumpable(false);
|
|
|
|
|
|
+ auto new_credentials = TRY(Credentials::create(
|
|
|
|
+ credentials->uid(),
|
|
|
|
+ new_rgid,
|
|
|
|
+ credentials->euid(),
|
|
|
|
+ new_egid,
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ new_sgid,
|
|
|
|
+ credentials->extra_gids()));
|
|
|
|
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.gid = new_rgid;
|
|
|
|
- m_protected_values.egid = new_egid;
|
|
|
|
- m_protected_values.sgid = new_sgid;
|
|
|
|
|
|
+
|
|
|
|
+ if (credentials->egid() != new_egid)
|
|
|
|
+ set_dumpable(false);
|
|
|
|
+
|
|
|
|
+ m_protected_values.credentials = move(new_credentials);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-ErrorOr<FlatPtr> Process::sys$setgroups(size_t count, Userspace<gid_t const*> user_gids)
|
|
|
|
|
|
+ErrorOr<FlatPtr> Process::sys$setgroups(size_t count, Userspace<GroupID const*> user_gids)
|
|
{
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::id));
|
|
TRY(require_promise(Pledge::id));
|
|
- if (!is_superuser())
|
|
|
|
|
|
+
|
|
|
|
+ auto credentials = this->credentials();
|
|
|
|
+
|
|
|
|
+ if (!credentials->is_superuser())
|
|
return EPERM;
|
|
return EPERM;
|
|
|
|
|
|
if (!count) {
|
|
if (!count) {
|
|
ProtectedDataMutationScope scope { *this };
|
|
ProtectedDataMutationScope scope { *this };
|
|
- m_protected_values.extra_gids.clear();
|
|
|
|
|
|
+ m_protected_values.credentials = TRY(Credentials::create(
|
|
|
|
+ credentials->uid(),
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ credentials->euid(),
|
|
|
|
+ credentials->egid(),
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ {}));
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- Vector<gid_t> new_extra_gids;
|
|
|
|
|
|
+ Vector<GroupID> new_extra_gids;
|
|
TRY(new_extra_gids.try_resize(count));
|
|
TRY(new_extra_gids.try_resize(count));
|
|
TRY(copy_n_from_user(new_extra_gids.data(), user_gids, count));
|
|
TRY(copy_n_from_user(new_extra_gids.data(), user_gids, count));
|
|
|
|
|
|
- HashTable<gid_t> unique_extra_gids;
|
|
|
|
|
|
+ HashTable<GroupID> unique_extra_gids;
|
|
for (auto& extra_gid : new_extra_gids) {
|
|
for (auto& extra_gid : new_extra_gids) {
|
|
if (extra_gid != gid())
|
|
if (extra_gid != gid())
|
|
TRY(unique_extra_gids.try_set(extra_gid));
|
|
TRY(unique_extra_gids.try_set(extra_gid));
|
|
}
|
|
}
|
|
|
|
|
|
- ProtectedDataMutationScope scope { *this };
|
|
|
|
- TRY(m_protected_values.extra_gids.try_resize(unique_extra_gids.size()));
|
|
|
|
- size_t i = 0;
|
|
|
|
- for (auto& extra_gid : unique_extra_gids) {
|
|
|
|
- if (extra_gid == gid())
|
|
|
|
- continue;
|
|
|
|
- m_protected_values.extra_gids[i++] = extra_gid;
|
|
|
|
|
|
+ new_extra_gids.clear_with_capacity();
|
|
|
|
+ for (auto extra_gid : unique_extra_gids) {
|
|
|
|
+ TRY(new_extra_gids.try_append(extra_gid));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ ProtectedDataMutationScope scope { *this };
|
|
|
|
+ m_protected_values.credentials = TRY(Credentials::create(
|
|
|
|
+ credentials->uid(),
|
|
|
|
+ credentials->gid(),
|
|
|
|
+ credentials->euid(),
|
|
|
|
+ credentials->egid(),
|
|
|
|
+ credentials->suid(),
|
|
|
|
+ credentials->sgid(),
|
|
|
|
+ new_extra_gids.span()));
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|