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

Partition probe broken with PCRE2 #2026

Closed
jan-cerny opened this issue Sep 7, 2023 · 1 comment · Fixed by #2027
Closed

Partition probe broken with PCRE2 #2026

jan-cerny opened this issue Sep 7, 2023 · 1 comment · Fixed by #2027

Comments

@jan-cerny
Copy link
Member

jan-cerny commented Sep 7, 2023

Description of Problem:

When OpenSCAP is built with PCRE2, the partition probe doesn't evaluate properly OVAL partition objects that contain a regular expression pattern.

This breaks rule audit_rules_privileged_commands from scap-security-guide-0.1.69.

OpenSCAP Version:

current upstream maint-1.3 branch as of HEAD 9b3e756

Operating System & Version:

Fedora 38

Steps to Reproduce:

Reproducer OVAL: reproducer.zip

  1. cmake -DWITH_PCRE2=ON -DCMAKE_BUILD_TYPE=Debug .. && make
  2. ./oscap_wrapper oval eval --results results.xml reproducer.xml

Actual Results:

Definition oval:x:def:1 is evaluated as false, the XML results shows that the object doesn't exist.

Expected Results:

Behavior should be the same as when built with PCRE1. Specifically, definition oval:x:def:1 is evaluated as true, the XML results contains many items matching the partition object.

Additional Information / Debugging Steps:

This patch seems to fix the problem:

diff --git a/src/OVAL/probes/unix/linux/partition_probe.c b/src/OVAL/probes/unix/linux/partition_probe.c
index cd0e10413..eea7bc348 100644
--- a/src/OVAL/probes/unix/linux/partition_probe.c
+++ b/src/OVAL/probes/unix/linux/partition_probe.c
@@ -402,7 +402,7 @@ int partition_probe_main(probe_ctx *ctx, void *probe_arg)
                                 rc = oscap_pcre_exec(re, mnt_entp->mnt_dir,
                                                strlen(mnt_entp->mnt_dir), 0, 0, NULL, 0);
 
-                                if (rc == 0) {
+                                if (rc >= 0) {
                                        if (
 #if defined(HAVE_BLKID_GET_TAG_VALUE)
                                                collect_item(ctx, obj_over, mnt_entp, blkcache)

Additionally, you can discover this by running Automatus test scenarios for the rule audit_rules_privileged_commands on a VM back end where the VM contains a custom build of OpenSCAP with the PCRE2.

@jan-cerny jan-cerny added the bug label Sep 7, 2023
@evgenyz
Copy link
Contributor

evgenyz commented Sep 8, 2023

We should try and reproduce the problem in OpenSCAP upstream unit tests on top of fixing the problem. Good catch!

@evgenyz evgenyz added this to the 1.3.10 milestone Sep 8, 2023
jan-cerny added a commit to jan-cerny/openscap that referenced this issue Sep 8, 2023
The pcre_exec function can return a positive number or zero,
zero is returned if the buffer isn't large enough. Therefore,
we should allow also positive number return code.

The commit also extends the test to cover the bug situation.

Fixes: OpenSCAP#2026
jan-cerny added a commit to jan-cerny/openscap that referenced this issue Sep 8, 2023
The pcre_exec function can return a positive number or zero,
zero is returned if the buffer isn't large enough. Therefore,
we should allow also positive number return code.

The commit also extends the test to cover the bug situation.

Fixes: OpenSCAP#2026
cschuber pushed a commit to cschuber/openscap that referenced this issue Feb 1, 2024
The pcre_exec function can return a positive number or zero,
zero is returned if the buffer isn't large enough. Therefore,
we should allow also positive number return code.

The commit also extends the test to cover the bug situation.

Fixes: OpenSCAP#2026
cschuber pushed a commit to cschuber/openscap that referenced this issue Feb 1, 2024
The pcre_exec function can return a positive number or zero,
zero is returned if the buffer isn't large enough. Therefore,
we should allow also positive number return code.

The commit also extends the test to cover the bug situation.

Fixes: OpenSCAP#2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants