Trouble with crypt(3) in pam module.

Anthony Iliopoulos ailiop at lsu.edu
Sat Jun 5 19:01:56 UTC 2010


Pedro,

On Wed, Jun 02, 2010 at 05:09:39PM +0200, Pedro Fortuny Ayuso wrote:
> Hi,
> 
> I simply do not get it... crypt(3) crashes in a PAM module,
> raising a segfault, but it does not in a 'standalone version'
> of the module.
> 
> The code below (which is the minimal I have been able to squeeze 
> it into) segfaults if run as a pam module. It does not do so 
> if run standalone (adding the main() and compiling it as an executable).
> 
> Any ideas, pointers, misunderstandings on my side?
> 
> I can run other libraries (namely OpenSSL) without problems, although
> BIO_free_all() also segfaulted...
> 
> This happens in two systems at least:
> 
> Ubuntu-9, 2.6.24-24-generic #1 SMP, x86_64
> Fedora-13, 2.6.33.3-85.fc13.x86_64 #1 SMP
> 
> It seems to be related to the 64bit thing, but I am not that
> sure. I am copying the error messages:
> 
> On the Ubuntu system:
> Jun  2 17:06:48 jorge-desktop kernel: [109318.066314] sshd[10318]: segfault at 5e6775f0 rip 7ff45bb900e0 rsp 7fff6644e658 error 4
> 
> On the Fedora system:
> Jun  2 04:40:42 fedora13 sibyl: Entered module BOGUS
> Jun  2 04:40:42 fedora13 sibyl: I can still log after crypt'ing
> Jun  2 04:40:42 fedora13 kernel: sshd[1855]: segfault at ffffffffca7c4be0 ip 00007fd8c68fb007 sp 00007fff4efb8b50 error 4 in libc-2.12.so[7fd8c68b3000+175000]

Looks like your calling your pam module through sshd. Note that
sshd runs pam authentication in a thread context. That might be
attributing to the crash your are seeing when the module is not
called as a standalone program.

Some other things you might want to pay attention to is, how you
are compiling the pam module (statically/dynamically and the various
linker options).

Also, did you try to isolate the fault ? e.g. does it still segfault
if you remove the crypt call ? What about removing the syslog
output of the crypt result array ? You can always make an attempt
to see if crypt_r (the re-entrant version of crypt) would work for
you.

Regards,
Anthony

> /* notice that one cannot assume Linux has OpenPAM implemented */
> 
> #include <pwd.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> #include <syslog.h>
> 
> #include <security/pam_modules.h>
> #include <security/pam_appl.h>
> 
> 
> int
> pam_sm_authenticate(pam_handle_t *pamh, int flags,
> 		    int argc, const char *argv[])
> {
> 	FILE *log;
> 	/* options */
> 
> 	openlog( "sibyl", LOG_CONS, LOG_AUTH);
> 	void syslog(int priority, const char *format, ...);
> 
> 	syslog(LOG_NOTICE, "Entered module BOGUS");
>         char *c = crypt("petete", "$1$cW0uis36$");
>         syslog(LOG_NOTICE, "I can still log after crypt'ing");
>         syslog(LOG_NOTICE, "Encrypted [%s]", c);
>         return(PAM_AUTH_ERR);
> }
> 
> /* uncomment for a standalone version
> int main(){
> 	pam_sm_authenticate(NULL, 0, 0, NULL);
> 	return(0);
> } */




More information about the Pam-list mailing list