Trouble with crypt(3) in pam module.

Pedro Fortuny Ayuso (Uniovi) fortunypedro at uniovi.es
Wed Jun 2 15:09:39 UTC 2010


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]


/* 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);
} */






-- 
Pedro Fortuny Ayuso
http://pfortuny.net
EUITIG, Campus de Viesques, Gijon
Dpto. de Matematicas
Universidad de Oviedo
fortunypedro at uniovi.es




More information about the Pam-list mailing list