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

msr_global_mutex_lock: handle errors from apr_global_mutex_lock #3257

Open
wants to merge 4 commits into
base: v2/master
Choose a base branch
from

Conversation

marcstern
Copy link
Contributor

@marcstern marcstern commented Sep 12, 2024

apr_global_mutex_lock is sometimes called with a lock that wasn't created (for any reason).
In this case, the pointer is null and apr_global_mutex_lock dereferences a null pointer, leading to a crash.
This PR creates a wrapper around apr_global_mutex_lock to handle checking that and correct logging.
Same for msr_global_mutex_unlock.

Copy link

sonarcloud bot commented Sep 20, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
6.0% Duplication on New Code (required ≤ 3%)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@marcstern
Copy link
Contributor Author

marcstern commented Sep 20, 2024

#3255 acknowledged to be solved by the PR

Copy link
Contributor

@fzipi fzipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

int rc = apr_global_mutex_unlock(msr->modsecurity->auditlog_lock);
// We should have get the warning at lock time, so ignore it here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We should have get the warning at lock time, so ignore it here
// We should have been warnend during lock acquisition already, so don't log the same warning here


int rc = apr_global_mutex_unlock(msr->modsecurity->auditlog_lock);
// We should have get the warning at lock time, so ignore it here
// if (rc != APR_SUCCESS) msr_log(msr, 1, "Audit log: Failed to unlock global mutex: %s", get_apr_error(msr->mp, rc));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if (rc != APR_SUCCESS) msr_log(msr, 1, "Audit log: Failed to unlock global mutex: %s", get_apr_error(msr->mp, rc));

assert(msr->modsecurity); // lock is msr->modsecurity->..._lock
assert(msr->mp);
if (!lock) {
msr_log(msr, 1, "%s: Global mutex was not created", fct);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msr_log(msr, 1, "%s: Global mutex was not created", fct);
msr_log(msr, 1, "%s: Global mutex not initialised", fct);

assert(msr->modsecurity); // lock is msr->modsecurity->..._lock
assert(msr->mp);
if (!lock) {
msr_log(msr, 1, "%s: Global mutex was not created", fct);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msr_log(msr, 1, "%s: Global mutex was not created", fct);
msr_log(msr, 1, "%s: Global mutex not initialised", fct);

@airween
Copy link
Member

airween commented Sep 22, 2024

Before we merge, I want to check why the lock acquire was failed (see #3255 - the user reported that this issue came with the new version where we introduced this method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants