-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
GH-115322: Add missing audit hooks #115624
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
GH-115322: Add missing audit hooks #115624
Conversation
Add extra audit hooks to catch C function calling from ctypes, reading/writing files through readline and executing external programs through _posixsubprocess.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
cc @gpshead you enabled auto-merge but the docs workflow failed so it never got merged. |
|
this PR is ready but we're having github CI issues all over right now. |
|
GH-115322: Add missing audit hooks
I've left out the potential
ctypes.cdata/functionevent for now, as constructing a function without notice is not as badwhen you cannot call it without audit hook anymore. Calling some functions in
ctypes(as far as I can see:(w)string_at) now have two associated hooks, going first through the genericctypes.call_functionand then their preexisting specific hook (ctypes.(w)string_at). It would be nice to associated actypes.call_functionwith its function name, but this isn't possible in general (as you could technically call into arbitrary addresses), and I couldn't find a nice way to do it even in the "nice" case.For
_posixsubprocess.fork_exec, I instead opted to introduce a new event of its own, as wrangling the slightly weird setup withexecutable_listand passingenvas a list rather than the usual dict makes it more annoying to (cheaply) map onto the semantics of the existing events. If constructing an explicit dict or passing an env list to those would be prefered, it should be possible to assume the worst case for theexecutable_listand do a hook for each element.In the "normal" case, going through
multiprocessing.util.spawnv_passfds, only a single element would be passed either way.readlinehas a few of its own problems, mostly when dealing with filename arguments being set toNone. For the*_history_filefunctions, I opted to hardcode the~/.historypath that can also be found in the documentation, even though the logic inside readline is slightly more elaborate, e.g. finding a different path when on windows, and expanding out the home directory. Forread_init_file(None), the logic is even more convoluted, and pointing out the exact path would require replicating it and keeping up with any possible future updates. Instead, I chose to represent this by<readline_init_file>.📚 Documentation preview 📚: https://cpython-previews--115624.org.readthedocs.build/