Hi,

When saving the image, uswsusp measures the time it takes and saves it in the writeout_time member of struct swsusp_info. During resume the information is printed. I found this feature useful. Unfortunately, it doesn't work when configured with CONFIG_ENCRYPT=yes.

The reason is that struct swsusp_info doesn't fit into one page anymore and the overflowing pieces are not saved. On my i386 system I have:
  sizeof(struct swsusp_info) == 4568
  page_size == 4096
Therefore part of key.data array overflows (only the first 538 bytes of 1000 fit into the page) and of course writeout_time is not saved at all.

Bits of key.data getting lost seems scary at first, but we are lucky - we use the maximum key size of 4096 bits (512 bytes). So the overflowing bytes of key.data were never used.

The solution is to decrease KEY_DATA_SIZE to 512. We know we never need more than that. The attached patch does that. And just in case we want to use larger keys in the future, it checks that the encrypted key fits into the buffer.

With the patch I now have (on i386) sizeof(struct swsusp_info) == 4080 and the writeout_time is saved correctly.

The question remains what to do on x86_64. Even with the patch, struct swsusp_info is 4104 bytes on this platform. Again, we're lucky that the encrypted key fits into the first 4096 bytes. The only overflowing member is writeout_time, so the issue is not critical. We could save 8 bytes by changing the order of "cpus" and "num_physpages", which would eliminate 8 bytes of padding. I'm afraid such solution is not acceptable, because that part of the structure defines the kernel<->userspace interface. Is it too late to change it? Instead, maybe we can simply save as many pages as needed for the complete struct swsusp_info? Or we can just accept the fact that measuring the writeout_time doesn't work on x86_64.

Michal
Index: encrypt.h
===================================================================
RCS file: /cvsroot/suspend/suspend/encrypt.h,v
retrieving revision 1.6
diff -u -p -r1.6 encrypt.h
--- encrypt.h   11 Dec 2006 20:42:46 -0000      1.6
+++ encrypt.h   18 Jan 2007 13:11:06 -0000
@@ -29,7 +29,7 @@
 #define PK_CIPHER_BLOCK        16
 /* Auxiliary constants */
 #define RSA_DATA_SIZE  3072
-#define KEY_DATA_SIZE  1000
+#define KEY_DATA_SIZE  512
 #define RSA_FIELDS     6
 #define RSA_FIELDS_PUB 2
 #define KEY_TEST_SIZE  8
Index: suspend.c
===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.66
diff -u -p -r1.66 suspend.c
--- suspend.c   10 Jan 2007 14:16:45 -0000      1.66
+++ suspend.c   18 Jan 2007 13:11:06 -0000
@@ -1107,11 +1107,13 @@ static void generate_key(void)
                        gcry_ac_data_get_index(key_set, GCRY_AC_FLAG_COPY, 0,
                                                (const char **)&str, &mpi);
                        gcry_free(str);
-                       gcry_mpi_print(GCRYMPI_FMT_USG, key->data,
+                       ret = gcry_mpi_print(GCRYMPI_FMT_USG, key->data,
                                        KEY_DATA_SIZE, &s, mpi);
                        gcry_mpi_release(mpi);
-                       key->size = s;
-                       use_RSA = 'y';
+                       if (!ret) {
+                               key->size = s;
+                               use_RSA = 'y';
+                       }
                }
 Close_urandom:
                close(rnd_fd);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to