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 @@ -100,7 +100,10 @@ struct ExecCommand: ParsableCommand {
100100 try App . applyCloseExecOnFDs ( )
101101 try App . setRLimits ( rlimits: process. rlimits)
102102
103- // set uid, gid, and supplementary groups
103+ // Change stdio to be owned by the requested user.
104+ try App . fixStdioPerms ( user: process. user)
105+
106+ // Set uid, gid, and supplementary groups
104107 try App . setPermissions ( user: process. user)
105108
106109 if process. terminal {
Original file line number Diff line number Diff line change @@ -109,7 +109,10 @@ struct RunCommand: ParsableCommand {
109109
110110 try App . setRLimits ( rlimits: process. rlimits)
111111
112- // set uid, gid, and supplementary groups
112+ // Change stdio to be owned by the requested user.
113+ try App . fixStdioPerms ( user: process. user)
114+
115+ // Set uid, gid, and supplementary groups.
113116 try App . setPermissions ( user: process. user)
114117
115118 if process. terminal {
Original file line number Diff line number Diff line change @@ -104,6 +104,24 @@ extension App {
104104 }
105105 }
106106
107+ static func fixStdioPerms( user: ContainerizationOCI . User ) throws {
108+ for i in 0 ... 2 {
109+ var fdStat = stat ( )
110+ try withUnsafeMutablePointer ( to: & fdStat) { pointer in
111+ guard fstat ( Int32 ( i) , pointer) == 0 else {
112+ throw App . Errno ( stage: " fstat(fd) " )
113+ }
114+ }
115+
116+ let desired = uid_t ( user. uid)
117+ if fdStat. st_uid != desired {
118+ guard fchown ( Int32 ( i) , desired, fdStat. st_gid) != - 1 else {
119+ throw App . Errno ( stage: " fchown( \( i) ) " )
120+ }
121+ }
122+ }
123+ }
124+
107125 static func setRLimits( rlimits: [ ContainerizationOCI . POSIXRlimit ] ) throws {
108126 for rl in rlimits {
109127 var limit = rlimit ( rlim_cur: rl. soft, rlim_max: rl. hard)
You can’t perform that action at this time.
0 commit comments