vmexec: Set perms on stdio (#174)

We don't chown the container's stdio today.
This commit is contained in:
Danny Canter
2025-06-27 11:03:21 -04:00
committed by GitHub
parent 059ff4033f
commit c7763c76cf
3 changed files with 26 additions and 2 deletions
+4 -1
View File
@@ -100,7 +100,10 @@ struct ExecCommand: ParsableCommand {
try App.applyCloseExecOnFDs()
try App.setRLimits(rlimits: process.rlimits)
// set uid, gid, and supplementary groups
// Change stdio to be owned by the requested user.
try App.fixStdioPerms(user: process.user)
// Set uid, gid, and supplementary groups
try App.setPermissions(user: process.user)
if process.terminal {
+4 -1
View File
@@ -109,7 +109,10 @@ struct RunCommand: ParsableCommand {
try App.setRLimits(rlimits: process.rlimits)
// set uid, gid, and supplementary groups
// Change stdio to be owned by the requested user.
try App.fixStdioPerms(user: process.user)
// Set uid, gid, and supplementary groups.
try App.setPermissions(user: process.user)
if process.terminal {
+18
View File
@@ -104,6 +104,24 @@ extension App {
}
}
static func fixStdioPerms(user: ContainerizationOCI.User) throws {
for i in 0...2 {
var fdStat = stat()
try withUnsafeMutablePointer(to: &fdStat) { pointer in
guard fstat(Int32(i), pointer) == 0 else {
throw App.Errno(stage: "fstat(fd)")
}
}
let desired = uid_t(user.uid)
if fdStat.st_uid != desired {
guard fchown(Int32(i), desired, fdStat.st_gid) != -1 else {
throw App.Errno(stage: "fchown(\(i))")
}
}
}
}
static func setRLimits(rlimits: [ContainerizationOCI.POSIXRlimit]) throws {
for rl in rlimits {
var limit = rlimit(rlim_cur: rl.soft, rlim_max: rl.hard)