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)
Wed, May 15, 5:39 AM
Unknown Object (File)
Sun, May 12, 1:40 PM
Unknown Object (File)
Sat, May 11, 5:45 PM
Unknown Object (File)
Fri, May 10, 3:49 AM
Unknown Object (File)
Thu, May 9, 7:56 PM
Unknown Object (File)
May 9 2024, 4:53 AM
Unknown Object (File)
Feb 24 2024, 3:28 AM
Unknown Object (File)
Jan 19 2024, 4:41 AM

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.