Anthony,<div><br></div><div><div class="gmail_quote">On Sat, Jun 5, 2010 at 9:01 PM, Anthony Iliopoulos <span dir="ltr"><<a href="mailto:ailiop@lsu.edu">ailiop@lsu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Pedro,<br>
<div class="im"><br>
On Wed, Jun 02, 2010 at 05:09:39PM +0200, Pedro Fortuny Ayuso wrote:<br>
> Hi,<br>
><br>
> I simply do not get it... crypt(3) crashes in a PAM module,<br>
> raising a segfault, but it does not in a 'standalone version'<br>
> of the module.<br>
><br>
> The code below (which is the minimal I have been able to squeeze<br>
> it into) segfaults if run as a pam module. It does not do so<br>
> if run standalone (adding the main() and compiling it as an executable).<br>
><br>
> Any ideas, pointers, misunderstandings on my side?<br>
><br>
> I can run other libraries (namely OpenSSL) without problems, although<br>
> BIO_free_all() also segfaulted...<br>
><br>
> This happens in two systems at least:<br>
><br>
> Ubuntu-9, 2.6.24-24-generic #1 SMP, x86_64<br>
> Fedora-13, 2.6.33.3-85.fc13.x86_64 #1 SMP<br>
><br>
> It seems to be related to the 64bit thing, but I am not that<br>
> sure. I am copying the error messages:<br>
><br>
> On the Ubuntu system:<br>
> Jun  2 17:06:48 jorge-desktop kernel: [109318.066314] sshd[10318]: segfault at 5e6775f0 rip 7ff45bb900e0 rsp 7fff6644e658 error 4<br>
><br>
> On the Fedora system:<br>
> Jun  2 04:40:42 fedora13 sibyl: Entered module BOGUS<br>
> Jun  2 04:40:42 fedora13 sibyl: I can still log after crypt'ing<br>
> Jun  2 04:40:42 fedora13 kernel: sshd[1855]: segfault at ffffffffca7c4be0 ip 00007fd8c68fb007 sp 00007fff4efb8b50 error 4 in <a href="http://libc-2.12.so" target="_blank">libc-2.12.so</a>[7fd8c68b3000+175000]<br>
<br>
</div>Looks like your calling your pam module through sshd. Note that<br>
sshd runs pam authentication in a thread context. That might be<br>
attributing to the crash your are seeing when the module is not<br>
called as a standalone program.<br>
<br>
Some other things you might want to pay attention to is, how you<br>
are compiling the pam module (statically/dynamically and the various<br>
linker options).<br>
<br>
Also, did you try to isolate the fault ? e.g. does it still segfault<br>
if you remove the crypt call ? What about removing the syslog<br>
output of the crypt result array ? You can always make an attempt<br>
to see if crypt_r (the re-entrant version of crypt) would work for<br>
you.<br>
<br>
Regards,<br>
Anthony<br>
<div><div></div><div class="h5"><br></div></div></blockquote><div><br></div><div><br></div><div><div>Yes, I did isolate the fault: it is the crypt() call for sure. Most probably it is the</div><div>sshd thread context thing you mention (it is the only way I have tried to run it so far).</div>
<div>As a matter of fact I tried to use also OpenSSL's BIOs and got another</div><div>segfault when calling BIO_free() (all this in through sshd), which makes</div><div>me think the thread context is the key to the problem.</div>
<div><br></div><div>I shall try and use the crypt_r version. However, could you point me</div><div>to some place where this thread context of sshd is explained? Is there a way</div><div>to replicate crypt() using OpenSSL?</div>
<div><br></div><div>Thanks a lot,</div><div><br></div><div>Pedro.</div></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div class="h5">
> /* notice that one cannot assume Linux has OpenPAM implemented */<br>
><br>
> #include <pwd.h><br>
> #include <stdlib.h><br>
> #include <stdio.h><br>
> #include <string.h><br>
> #include <unistd.h><br>
> #include <syslog.h><br>
><br>
> #include <security/pam_modules.h><br>
> #include <security/pam_appl.h><br>
><br>
><br>
> int<br>
> pam_sm_authenticate(pam_handle_t *pamh, int flags,<br>
>                   int argc, const char *argv[])<br>
> {<br>
>       FILE *log;<br>
>       /* options */<br>
><br>
>       openlog( "sibyl", LOG_CONS, LOG_AUTH);<br>
>       void syslog(int priority, const char *format, ...);<br>
><br>
>       syslog(LOG_NOTICE, "Entered module BOGUS");<br>
>         char *c = crypt("petete", "$1$cW0uis36$");<br>
>         syslog(LOG_NOTICE, "I can still log after crypt'ing");<br>
>         syslog(LOG_NOTICE, "Encrypted [%s]", c);<br>
>         return(PAM_AUTH_ERR);<br>
> }<br>
><br>
> /* uncomment for a standalone version<br>
> int main(){<br>
>       pam_sm_authenticate(NULL, 0, 0, NULL);<br>
>       return(0);<br>
> } */<br>
<br>
</div></div>_______________________________________________<br>
Pam-list mailing list<br>
<a href="mailto:Pam-list@redhat.com">Pam-list@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/pam-list" target="_blank">https://www.redhat.com/mailman/listinfo/pam-list</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Pedro Fortuny Ayuso<br>Dpto de Matemáticas<br>Escuela Univ. de Ingeniería Técnica Industrial<br>Campus Universitario de Gijón (Viesques)<br>33203 Gijón (Asturias)<br><br>

</div>