-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Missing audit hooks in several extension modules #115322
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
Comments
Add extra audit hooks to catch C function calling from ctypes, reading/writing files through readline and executing external programs through _posixsubprocess.
The primary user of that is
There is symmetry in that the private |
Ah, yes, I have no idea how I missed subprocess when looking for callers... It's indeed the goal to have some fewer "holes" or better coverage from the audit hooks here. That includes directly calling into the extension modules or callers that don't do their own hook (like the multiprocessing one). The new event was indeed based on the winapi ones. |
Should |
Looks like a good catch that should probably be covered too. It may need a bit of translation to not confuse existing consumers of the |
Add extra audit hooks to catch C function calling from ctypes, reading/writing files through readline and executing external programs through _posixsubprocess. * Make audit-tests for open pass when readline.append_history_file is unavailable * Less direct testing of _posixsubprocess for audit hooks * Also remove the audit hook from call_cdeclfunction now that _ctypes_callproc does it instead. * reword the NEWS entry. * mention readline in NEWS * add versionchanged markers * fix audit_events.rst versionadded * doc lint --------- Co-authored-by: Gregory P. Smith <[email protected]>
…rms. It was using a signed conversion to communicate the function id (pointer) value.
Bug report
Bug description:
Several extension modules don't fully emit the relevant audit events, leading to file read or process spawning without any traceability.
In particular:
_ctypes.CFuncPtr
does not emitctypes.call_function
. When combined with some known addresses, this can result in arbitrary functions in libc or python getting called. Such addresses could come fromid
,ctypes.pythonapi._handle
, passing abyref
pointer toctypes.cast
, or probably still several other methods. Coincidentally, thectypes.cast
method would by audited by the samectypes.call_function
once it is present. The downside is that it may also result in multiple audit hooks for functions likectypes.string_at
that have their own specialized audit hook event too._ctypes.CFuncPtr
might fall under the audit eventctypes.cdata
, as it is in spirit (though not in implementation) similar to calling a.from_address
. An option might be to introducectypes.cdata/function
similar toctypes.cdata/buffer
for this.readline
module can open and read a file throughreadline.read_history_file
without having anopen
audit hook. Together withreadline.get_history_item
, this can lead to unaudited file reads. A similar situation exists for some other functions in this library._posixsubprocess.fork_exec
function, and its only user in the standard library,multiprocessing.util.spawnv_passfds
perform a fork + exec without any audit hooks. One would expect eitheros.fork
andos.exec
or the functionally similaros.posix_spawn
here.I'm happy to make a quick PR for these and adjust any specific event types to be more consistent or more uniquely identifiable.
Quick example in code:
CPython versions tested on:
3.11, 3.12, 3.13, CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: