mirror of
https://github.com/xcat2/confluent.git
synced 2026-09-01 15:06:06 +00:00
Make sure a child can't except out of a forked child
If an exception were incurred in child in fork, the code could break out.
This commit is contained in:
@@ -167,10 +167,15 @@ def init_confluent_myname():
|
||||
if pid:
|
||||
os.waitpid(pid, 0)
|
||||
else:
|
||||
os.setgid(hasconfluentuser.pw_gid)
|
||||
os.setuid(hasconfluentuser.pw_uid)
|
||||
collective.get_myname()
|
||||
os._exit(0)
|
||||
exitcode = 0
|
||||
try:
|
||||
os.setgid(hasconfluentuser.pw_gid)
|
||||
os.setuid(hasconfluentuser.pw_uid)
|
||||
collective.get_myname()
|
||||
except Exception:
|
||||
exitcode = 1
|
||||
finally:
|
||||
os._exit(exitcode)
|
||||
|
||||
|
||||
async def local_node_trust_setup():
|
||||
|
||||
@@ -606,12 +606,14 @@ def checkaccess(user, filename, pwent, mode=os.R_OK):
|
||||
"""
|
||||
child = os.fork()
|
||||
if child == 0:
|
||||
os.setgroups(os.getgrouplist(user, pwent.pw_gid))
|
||||
os.setgid(pwent.pw_gid)
|
||||
os.setuid(pwent.pw_uid)
|
||||
if os.access(filename, mode):
|
||||
os._exit(0)
|
||||
os._exit(1)
|
||||
try:
|
||||
os.setgroups(os.getgrouplist(user, pwent.pw_gid))
|
||||
os.setgid(pwent.pw_gid)
|
||||
os.setuid(pwent.pw_uid)
|
||||
if os.access(filename, mode):
|
||||
os._exit(0)
|
||||
finally:
|
||||
os._exit(1)
|
||||
else:
|
||||
pid, status = os.waitpid(child, 0)
|
||||
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
|
||||
|
||||
+34
-24
@@ -965,18 +965,23 @@ def run_constrainedx(function, args):
|
||||
if pid:
|
||||
_, status = os.waitpid(pid, 0)
|
||||
return _exitcode_from_status(status)
|
||||
libc.unshare(CLONE_NEWNS|CLONE_NEWPID)
|
||||
# must fork again due to CLONE_NEWPID, or else lose the ability to make
|
||||
# subprocesses
|
||||
pid = os.fork()
|
||||
if pid:
|
||||
_, status = os.waitpid(pid, 0)
|
||||
os._exit(_exitcode_from_status(status))
|
||||
# we are pid 1 now
|
||||
_mount('none', '/', flags=MS_REC|MS_PRIVATE)
|
||||
_mount('proc', '/proc', fstype='proc')
|
||||
function(*args)
|
||||
os._exit(0)
|
||||
exitcode = 0
|
||||
try:
|
||||
libc.unshare(CLONE_NEWNS|CLONE_NEWPID)
|
||||
# must fork again due to CLONE_NEWPID, or else lose the ability to make
|
||||
# subprocesses
|
||||
pid = os.fork()
|
||||
if pid:
|
||||
_, status = os.waitpid(pid, 0)
|
||||
os._exit(_exitcode_from_status(status))
|
||||
# we are pid 1 now
|
||||
_mount('none', '/', flags=MS_REC|MS_PRIVATE)
|
||||
_mount('proc', '/proc', fstype='proc')
|
||||
function(*args)
|
||||
except Exception:
|
||||
exitcode = 1
|
||||
finally:
|
||||
os._exit(exitcode)
|
||||
|
||||
def run_constrained(function, args):
|
||||
# first fork to avoid changing namespace of unconstrained environment
|
||||
@@ -984,18 +989,23 @@ def run_constrained(function, args):
|
||||
if pid:
|
||||
_, status = os.waitpid(pid, 0)
|
||||
return _exitcode_from_status(status)
|
||||
libc.unshare(CLONE_NEWNS|CLONE_NEWPID)
|
||||
# must fork again due to CLONE_NEWPID, or else lose the ability to make
|
||||
# subprocesses
|
||||
pid = os.fork()
|
||||
if pid:
|
||||
_, status = os.waitpid(pid, 0)
|
||||
os._exit(_exitcode_from_status(status))
|
||||
# we are pid 1 now
|
||||
_mount('none', '/', flags=MS_REC|MS_PRIVATE)
|
||||
_mount('proc', '/proc', fstype='proc')
|
||||
function(args)
|
||||
os._exit(0)
|
||||
exitcode = 0
|
||||
try:
|
||||
libc.unshare(CLONE_NEWNS|CLONE_NEWPID)
|
||||
# must fork again due to CLONE_NEWPID, or else lose the ability to make
|
||||
# subprocesses
|
||||
pid = os.fork()
|
||||
if pid:
|
||||
_, status = os.waitpid(pid, 0)
|
||||
os._exit(_exitcode_from_status(status))
|
||||
# we are pid 1 now
|
||||
_mount('none', '/', flags=MS_REC|MS_PRIVATE)
|
||||
_mount('proc', '/proc', fstype='proc')
|
||||
function(args)
|
||||
except Exception:
|
||||
exitcode = 1
|
||||
finally:
|
||||
os._exit(exitcode)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user