Skip to content

Commit 9075ffa

Browse files
committed
linux: switch to target process UID/GID
Ensure access to /tmp when overlayfs involved.
1 parent c791d36 commit 9075ffa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ci_core_dumper/linux.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,22 @@ def dump(outdir, gdb, extra_cmds):
294294

295295
def dump2(pid, gdb, extra_cmds):
296296
# running as root, fully in the target/container namespaces
297+
print('Initial root is uid %d, gid %d'%(os.getuid(), os.getgid()))
298+
299+
uid = gid = None
300+
with open('/proc/{}/status'.format(pid)) as F:
301+
for line in F:
302+
if line.startswith('Uid:'): # Uid: 1000 1000 1000 1000
303+
uid = int(line.split()[1])
304+
305+
elif line.startswith('Gid:'): # Gid: 1000 1000 1000 1000
306+
uid = int(line.split()[1])
307+
308+
if gid:
309+
os.setegid(gid)
310+
if uid:
311+
os.seteuid(uid)
312+
print('Target UID %d/%d'%(uid, gid))
297313

298314
# os.environ is still from the init namespaces.
299315
# copy the target process environment

0 commit comments

Comments
 (0)