Skip to content

[3.10] bpo-47260: Fix os.closerange() potentially being a no-op in a seccomp sandbox (GH-32418) #32420

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

Merged
merged 1 commit into from
Apr 8, 2022

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Apr 8, 2022

_Py_closerange() currently assumes that close_range() closes
all file descriptors even if it returns an error (other than ENOSYS).
This assumption can be wrong on Linux if a seccomp sandbox denies
the underlying syscall, pretending that it returns EPERM or EACCES.
In this case _Py_closerange() won't close any descriptors at all,
which in the worst case can be a security issue.

Fix this by falling back to other methods in case of any close_range()
error. Note that fallbacks will not be triggered on any problems with
closing individual file descriptors because close_range() is documented
to ignore such errors on both Linux[1] and FreeBSD[2].

[1] https://man7.org/linux/man-pages/man2/close_range.2.html
[2] https://www.freebsd.org/cgi/man.cgi?query=close_range&sektion=2
(cherry picked from commit 1c8b3b5)

Co-authored-by: Alexey Izbyshev izbyshev@ispras.ru

https://bugs.python.org/issue47260

… sandbox (pythonGH-32418)

_Py_closerange() currently assumes that close_range() closes
all file descriptors even if it returns an error (other than ENOSYS).
This assumption can be wrong on Linux if a seccomp sandbox denies
the underlying syscall, pretending that it returns EPERM or EACCES.
In this case _Py_closerange() won't close any descriptors at all,
which in the worst case can be a security issue.

Fix this by falling back to other methods in case of any close_range()
error. Note that fallbacks will not be triggered on any problems with
closing individual file descriptors because close_range() is documented
to ignore such errors on both Linux[1] and FreeBSD[2].

[1] https://man7.org/linux/man-pages/man2/close_range.2.html
[2] https://www.freebsd.org/cgi/man.cgi?query=close_range&sektion=2
(cherry picked from commit 1c8b3b5)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
@miss-islington
Copy link
Contributor Author

@izbyshev and @gpshead: Status check is done, and it's a success ✅ .

1 similar comment
@miss-islington
Copy link
Contributor Author

@izbyshev and @gpshead: Status check is done, and it's a success ✅ .

@miss-islington
Copy link
Contributor Author

@izbyshev and @gpshead: Status check is done, and it's a success ✅ .

@bedevere-bot bedevere-bot added the type-bug An unexpected behavior, bug, or error label Apr 8, 2022
@miss-islington
Copy link
Contributor Author

Sorry, I can't merge this PR. Reason: 3 of 6 required status checks are expected..

@miss-islington
Copy link
Contributor Author

@izbyshev and @gpshead: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit 89697f7 into python:3.10 Apr 8, 2022
@miss-islington miss-islington deleted the backport-1c8b3b5-3.10 branch April 8, 2022 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants