File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,10 @@ struct ExecCommand: ParsableCommand {
103103 try App . applyCloseExecOnFDs ( )
104104 try App . setRLimits ( rlimits: process. rlimits)
105105
106- // set uid, gid, and supplementary groups
106+ // Change stdio to be owned by the requested user.
107+ try App . fixStdioPerms ( user: process. user)
108+
109+ // Set uid, gid, and supplementary groups
107110 try App . setPermissions ( user: process. user)
108111
109112 if process. terminal {
Original file line number Diff line number Diff line change @@ -112,7 +112,10 @@ struct RunCommand: ParsableCommand {
112112
113113 try App . setRLimits ( rlimits: process. rlimits)
114114
115- // set uid, gid, and supplementary groups
115+ // Change stdio to be owned by the requested user.
116+ try App . fixStdioPerms ( user: process. user)
117+
118+ // Set uid, gid, and supplementary groups.
116119 try App . setPermissions ( user: process. user)
117120
118121 if process. terminal {
Original file line number Diff line number Diff line change @@ -106,6 +106,24 @@ extension App {
106106 }
107107 }
108108
109+ static func fixStdioPerms( user: ContainerizationOCI . User ) throws {
110+ for i in 0 ... 2 {
111+ var fdStat = stat ( )
112+ try withUnsafeMutablePointer ( to: & fdStat) { pointer in
113+ guard fstat ( Int32 ( i) , pointer) == 0 else {
114+ throw App . Errno ( stage: " fstat(fd) " )
115+ }
116+ }
117+
118+ let desired = uid_t ( user. uid)
119+ if fdStat. st_uid != desired {
120+ guard fchown ( Int32 ( i) , desired, fdStat. st_gid) != - 1 else {
121+ throw App . Errno ( stage: " fchown( \( i) ) " )
122+ }
123+ }
124+ }
125+ }
126+
109127 static func setRLimits( rlimits: [ ContainerizationOCI . POSIXRlimit ] ) throws {
110128 for rl in rlimits {
111129 var limit = rlimit ( rlim_cur: rl. soft, rlim_max: rl. hard)
You can’t perform that action at this time.
0 commit comments