Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

declare proc_dir earlier and resolve exact proc_dir #1001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dmoj/cptbox/isolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,19 @@ def _access_check(self, debugger: Debugger, file: str, fs_jail: FilesystemPolicy

# normpath doesn't strip leading slashes
projected = normalized = '/' + os.path.normpath(file).lstrip('/')
proc_dir = f'/proc/{debugger.tid}'
if normalized.startswith('/proc/self'):
# modify file so that the correct realpath is used
file = os.path.join(f'/proc/{debugger.tid}', os.path.relpath(file, '/proc/self'))
projected = '/' + os.path.normpath(file).lstrip('/')
elif normalized.startswith(f'/proc/{debugger.tid}/'):
elif normalized.startswith(
proc_dir + '/'
): # Use a slash because otherwise if we are 123 then /proc/12345 matches
# If the child process uses /proc/getpid()/foo, set the normalized path to be /proc/self/foo.
# Access rules can more easily check /proc/self.
normalized = os.path.join('/proc/self', os.path.relpath(file, f'/proc/{debugger.tid}'))
normalized = os.path.join('/proc/self', os.path.relpath(file, proc_dir))
elif normalized == proc_dir:
normalized = '/proc/self'
real = os.path.realpath(file)

try:
Expand All @@ -367,7 +373,6 @@ def _access_check(self, debugger: Debugger, file: str, fs_jail: FilesystemPolicy
raise DeniedSyscall(ACCESS_EACCES, f'Denying {file}, normalized to {normalized}')

if normalized != real:
proc_dir = f'/proc/{debugger.tid}'
if real.startswith(proc_dir):
real = os.path.join('/proc/self', os.path.relpath(real, proc_dir))

Expand Down