summaryrefslogtreecommitdiff
path: root/DevTools
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-27 16:32:30 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-27 16:32:30 +0200
commitd9f933df7b1b1daef238bb7b0728c9f04097a977 (patch)
treed27c9f72d16e26dc588fe4c9c1d9da3ba4455ad7 /DevTools
parent368cea4094709a1e493b419c5bcc86040a207a38 (diff)
downloadserenity-d9f933df7b1b1daef238bb7b0728c9f04097a977.zip
UserspaceEmulator: Implement the setuid() and setgid() syscalls
Note that running a setuid program (e.g /bin/ping) in UE does not actually run uid=0. You'll have to run UE itself as uid=0 if you want to test programs that do setuid/setgid.
Diffstat (limited to 'DevTools')
-rw-r--r--DevTools/UserspaceEmulator/Emulator.cpp14
-rw-r--r--DevTools/UserspaceEmulator/Emulator.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp
index a8bc5e61c9..42cc29c3e5 100644
--- a/DevTools/UserspaceEmulator/Emulator.cpp
+++ b/DevTools/UserspaceEmulator/Emulator.cpp
@@ -278,6 +278,10 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
return virt$getuid();
case SC_getgid:
return virt$getgid();
+ case SC_setuid:
+ return virt$setuid(arg1);
+ case SC_setgid:
+ return virt$setgid(arg2);
case SC_close:
return virt$close(arg1);
case SC_fstat:
@@ -791,6 +795,16 @@ gid_t Emulator::virt$getgid()
return getgid();
}
+int Emulator::virt$setuid(uid_t uid)
+{
+ return syscall(SC_setuid, uid);
+}
+
+int Emulator::virt$setgid(gid_t gid)
+{
+ return syscall(SC_setgid, gid);
+}
+
u32 Emulator::virt$write(int fd, FlatPtr data, ssize_t size)
{
if (size < 0)
diff --git a/DevTools/UserspaceEmulator/Emulator.h b/DevTools/UserspaceEmulator/Emulator.h
index f08fd53efa..2093e3d30f 100644
--- a/DevTools/UserspaceEmulator/Emulator.h
+++ b/DevTools/UserspaceEmulator/Emulator.h
@@ -88,6 +88,8 @@ private:
u32 virt$pledge(u32);
uid_t virt$getuid();
gid_t virt$getgid();
+ int virt$setuid(uid_t);
+ int virt$setgid(gid_t);
u32 virt$read(int, FlatPtr, ssize_t);
u32 virt$write(int, FlatPtr, ssize_t);
u32 virt$mprotect(FlatPtr, size_t, int);