Page MenuHomeFreeBSD

login: Use getpwnam_r() instead of getpwnam().
ClosedPublic

Authored by des on Jan 9 2024, 6:09 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 29, 6:04 AM
Unknown Object (File)
Wed, Jun 26, 4:46 PM
Unknown Object (File)
Tue, Jun 25, 3:06 AM
Unknown Object (File)
Mon, Jun 24, 3:24 AM
Unknown Object (File)
Mon, Jun 24, 12:50 AM
Unknown Object (File)
May 15 2024, 5:39 AM
Unknown Object (File)
May 12 2024, 1:40 PM
Unknown Object (File)
May 11 2024, 5:45 PM

Details

Summary

Since we expect the entry to still be valid after calling into PAM,
which may call getpwnam() itself, we need to use getpwnam_r().

MFC after: 1 week
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Jan 9 2024, 6:09 PM
This revision is now accepted and ready to land.Jan 9 2024, 6:37 PM
allanjude added a subscriber: allanjude.

Reviewed-by: allanjude

OK. Sure. But why? You're just swapping out one global for another

markj added a subscriber: markj.
In D43376#989563, @imp wrote:

OK. Sure. But why? You're just swapping out one global for another

I believe the point is that the auth_pam() call can clobber the buffer.

In D43376#989563, @imp wrote:

OK. Sure. But why? You're just swapping out one global for another

We call pam_setcred() after calling getpwnam() and expect pwd to still be valid afterwards. PAM modules frequently also call getpwnam(). The only reason this hasn't gotten us into trouble yet is that they usually look up the same user, so even though pwd gets clobbered it still contains the correct data.

This revision was automatically updated to reflect the committed changes.