Repository navigation
Fix descriptor mutex errno reporting and synchronize probe workers (#2481) - #2482
Open
Mohit20057 wants to merge 1 commit into
Open
Mohit20057 wants to merge 1 commit into
Mohit20057 wants to merge 1 commit into
Conversation
In seap-descriptor.h, SEAP_desc_lock, SEAP_desc_unlock, and
SEAP_desc_trylock invoked pthread_mutex functions without setting
errno on failure. Since pthread_mutex_* functions return the error
code directly instead of setting errno, callers like SEAP_packet_send
logged misleading messages such as:
E: oscap: DESC_WUNLOCK failed to unlock a mutex: Success
Fix this by explicitly setting errno = ret on failure in all SEAP
descriptor mutex helpers.
Furthermore, synchronize probe worker threads during probe shutdown.
When a probe completes its last evaluation, probe_common_main_cleanup
freed the SEAP context and descriptors while a worker thread in
SEAP_packet_send was still about to unlock the descriptor mutex,
causing intermittent use-after-free failures and non-deterministic
failures in test_tmpdir.sh (especially on s390x).
Wait for all active worker threads to terminate before releasing
probe resources.
Fixes: OpenSCAP#2481
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes the intermittent test failure in
tests/common/test_tmpdir.shon s390x and systems under specific thread timing, and corrects the misleadingDESC_WUNLOCK failed to unlock a mutex: Successerror log.Fixes: #2481
Root Causes
Misleading Mutex Error Logging (
seap-descriptor.h):POSIX thread functions (
pthread_mutex_lock,pthread_mutex_unlock, andpthread_mutex_trylock) return an error integer directly upon failure and do not assign toerrno. The helper functions inseap-descriptor.hdid not seterrno = ret;when those calls failed. Callers likeSEAP_packet_send()calledstrerror(errno)whereerrnowas0, emitting the contradictory message:Probe Worker Teardown Race Condition (
probe_main.c/worker.c):When an OVAL probe evaluation completed its final object response,
probe_common_main_cleanup()freed the probe's SEAP context and descriptor tables while a background worker thread executingSEAP_packet_send()was still in the middle of sending or about to unlock the descriptor mutex. This use-after-free led to memory corruption and unexpected termination ofoscap(exiting with code 0 instead of propagating code 2 intest_tmpdir.sh).Changes
src/OVAL/probes/SEAP/seap-descriptor.h:errno = ret;on failure inSEAP_desc_lock(),SEAP_desc_unlock(), andSEAP_desc_trylock().src/OVAL/probes/probe/probe.h:workers_mutex,workers_cond, andworkers_runningcount toprobe_t.src/OVAL/probes/probe/worker.h:probe_worker_start(),probe_worker_end(), andprobe_worker_wait().src/OVAL/probes/probe/worker.c:workers_running == 0.probe_worker_end(probe)to worker thread exit points inprobe_worker_runfn().src/OVAL/probes/probe/input_handler.c:probe_worker_start()prior to thread creation with rollback onpthread_create()failure.src/OVAL/probes/probe/probe_main.c:workers_mutexandworkers_cond).probe_worker_wait(probe)toprobe_common_main_cleanup()to ensure all workers exit before destroying SEAP contexts and caches.Testing Done
-DCMAKE_COMPILE_WARNING_AS_ERROR=True(0 compiler warnings, 0 errors).ctest --verbose -R common/test_tmpdir.shwith 100% pass across all 6 test scenarios:TMPDIR: remediation: PASSEDTMPDIR with trailing slash: remediation: PASSEDTMPDIR: oval: PASSEDTMPDIR with trailing slash: oval: PASSEDTMPDIR: datastream: PASSEDTMPDIR with trailing slash: datastream: PASSED