Recently I ran into the issue that an application which is performing PAM authentication was hanging for up to 20 seconds before it reported whether PAM authentication was successful or not. Other applications performing PAM authentication via exactly the same set PAM modules (identical files in /etc/pam.d
!) didn't have such a problem.
After some investigations I found out that the difference was that this one application was setting PAM_RHOST
to a value prior to performing authentication whereas the other applications were not. I also discovered that the problem would not occur if the machine was not connected to any network. In the end, it all boiled down to incorrect DNS settings on the machine. Apparently some DNS lookup was hanging and fixing the DNS setup also made the problem vanish.
What I don't quite understand about all this is who is triggering that DNS lookup in the first place? None of the PAM modules I used will ever trigger a DNS lookup and PAM itself also doesn't seem to trigger one in its code. Not knowing where the lookup comes from is driving me nuts!
Well, after an extensive search through lots of source code, I finally found the cause of this lookup.
If you look at the source code of PAM, especially the file
pam_audit.c
, then there is function named_pam_audit_writelog(...)
and inside this function, the following call is being made:pamh->rhost
is the storage for thePAM_RHOST
item. Important is that the next argument afterpamh->rhost
is actuallyNULL
.This is a function of the Linux Auditing Framework and the function signature of the function in question is:
So as you can see, a
host
is given to the function butaddr
isNULL
. In that case, this function will try to resolvehost
via DNS resolution to obtain the missing address.Thus if a program is using PAM and the program is setting the
PAM_RHOST
item, PAM will indirectly trigger a DNS lookup through the Auditing Framework. As this all happens synchronously, an incorrectly configured DNS setup (e.g. multiple unreachable DNS servers and/or many search domains) can cause PAM authentication to hang for quite a while before the DNS lookup will finally fail with error but that error is ignored (the lookup is just best effort) and the login is stored without an address; thus the failure of the lookup has no effect on PAM authentication either.