Skip to content

src/sss_client/common.c: Use getpwnam_r to avoid clobbering struct passwd#8487

Merged
alexey-tikhonov merged 1 commit into
SSSD:masterfrom
salahcoronya:preserve-passwd
Mar 6, 2026
Merged

src/sss_client/common.c: Use getpwnam_r to avoid clobbering struct passwd#8487
alexey-tikhonov merged 1 commit into
SSSD:masterfrom
salahcoronya:preserve-passwd

Conversation

@salahcoronya

Copy link
Copy Markdown
Contributor

If something else uses PAM (like openrc, see
OpenRC/openrc#984) and getpwnam, and calls something like pam_open_session, sssd's call to getpwnam in init_sssd_ids clobbers the cached value by the other program.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request correctly replaces the non-thread-safe getpwnam with its re-entrant version, getpwnam_r, to prevent potential data corruption when multiple threads are involved. The implementation follows the standard pattern for using getpwnam_r, including dynamic buffer allocation and resizing. However, I've found a potential memory leak in the error handling of realloc and provided a suggestion to fix it.

Comment thread src/sss_client/common.c Outdated
@salahcoronya
salahcoronya force-pushed the preserve-passwd branch 2 times, most recently from b66af65 to c37669a Compare March 2, 2026 05:11
@alexey-tikhonov alexey-tikhonov added the no-backport This should go to target branch only. label Mar 2, 2026
@alexey-tikhonov alexey-tikhonov self-assigned this Mar 2, 2026
@alexey-tikhonov
alexey-tikhonov self-requested a review March 2, 2026 08:01
@alexey-tikhonov

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request correctly replaces the non-reentrant getpwnam with the reentrant getpwnam_r to prevent thread-safety issues. The implementation for handling ERANGE is mostly correct, but it has a potential denial-of-service vulnerability due to unbounded memory allocation. I've added a review comment with a suggested fix to address this by adding a size limit to the buffer.

Comment thread src/sss_client/common.c Outdated
@alexey-tikhonov

Copy link
Copy Markdown
Member

Hi @salahcoronya,

I think this reports a valid bug, thanks.

But there is a number of (at least) stylistic issues (re SSSD coding style) with the patch.
Would you prefer to finalize the patch yourself (and then I'll provide review comments) or do you prefer somebody from maintainers take over?

@salahcoronya

Copy link
Copy Markdown
Contributor Author

I went ahead and finalized it myself, follow the coding style document.

Comment thread src/sss_client/common.c Outdated
@salahcoronya
salahcoronya force-pushed the preserve-passwd branch 2 times, most recently from 894f67c to 6c85770 Compare March 2, 2026 16:04
@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Mar 4, 2026
Comment thread src/sss_client/common.c Outdated
Comment thread src/sss_client/common.c Outdated
Comment thread src/sss_client/common.c Outdated
@alexey-tikhonov

Copy link
Copy Markdown
Member

FAIL: src/tests/whitespace_test of make check fails. Probably a trailing whitespace?

Comment thread src/sss_client/common.c Outdated
Comment thread src/sss_client/common.c Outdated
@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Mar 6, 2026
@alexey-tikhonov

Copy link
Copy Markdown
Member

Thank you, I have no further comments. ACK.

@alexey-tikhonov

Copy link
Copy Markdown
Member

Note: Covscan is green.

@alexey-tikhonov alexey-tikhonov removed the coverity Trigger a coverity scan label Mar 6, 2026

@thalman thalman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, thanks

…sswd

If something else uses PAM (like openrc, see
OpenRC/openrc#984) and getpwnam, and calls
something like pam_open_session, sssd's call to getpwnam in
init_sssd_ids clobbers the cached value by the other program.

Signed-off-by: Christopher Byrne <[email protected]>
Reviewed-by: Alexey Tikhonov <[email protected]>
Reviewed-by: Tomáš Halman <[email protected]>
@sssd-bot

sssd-bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

The pull request was accepted by @thalman with the following PR CI status:


🟢 CodeQL (success)
🟢 osh-diff-scan:fedora-rawhide-x86_64:upstream (success)
🟢 rpm-build:centos-stream-10-x86_64:upstream (success)
🟢 rpm-build:fedora-42-x86_64:upstream (success)
🟢 rpm-build:fedora-43-x86_64:upstream (success)
🟢 rpm-build:fedora-44-x86_64:upstream (success)
🟢 rpm-build:fedora-rawhide-x86_64:upstream (success)
🟢 Analyze (target) / cppcheck (success)
🟢 Build / freebsd (success)
🟢 Build / make-distcheck (success)
🟢 ci / intgcheck (centos-10) (success)
🟢 ci / intgcheck (fedora-42) (success)
🟢 ci / intgcheck (fedora-43) (success)
🟢 ci / intgcheck (fedora-44) (success)
🟢 ci / intgcheck (fedora-45) (success)
🟢 ci / prepare (success)
🟢 ci / system (centos-10) (success)
🟢 ci / system (fedora-42) (success)
🟢 ci / system (fedora-43) (success)
🟢 ci / system (fedora-44) (success)
🟢 ci / system (fedora-45) (success)
➖ Coverity scan / coverity (skipped)
🟢 Static code analysis / codeql (success)
🟢 Static code analysis / pre-commit (success)
🟢 Static code analysis / python-system-tests (success)


There are unsuccessful or unfinished checks. Make sure that the failures are not related to this pull request before merging.

@alexey-tikhonov
alexey-tikhonov merged commit dc6970c into SSSD:master Mar 6, 2026
2 of 7 checks passed
@salahcoronya
salahcoronya deleted the preserve-passwd branch March 6, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accepted no-backport This should go to target branch only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants