Add test for CVE-2026-35535: Privilege escalation#27
Merged
jakub-vavra-cz merged 1 commit intoApr 23, 2026
Conversation
Reviewer's GuideAdds a new critical pytest integration test that reproduces and guards against CVE-2026-35535 by verifying that sudo’s mailer runs under the invoking user’s UID/GID rather than root when mail_always is enabled. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The test description says the user should have UID/GID (10001/20001), but the code uses
expected_gid = 10001and never explicitly sets the user's primary GID; consider either updating the description or settinggidto the intended value and adjustingexpected_gidaccordingly to avoid confusion and brittle expectations. - Relying on
time.sleep(3)before reading/tmp/mail.*makes the test timing-dependent; consider polling for the mail file with a timeout instead to make the test more robust on slower or more variable environments. - The error messages around reading
/tmp/mail.*mentionlseven thoughcatis used; updating these to reflect the actual command should make failures easier to interpret.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The test description says the user should have UID/GID (10001/20001), but the code uses `expected_gid = 10001` and never explicitly sets the user's primary GID; consider either updating the description or setting `gid` to the intended value and adjusting `expected_gid` accordingly to avoid confusion and brittle expectations.
- Relying on `time.sleep(3)` before reading `/tmp/mail.*` makes the test timing-dependent; consider polling for the mail file with a timeout instead to make the test more robust on slower or more variable environments.
- The error messages around reading `/tmp/mail.*` mention `ls` even though `cat` is used; updating these to reflect the actual command should make failures easier to interpret.
## Individual Comments
### Comment 1
<location path="pytest/tests/test_security.py" line_range="50-51" />
<code_context>
+ :customerscenario: False
+ """
+ username = "testuser"
+ expected_uid = 10001
+ expected_gid = 10001
+ mailer_drop_in_path = "/etc/sudoers.d/00-cve-35535-mailer"
+ client.user(username).add(uid=expected_uid, password="Secret123")
</code_context>
<issue_to_address>
**issue:** Align expected GID with the documented test setup to avoid a misleading assertion
The docstring states the user should have UID/GID 10001/20001, but the test uses 10001 for both. This makes the test scenario inconsistent with its description and could hide issues if the real primary GID differs. Please either set `expected_gid` to the intended primary GID (e.g. 20001 and pass it to `client.user(...).add`) or update the docstring so it matches the actual UID/GID used.
</issue_to_address>
### Comment 2
<location path="pytest/tests/test_security.py" line_range="98-104" />
<code_context>
+ f"sudo must allow {username!r} to run /usr/bin/whoami with password Secret123 (sudoers rule from "
+ f"this test); otherwise the mailer is never invoked and the CVE check cannot run."
+ )
+ time.sleep(3)
+ after = client.host.conn.run("cat /tmp/mail.* 2>/dev/null")
+ client.host.conn.run("rm -f /tmp/mail.*", raise_on_error=False)
+ assert after.rc == 0 and after.stdout.strip(), (
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid fixed sleep; wait explicitly for the mail file to appear to reduce flakiness
The hard-coded `time.sleep(3)` risks flakiness on slower systems and wastes time on faster ones. Instead, poll for `/tmp/mail.*` for a bounded period (e.g., loop up to N seconds with a short sleep) and break as soon as `cat /tmp/mail.*` returns non-empty output, still failing if the mailer never runs.
```suggestion
assert client.auth.sudo.run(username, "Secret123", command="/usr/bin/whoami"), (
f"sudo must allow {username!r} to run /usr/bin/whoami with password Secret123 (sudoers rule from "
f"this test); otherwise the mailer is never invoked and the CVE check cannot run."
)
# Poll for fakemailer output instead of using a fixed sleep to reduce flakiness
timeout_seconds = 10
poll_interval = 0.5
deadline = time.time() + timeout_seconds
after = None
while time.time() < deadline:
after = client.host.conn.run("cat /tmp/mail.* 2>/dev/null")
if after.rc == 0 and after.stdout.strip():
break
time.sleep(poll_interval)
if after is None:
# Fallback in the unlikely event the loop body never ran
after = client.host.conn.run("cat /tmp/mail.* 2>/dev/null")
client.host.conn.run("rm -f /tmp/mail.*", raise_on_error=False)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
7bfd07e to
a7dde8a
Compare
shridhargadekar
approved these changes
Apr 21, 2026
331762c
into
RedHat-SP-Security:master
3 of 7 checks passed
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 by Sourcery
Tests: