Skip to contentSkip to conversation

Exhaustive key reading seems to silently stop on error

dm-crypt Nico R. 3 participants 4 messages Dec 9, 2009 – Dec 11, 2009

lore
Share & tools
lore

Nico R.

author
#0 lore raw

Hello!

Just a minute ago, I have subscribed to this list in order to let you know about what I have found in the cryptsetup code and which seems to be a bug to me.

In lib/utils.c (line 450f. in cryptsetup-1.0.7; line 490f. in current SVN revision, r132, equal to r152), we see the following code:

if(read(fd, pass + i, 1) != 1 || (newline_stop && pass[i] == '\n'))

        break;

If I interpret that snipped (and its surroundings) correctly, the code will read until EOF *or* until an error occurs.

If my interpretation is true, that code causes a problem: imagine a hardware failure while reading the key the first two times (for luksFormat/luksOpen). The read function returns -1 and sets errno to EIO. cryptsetup continues with a truncated key, it seems. On a later attempt to read the key (for luksOpen), the hardware failure is gone, and the key can be read completely. cryptsetup will not be able to open the encrypted partition anymore.

Please correct me if I got the code wrong … :-)

Thanks

Signature · 1 line
Nico
#1 lore raw

Hmm. This seems to indeed be a bug.

I gather there is no code later that distinguishes EOF and error and deals with the second possibility?

Arno

Quoted 36 lines · Nico R.

Hello!

Just a minute ago, I have subscribed to this list in order to let you know about what I have found in the cryptsetup code and which seems to be a bug to me.

In lib/utils.c (line 450f. in cryptsetup-1.0.7; line 490f. in current SVN revision, r132, equal to r152), we see the following code:

if(read(fd, pass + i, 1) != 1 || (newline_stop && pass[i] == '\n'))

        break;

If I interpret that snipped (and its surroundings) correctly, the code will read until EOF *or* until an error occurs.

If my interpretation is true, that code causes a problem: imagine a hardware failure while reading the key the first two times (for luksFormat/luksOpen). The read function returns -1 and sets errno to EIO. cryptsetup continues with a truncated key, it seems. On a later attempt to read the key (for luksOpen), the hardware failure is gone, and the key can be read completely. cryptsetup will not be able to open the encrypted partition anymore.

Please correct me if I got the code wrong?????? :-)

Thanks

Signature · 9 lines
Nico




_______________________________________________
dm-crypt mailing list
[email protected]
http://www.saout.de/mailman/listinfo/dm-crypt
Signature · 7 lines
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email: [email protected] 
GnuPG:  ID: 1E25338F  FP: 0C30 5782 9D93 F785 E79C  0296 797F 6B50 1E25 338F
----
Cuddly UI's are the manifestation of wishful thinking. -- Dylan Evans

If it's in the news, don't worry about it.  The very definition of 
"news" is "something that hardly ever happens." -- Bruce Schneier 
author
#2 lore raw

Hi!

(De-TOFU-ized.)

Quoted 1 line · Nico R.

[…]

Quoted 10 lines
Quoted 10 lines

In lib/utils.c (line 450f. in cryptsetup-1.0.7; line 490f. in current SVN revision, r132, equal to r152), we see the following code:

if(read(fd, pass + i, 1) != 1 || (newline_stop && pass[i] == '\n'))

        break;

If I interpret that snipped (and its surroundings) correctly, the code will read until EOF *or* until an error occurs.

If my interpretation is true, that code causes a problem:

[…]

Quoted 4 lines · Arno Wagner

Hmm. This seems to indeed be a bug.

I gather there is no code later that distinguishes EOF and error and deals with the second possibility?

As far as I can see, there is not. See <URL:http://code.google.com/p/cryptsetup/source/browse/trunk/lib/utils.c?r=132#480>.

Signature · 1 line
Nico
#3 lore raw
Quoted 8 lines · Nico R.
Quoted 8 lines
Quoted 8 lines

In lib/utils.c (line 450f. in cryptsetup-1.0.7; line 490f. in current SVN revision, r132, equal to r152), we see the following code:

if(read(fd, pass + i, 1) != 1 || (newline_stop && pass[i] == '\n'))

        break;

If I interpret that snipped (and its surroundings) correctly, the code will read until EOF *or* until an error occurs.

yes, sure it is bug, thanks for reporting it.

Fixed in trunk now
http://code.google.com/p/cryptsetup/source/detail?r=154#

Milan
--
[email protected]