Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 9 Dec 2013 16:39:45 +0400
From: Solar Designer <>
Subject: Re: CVE request: pam: password hashes aren't compared case-sensitively

On Mon, Dec 09, 2013 at 03:21:39PM +0530, Ratul Gupta wrote:
> It was found that in pam_userdb module for Pam, password hashes weren't 
> compared case-sensitively, which could lead to acceptance of hashes for 
> completely different passwords, which shouldn't be accepted.
> After hashing the user's password with crypt(), pam_userdb compares the 
> result to the stored hash case-insensitively with strncasecmp(), which 
> should be avoided, as it could result in an increased possibility of a 
> successful brute-force attack.

Ouch.  A funny bug.  I just took a look at the code:

and here are some additional observations:

The limited length comparison is also slightly problematic.  In an older
revision of the code (e.g. in Linux-PAM-1.1.2), pam_userdb.c had:

	  if (data.dsize != 13) {
	    compare = -2;

which was later changed to:

	  if (data.dsize < 13) {
	    compare = -2;

I think that along with this change, a length comparison of the computed
vs. stored hash should have been added, but this was not done.  I think
the line:

	    if (cryptpw) {

should be changed to:

	    if (cryptpw && strlen(cryptpw) == (size_t)data.dsize) {

This is consistent with the approach pam_userdb already uses when
comparing plaintext passwords (ouch).  Speaking of which:

There are two code paths that compare plaintext passwords.  Luckily,
both check exact lengths and both only use case-insensitive comparison
if PAM_ICASE_ARG is set.  However, they are not constant time, so
correct passwords may possibly be determined remotely in linear rather
than exponential time (as function of password length):

Additionally, the length comparison, while having it is crucial, leaks
even more timing information: it tells a remote attacker whether the
tested password length is correct or not.  The result of such comparison
could be obtained and merged into the final authentication outcome in a
constant time fashion, although doing so may be non-trivial (especially
given possible compiler optimizations).

Is repairing all of this for real worth the effort?  Repairing plaintext
password comparisons (so that they are not even weaker than they appear
at first) feels weird.  Can pam_userdb be dropped from Linux-PAM and
from distros?  I hope people aren't using it because it looks unsuitable
for use, but I'm probably wrong.

(The hash comparisons aren't constant time either, but with large enough
salts that are unpredictable by a remote attacker and that are stored
only along with the hashes, this is OK.  In practice not all of these
conditions might be met all the time, but anyhow this is a more general
topic that is not limited to pam_userdb, so let's not focus on it in
this context.)


Powered by blists - more mailing lists

Please check out the Open Source Software Security Wiki, which is counterpart to this mailing list.

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.